aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-04-02 16:09:43 +0900
committertmk <nobody@nowhere>2013-04-02 16:09:43 +0900
commitcc8e66754b1a5d0c11985cb0feb51ead49668744 (patch)
treeb2c7aa7bf5a2ed20650febc6b25fbbd3d773fe10 /common/action.c
parent10f33a3e484e24065ed5eaab1c56c35156bace89 (diff)
downloadqmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.tar.gz
qmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.zip
Refine ACT_LAYER and ACT_LAYER_TAP
- Remove ACT_LAYER_BITOP
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c201
1 files changed, 62 insertions, 139 deletions
diff --git a/common/action.c b/common/action.c
index ef04851b1..596831d4d 100644
--- a/common/action.c
+++ b/common/action.c
@@ -50,14 +50,19 @@ void action_exec(keyevent_t event)
50void process_action(keyrecord_t *record) 50void process_action(keyrecord_t *record)
51{ 51{
52 keyevent_t event = record->event; 52 keyevent_t event = record->event;
53#ifndef NO_ACTION_TAPPING
53 uint8_t tap_count = record->tap.count; 54 uint8_t tap_count = record->tap.count;
55#endif
54 56
55 if (IS_NOEVENT(event)) { return; } 57 if (IS_NOEVENT(event)) { return; }
56 58
57 action_t action = layer_switch_get_action(event.key); 59 action_t action = layer_switch_get_action(event.key);
58 debug("ACTION: "); debug_action(action); 60 debug("ACTION: "); debug_action(action);
59 debug(" keymaps: "); keymap_debug(); 61#ifndef NO_ACTION_LAYER
60 debug(" default_layer: "); debug_dec(default_layer); debug("\n"); 62 debug(" layer_state: "); layer_debug();
63 debug(" default_layer_state: "); default_layer_debug();
64#endif
65 debug("\n");
61 66
62 switch (action.kind.id) { 67 switch (action.kind.id) {
63 /* Key and Mods */ 68 /* Key and Mods */
@@ -92,7 +97,7 @@ void process_action(keyrecord_t *record)
92 { 97 {
93 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : 98 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
94 action.key.mods<<4; 99 action.key.mods<<4;
95 switch (action.layer.code) { 100 switch (action.layer_tap.code) {
96 #ifndef NO_ACTION_ONESHOT 101 #ifndef NO_ACTION_ONESHOT
97 case 0x00: 102 case 0x00:
98 // Oneshot modifier 103 // Oneshot modifier
@@ -200,163 +205,86 @@ void process_action(keyrecord_t *record)
200#endif 205#endif
201#ifndef NO_ACTION_LAYER 206#ifndef NO_ACTION_LAYER
202 case ACT_LAYER: 207 case ACT_LAYER:
203 case ACT_LAYER1: 208 if (action.layer_bitop.on == 0) {
204 switch (action.layer.code) { 209 /* Default Layer Bitwise Operation */
205 /* Keymap clear */ 210 if (!event.pressed) {
206 case OP_RESET: 211 uint8_t shift = action.layer_bitop.part*4;
207 switch (action.layer.val & 0x03) { 212 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
208 case 0: 213 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
209 // NOTE: reserved 214 switch (action.layer_bitop.op) {
210 keymap_clear(); 215 case OP_BIT_AND: default_layer_and(bits | mask); break;
211 break; 216 case OP_BIT_OR: default_layer_or(bits | mask); break;
212 case ON_PRESS: 217 case OP_BIT_XOR: default_layer_xor(bits | mask); break;
213 if (event.pressed) { 218 case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
214 keymap_clear();
215 }
216 break;
217 case ON_RELEASE:
218 if (!event.pressed) {
219 keymap_clear();
220 }
221 break;
222 case ON_BOTH:
223 keymap_clear();
224 break;
225 /* NOTE: 4-7 rserved */
226 } 219 }
227 break; 220 }
228 /* Keymap Reset default layer */ 221 } else {
229 case (OP_RESET | ON_PRESS): 222 /* Layer Bitwise Operation */
230 if (event.pressed) { 223 if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
231 default_layer_set(action.layer.val); 224 (action.layer_bitop.on & ON_RELEASE)) {
232 } 225 uint8_t shift = action.layer_bitop.part*4;
233 break; 226 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
234 case (OP_RESET | ON_RELEASE): 227 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
235 if (!event.pressed) { 228 switch (action.layer_bitop.op) {
236 default_layer_set(action.layer.val); 229 case OP_BIT_AND: layer_and(bits | mask); break;
230 case OP_BIT_OR: layer_or(bits | mask); break;
231 case OP_BIT_XOR: layer_xor(bits | mask); break;
232 case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
237 } 233 }
238 break; 234 }
239 case (OP_RESET | ON_BOTH): 235 }
240 default_layer_set(action.layer.val); 236 break;
241 break; 237 #ifndef NO_ACTION_TAPPING
242 238 case ACT_LAYER_TAP:
243 /* Keymap Bit invert */ 239 case ACT_LAYER_TAP1:
244 case OP_INV: 240 switch (action.layer_tap.code) {
245 /* with tap toggle */ 241 case OP_TAP_TOGGLE:
242 /* tap toggle */
246 if (event.pressed) { 243 if (event.pressed) {
247 if (tap_count < TAPPING_TOGGLE) { 244 if (tap_count < TAPPING_TOGGLE) {
248 debug("KEYMAP_INV: tap toggle(press).\n"); 245 layer_invert(action.layer_tap.val);
249 keymap_invert(action.layer.val);
250 } 246 }
251 } else { 247 } else {
252 if (tap_count <= TAPPING_TOGGLE) { 248 if (tap_count <= TAPPING_TOGGLE) {
253 debug("KEYMAP_INV: tap toggle(release).\n"); 249 layer_invert(action.layer_tap.val);
254 keymap_invert(action.layer.val);
255 } 250 }
256 } 251 }
257 break; 252 break;
258 case (OP_INV | ON_PRESS): 253 case OP_ON_OFF:
259 if (event.pressed) { 254 event.pressed ? layer_on(action.layer_tap.val) :
260 keymap_invert(action.layer.val); 255 layer_off(action.layer_tap.val);
261 }
262 break; 256 break;
263 case (OP_INV | ON_RELEASE): 257 case OP_OFF_ON:
264 if (!event.pressed) { 258 event.pressed ? layer_off(action.layer_tap.val) :
265 keymap_invert(action.layer.val); 259 layer_on(action.layer_tap.val);
266 }
267 break; 260 break;
268 case (OP_INV | ON_BOTH): 261 case OP_SET_CLEAR:
269 keymap_invert(action.layer.val); 262 event.pressed ? layer_move(action.layer_tap.val) :
263 layer_clear();
270 break; 264 break;
271
272 /* Keymap Bit on */
273 case OP_ON:
274 if (event.pressed) {
275 keymap_on(action.layer.val);
276 } else {
277 keymap_off(action.layer.val);
278 }
279 break;
280 case (OP_ON | ON_PRESS):
281 if (event.pressed) {
282 keymap_on(action.layer.val);
283 }
284 break;
285 case (OP_ON | ON_RELEASE):
286 if (!event.pressed) {
287 keymap_on(action.layer.val);
288 }
289 break;
290 case (OP_ON | ON_BOTH):
291 keymap_on(action.layer.val);
292 break;
293
294 /* Keymap Bit off */
295 case OP_OFF:
296 if (event.pressed) {
297 keymap_off(action.layer.val);
298 } else {
299 keymap_on(action.layer.val);
300 }
301 break;
302 case (OP_OFF | ON_PRESS):
303 if (event.pressed) {
304 keymap_off(action.layer.val);
305 }
306 break;
307 case (OP_OFF | ON_RELEASE):
308 if (!event.pressed) {
309 keymap_off(action.layer.val);
310 }
311 break;
312 case (OP_OFF | ON_BOTH):
313 keymap_off(action.layer.val);
314 break;
315
316 /* Keymap Bit set */
317 case OP_SET:
318 if (event.pressed) {
319 keymap_set(action.layer.val);
320 } else {
321 keymap_clear();
322 }
323 break;
324 case (OP_SET | ON_PRESS):
325 if (event.pressed) {
326 keymap_set(action.layer.val);
327 }
328 break;
329 case (OP_SET | ON_RELEASE):
330 if (!event.pressed) {
331 keymap_set(action.layer.val);
332 }
333 break;
334 case (OP_SET | ON_BOTH):
335 keymap_set(action.layer.val);
336 break;
337
338 /* Keymap Bit invert with tap key */
339 default: 265 default:
266 /* tap key */
340 if (event.pressed) { 267 if (event.pressed) {
341 if (tap_count > 0) { 268 if (tap_count > 0) {
342 debug("KEYMAP_TAP_KEY: Tap: register_code\n"); 269 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
343 register_code(action.layer.code); 270 register_code(action.layer_tap.code);
344 } else { 271 } else {
345 debug("KEYMAP_TAP_KEY: No tap: On on press\n"); 272 debug("KEYMAP_TAP_KEY: No tap: On on press\n");
346 keymap_on(action.layer.val); 273 layer_on(action.layer_tap.val);
347 } 274 }
348 } else { 275 } else {
349 if (tap_count > 0) { 276 if (tap_count > 0) {
350 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); 277 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
351 unregister_code(action.layer.code); 278 unregister_code(action.layer_tap.code);
352 } else { 279 } else {
353 debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); 280 debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
354 keymap_off(action.layer.val); 281 layer_off(action.layer_tap.val);
355 } 282 }
356 } 283 }
357 break; 284 break;
358 } 285 }
359 break; 286 break;
287 #endif
360#endif 288#endif
361 /* Extentions */ 289 /* Extentions */
362#ifndef NO_ACTION_MACRO 290#ifndef NO_ACTION_MACRO
@@ -508,15 +436,9 @@ bool is_tap_key(key_t key)
508 switch (action.kind.id) { 436 switch (action.kind.id) {
509 case ACT_LMODS_TAP: 437 case ACT_LMODS_TAP:
510 case ACT_RMODS_TAP: 438 case ACT_RMODS_TAP:
439 case ACT_LAYER_TAP:
440 case ACT_LAYER_TAP1:
511 return true; 441 return true;
512 case ACT_LAYER:
513 switch (action.layer.code) {
514 case 0x04 ... 0xEF: /* tap key */
515 case OP_INV:
516 return true;
517 default:
518 return false;
519 }
520 case ACT_MACRO: 442 case ACT_MACRO:
521 case ACT_FUNCTION: 443 case ACT_FUNCTION:
522 if (action.func.opt & FUNC_TAP) { return true; } 444 if (action.func.opt & FUNC_TAP) { return true; }
@@ -555,7 +477,8 @@ void debug_action(action_t action)
555 case ACT_USAGE: debug("ACT_USAGE"); break; 477 case ACT_USAGE: debug("ACT_USAGE"); break;
556 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 478 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
557 case ACT_LAYER: debug("ACT_LAYER"); break; 479 case ACT_LAYER: debug("ACT_LAYER"); break;
558 case ACT_LAYER_BITOP: debug("ACT_LAYER_BITOP"); break; 480 case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break;
481 case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break;
559 case ACT_MACRO: debug("ACT_MACRO"); break; 482 case ACT_MACRO: debug("ACT_MACRO"); break;
560 case ACT_COMMAND: debug("ACT_COMMAND"); break; 483 case ACT_COMMAND: debug("ACT_COMMAND"); break;
561 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 484 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;