aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action.c255
-rw-r--r--common/action.h133
2 files changed, 284 insertions, 104 deletions
diff --git a/common/action.c b/common/action.c
index 6528cd46c..d0c9ddb0a 100644
--- a/common/action.c
+++ b/common/action.c
@@ -163,6 +163,85 @@ static void oneshot_toggle(void)
163} 163}
164 164
165 165
166/*
167 * Layer stack
168 */
169#define LAYER_STACK_SIZE 8
170typedef struct {
171 uint8_t layer:4;
172 uint8_t next:3;
173 bool used;
174} layer_item_t;
175
176static uint8_t top_layer = 0;
177// [0] is sentinel and not used. [0] is null item.
178static layer_item_t layer_stack[LAYER_STACK_SIZE] = {};
179
180static bool layer_push(uint8_t layer)
181{
182 for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) {
183 if (!layer_stack[i].used) {
184 layer_stack[i] = (layer_item_t){ .layer = layer,
185 .next = top_layer,
186 .used = true };
187 top_layer = i;
188 return true;
189 }
190 }
191 return false;
192}
193static bool layer_pop(void)
194{
195 if (layer_stack[top_layer].used) {
196 uint8_t popped = top_layer;
197 top_layer = layer_stack[popped].next;
198 layer_stack[popped] = (layer_item_t){};
199 return true;
200 }
201 return false;
202}
203static bool layer_remove(uint8_t layer)
204{
205 if (layer_stack[top_layer].used && layer_stack[top_layer].layer == layer) {
206 layer_pop();
207 debug("layer_remove: top_layer\n");
208 return true;
209 }
210
211 for (uint8_t i = top_layer; layer_stack[i].used; i = layer_stack[i].next) {
212 debug("layer_remove: ["); debug_dec(i); debug("]");
213 debug_dec(layer_stack[i].layer); debug("\n");
214 uint8_t removed = layer_stack[i].next;
215 if (layer_stack[removed].used && layer_stack[removed].layer == layer) {
216 layer_stack[i].next = layer_stack[removed].next;
217 layer_stack[removed] = (layer_item_t){};
218 debug("layer_remove: removed.\n");
219 return true;
220 }
221 }
222 return false;
223}
224static bool layer_remove_then_push(uint8_t layer)
225{
226 layer_remove(layer);
227 return layer_push(layer);
228}
229static bool layer_remove_or_push(uint8_t layer)
230{
231 return (layer_remove(layer)) || layer_push(layer);
232}
233static void debug_layer_stack(void)
234{
235 debug("layer_stack: ");
236 layer_item_t item = layer_stack[top_layer];
237 while (item.used) {
238 debug_dec(item.layer);
239 debug("["); debug_dec(item.next); debug("]");
240 item = layer_stack[item.next];
241 }
242 debug("\n");
243}
244
166 245
167void action_exec(keyevent_t event) 246void action_exec(keyevent_t event)
168{ 247{
@@ -209,13 +288,26 @@ void action_exec(keyevent_t event)
209 288
210static action_t get_action(key_t key) 289static action_t get_action(key_t key)
211{ 290{
212 action_t action = action_for_key(current_layer, key); 291 action_t action;
292
293 /* layer stack */
294 for (layer_item_t i = layer_stack[top_layer]; i.used; i = layer_stack[i.next]) {
295 action = action_for_key(i.layer, key);
296 if (action.code != ACTION_TRANSPARENT) {
297 debug_layer_stack();
298 debug("layer_stack: used. "); debug_dec(i.layer); debug("\n");
299 return action;
300 }
301 debug("layer_stack: through. "); debug_dec(i.layer); debug("\n");
302 }
213 303
214 /* Transparently use default layer */ 304 /* current layer */
305 action = action_for_key(current_layer, key);
306
307 /* default layer */
215 if (action.code == ACTION_TRANSPARENT) { 308 if (action.code == ACTION_TRANSPARENT) {
216 // TODO: layer stacking
217 action = action_for_key(default_layer, key);
218 debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); 309 debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n");
310 action = action_for_key(default_layer, key);
219 } 311 }
220 return action; 312 return action;
221} 313}
@@ -287,7 +379,7 @@ static void process_action(keyrecord_t *record)
287 } else { 379 } else {
288 if (tap_count == 0) { 380 if (tap_count == 0) {
289 debug("MODS_TAP: Oneshot: cancel/del_mods\n"); 381 debug("MODS_TAP: Oneshot: cancel/del_mods\n");
290 // cancel oneshot by holding. 382 // cancel oneshot on hold
291 oneshot_cancel(); 383 oneshot_cancel();
292 del_mods(mods); 384 del_mods(mods);
293 } 385 }
@@ -390,22 +482,8 @@ static void process_action(keyrecord_t *record)
390 layer_switch(action.layer.val); 482 layer_switch(action.layer.val);
391 } 483 }
392 break; 484 break;
393 case LAYER_DEFAULT: /* default layer */ 485 case LAYER_ON_BOTH:
394 switch (action.layer.val) { 486 layer_switch(action.layer.val);
395 case DEFAULT_ON_BOTH:
396 layer_switch(default_layer);
397 break;
398 case DEFAULT_ON_PRESS:
399 if (event.pressed) {
400 layer_switch(default_layer);
401 }
402 break;
403 case DEFAULT_ON_RELEASE:
404 if (!event.pressed) {
405 layer_switch(default_layer);
406 }
407 break;
408 }
409 break; 487 break;
410 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 488 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
411 if (event.pressed) { 489 if (event.pressed) {
@@ -419,29 +497,39 @@ static void process_action(keyrecord_t *record)
419 } 497 }
420 } 498 }
421 break; 499 break;
422 case LAYER_CHANGE_DEFAULT: /* change default layer */ 500 case LAYER_SET_DEFAULT_ON_PRESS:
423 if (event.pressed) { 501 if (event.pressed) {
424 default_layer = action.layer.val; 502 default_layer = action.layer.val;
425 layer_switch(default_layer); 503 layer_switch(default_layer);
426 } 504 }
427 break; 505 break;
428 default: /* switch layer on hold and key on tap*/ 506 case LAYER_SET_DEFAULT_ON_RELEASE:
507 if (!event.pressed) {
508 default_layer = action.layer.val;
509 layer_switch(default_layer);
510 }
511 break;
512 case LAYER_SET_DEFAULT_ON_BOTH:
513 default_layer = action.layer.val;
514 layer_switch(default_layer);
515 break;
516 default:
517 /* tap key */
429 if (event.pressed) { 518 if (event.pressed) {
430 if (tap_count > 0) { 519 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
431 debug("LAYER_PRESSED: Tap: register_code\n"); 520 debug("LAYER_SET: Tap: register_code\n");
432 register_code(action.layer.code); 521 register_code(action.layer.code);
433 } else { 522 } else {
434 debug("LAYER_PRESSED: No tap: layer_switch\n"); 523 debug("LAYER_SET: No tap: layer_set(on press)\n");
435 layer_switch(action.layer.val); 524 layer_switch(action.layer.val);
436 } 525 }
437 } else { 526 } else {
438 if (tap_count > 0) { 527 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
439 debug("LAYER_PRESSED: Tap: unregister_code\n"); 528 debug("LAYER_SET: Tap: unregister_code\n");
440 unregister_code(action.layer.code); 529 unregister_code(action.layer.code);
441 } else { 530 } else {
442 //debug("LAYER_PRESSED: No tap: NO ACTION\n");
443 // NOTE: This is needed by legacy keymap support 531 // NOTE: This is needed by legacy keymap support
444 debug("LAYER_PRESSED: No tap: return to default layer\n"); 532 debug("LAYER_SET: No tap: return to default layer(on release)\n");
445 layer_switch(default_layer); 533 layer_switch(default_layer);
446 } 534 }
447 } 535 }
@@ -452,9 +540,9 @@ static void process_action(keyrecord_t *record)
452 switch (action.layer.code) { 540 switch (action.layer.code) {
453 case LAYER_MOMENTARY: /* momentary */ 541 case LAYER_MOMENTARY: /* momentary */
454 if (event.pressed) { 542 if (event.pressed) {
455 layer_switch(current_layer ^ action.layer.val); 543 layer_switch(current_layer | action.layer.val);
456 } else { 544 } else {
457 layer_switch(current_layer ^ action.layer.val); 545 layer_switch(current_layer & ~action.layer.val);
458 } 546 }
459 break; 547 break;
460 case LAYER_ON_PRESS: 548 case LAYER_ON_PRESS:
@@ -467,6 +555,9 @@ static void process_action(keyrecord_t *record)
467 layer_switch(current_layer ^ action.layer.val); 555 layer_switch(current_layer ^ action.layer.val);
468 } 556 }
469 break; 557 break;
558 case LAYER_ON_BOTH:
559 layer_switch(current_layer ^ action.layer.val);
560 break;
470 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ 561 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
471 if (event.pressed) { 562 if (event.pressed) {
472 if (tap_count < TAPPING_TOGGLE) { 563 if (tap_count < TAPPING_TOGGLE) {
@@ -480,24 +571,30 @@ static void process_action(keyrecord_t *record)
480 } 571 }
481 } 572 }
482 break; 573 break;
483 case 0xFF: 574 case LAYER_SET_DEFAULT_ON_PRESS:
484 // change default layer
485 if (event.pressed) { 575 if (event.pressed) {
486 default_layer = current_layer ^ action.layer.val; 576 default_layer = current_layer ^ action.layer.val;
487 layer_switch(default_layer); 577 layer_switch(default_layer);
488 } else { 578 }
579 break;
580 case LAYER_SET_DEFAULT_ON_RELEASE:
581 if (!event.pressed) {
489 default_layer = current_layer ^ action.layer.val; 582 default_layer = current_layer ^ action.layer.val;
490 layer_switch(default_layer); 583 layer_switch(default_layer);
491 } 584 }
492 break; 585 break;
586 case LAYER_SET_DEFAULT_ON_BOTH:
587 default_layer = current_layer ^ action.layer.val;
588 layer_switch(default_layer);
589 break;
493 default: 590 default:
494 // with tap key 591 // tap key
495 if (event.pressed) { 592 if (event.pressed) {
496 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 593 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
497 debug("LAYER_BIT: Tap: register_code\n"); 594 debug("LAYER_BIT: Tap: register_code\n");
498 register_code(action.layer.code); 595 register_code(action.layer.code);
499 } else { 596 } else {
500 debug("LAYER_BIT: No tap: layer_switch(bit on)\n"); 597 debug("LAYER_BIT: No tap: layer_bit(on press)\n");
501 layer_switch(current_layer ^ action.layer.val); 598 layer_switch(current_layer ^ action.layer.val);
502 } 599 }
503 } else { 600 } else {
@@ -505,13 +602,79 @@ static void process_action(keyrecord_t *record)
505 debug("LAYER_BIT: Tap: unregister_code\n"); 602 debug("LAYER_BIT: Tap: unregister_code\n");
506 unregister_code(action.layer.code); 603 unregister_code(action.layer.code);
507 } else { 604 } else {
508 debug("LAYER_BIT: No tap: layer_switch(bit off)\n"); 605 debug("LAYER_BIT: No tap: layer_bit(on release)\n");
509 layer_switch(current_layer ^ action.layer.val); 606 layer_switch(current_layer ^ action.layer.val);
510 } 607 }
511 } 608 }
512 break; 609 break;
513 } 610 }
514 break; 611 break;
612 case ACT_LAYER_STACK:
613 switch (action.layer.code) {
614 case LAYER_MOMENTARY: /* momentary */
615 if (event.pressed) {
616 layer_remove_then_push(action.layer.val);
617 debug_layer_stack();
618 } else {
619 layer_remove(action.layer.val);
620 debug_layer_stack();
621 }
622 break;
623 case LAYER_ON_PRESS:
624 if (event.pressed) {
625 layer_remove_or_push(action.layer.val);
626 debug_layer_stack();
627 }
628 break;
629 case LAYER_ON_RELEASE:
630 if (!event.pressed) {
631 layer_remove_or_push(action.layer.val);
632 debug_layer_stack();
633 }
634 break;
635 case LAYER_ON_BOTH:
636 layer_remove_or_push(action.layer.val);
637 debug_layer_stack();
638 break;
639 case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
640 if (event.pressed) {
641 if (tap_count < TAPPING_TOGGLE) {
642 debug("LAYER_STACK: tap toggle(press).\n");
643 layer_remove_or_push(action.layer.val);
644 debug_layer_stack();
645 }
646 } else {
647 if (tap_count <= TAPPING_TOGGLE) {
648 debug("LAYER_STACK: tap toggle(release).\n");
649 layer_remove_or_push(action.layer.val);
650 debug_layer_stack();
651 }
652 }
653 break;
654 default:
655 // tap key
656 if (event.pressed) {
657 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
658 debug("LAYER_STACK: Tap: register_code\n");
659 register_code(action.layer.code);
660 } else {
661 debug("LAYER_STACK: No tap: layer_stack(on press)\n");
662 layer_remove_or_push(action.layer.val);
663 debug_layer_stack();
664 }
665 } else {
666 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
667 debug("LAYER_STACK: Tap: unregister_code\n");
668 unregister_code(action.layer.code);
669 } else {
670 debug("LAYER_STACK: No tap: layer_stack(on release)\n");
671 layer_remove_or_push(action.layer.val);
672 debug_layer_stack();
673 }
674 }
675 break;
676 }
677 break;
515 678
516 /* Extentions */ 679 /* Extentions */
517 case ACT_MACRO: 680 case ACT_MACRO:
@@ -839,7 +1002,10 @@ bool is_tap_key(key_t key)
839 case LAYER_MOMENTARY: 1002 case LAYER_MOMENTARY:
840 case LAYER_ON_PRESS: 1003 case LAYER_ON_PRESS:
841 case LAYER_ON_RELEASE: 1004 case LAYER_ON_RELEASE:
842 case LAYER_DEFAULT: 1005 case LAYER_ON_BOTH:
1006 case LAYER_SET_DEFAULT_ON_PRESS:
1007 case LAYER_SET_DEFAULT_ON_RELEASE:
1008 case LAYER_SET_DEFAULT_ON_BOTH:
843 return false; 1009 return false;
844 case LAYER_TAP_TOGGLE: 1010 case LAYER_TAP_TOGGLE:
845 default: /* tap key */ 1011 default: /* tap key */
@@ -876,8 +1042,9 @@ static void debug_action(action_t action)
876 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 1042 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
877 case ACT_USAGE: debug("ACT_USAGE"); break; 1043 case ACT_USAGE: debug("ACT_USAGE"); break;
878 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 1044 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
879 case ACT_LAYER: debug("ACT_LAYER"); break; 1045 case ACT_LAYER: debug("ACT_LAYER"); break;
880 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; 1046 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break;
1047 case ACT_LAYER_STACK: debug("ACT_LAYER_STACK"); break;
881 case ACT_MACRO: debug("ACT_MACRO"); break; 1048 case ACT_MACRO: debug("ACT_MACRO"); break;
882 case ACT_COMMAND: debug("ACT_COMMAND"); break; 1049 case ACT_COMMAND: debug("ACT_COMMAND"); break;
883 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 1050 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
diff --git a/common/action.h b/common/action.h
index b9a6cb5b4..96b8ba2ed 100644
--- a/common/action.h
+++ b/common/action.h
@@ -162,25 +162,34 @@ bool waiting_buffer_has_anykey_pressed(void);
162 * 162 *
163 * Layer Actions 163 * Layer Actions
164 * ------------- 164 * -------------
165 * ACT_LAYER(1000): Set layer 165 * ACT_LAYER(1000): Set layer
166 * ACT_LAYER_BIT(1001): Bit-op layer 166 * ACT_LAYER_BIT(1001): Bit-op layer
167 * ACT_LAYER_STACK: Layer stack
167 * 168 *
168 * 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) 169 * 1000|LLLL|0000 0000 set current layer on press and return to default on release(momentary)
169 * 1000|LLLL|0000 0001 set L to layer on press 170 * 1000|LLLL|0000 0001 set current layer on press
170 * 1000|LLLL|0000 0010 set L to layer on release 171 * 1000|LLLL|0000 0010 set current layer on release
171 * 1000|----|0000 0011 set default to layer on both(return to default layer) 172 * 1000|LLLL|0000 0011 set current layer on both
172 * 1000|LLLL| keycode set L to layer while hold and send key on tap 173 * 1000|LLLL| keycode set current layer on hold and send key on tap
173 * 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps 174 * 1000|LLLL|1111 0000 set current layer on hold and toggle on several taps
174 * 1000|LLLL|1111 1111 set L to default and layer(on press) 175 * 1000|DDDD|1111 1111 set default layer on press
176 * L: 0 means default layer
175 * 177 *
176 * 1001|BBBB|0000 0000 (not used) 178 * 1001|BBBB|0000 0000 bit-on current layer on press and bit-off on release(momentary)
177 * 1001|BBBB|0000 0001 bit-xor layer with B on press 179 * 1001|BBBB|0000 0001 bit-xor current layer on press
178 * 1001|BBBB|0000 0010 bit-xor layer with B on release 180 * 1001|BBBB|0000 0010 bit-xor current layer on release
179 * 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary) 181 * 1001|BBBB|0000 0011 bit-xor current layer on both
180 * 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap 182 * 1001|BBBB| keycode bit-xor current layer on hold and send key on tap
181 * 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps 183 * 1001|BBBB|1111 0000 bit-xor current layer on hold and toggle on several taps
182 * 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press) 184 * 1001|BBBB|1111 1111 bit-xor default layer on both
183 * 185 *
186 * 1011|LLLL|0000 0000 push on press and remove on release(momentary)
187 * 1011|LLLL|0000 0001 push or remove on press
188 * 1011|LLLL|0000 0010 push or remove on release
189 * 1011|LLLL|0000 0011 push or remove on both
190 * 1011|LLLL| keycode push or remove on hold and send key on tap
191 * 1011|LLLL|1111 0000 push or remove on hold and toggle on several taps
192 * 1011|LLLL|1111 1111 (not used)
184 * 193 *
185 * 194 *
186 * Extensions(11XX) 195 * Extensions(11XX)
@@ -210,6 +219,7 @@ enum action_kind_id {
210 219
211 ACT_LAYER = 0b1000, 220 ACT_LAYER = 0b1000,
212 ACT_LAYER_BIT = 0b1001, 221 ACT_LAYER_BIT = 0b1001,
222 ACT_LAYER_STACK = 0b1011,
213 223
214 ACT_MACRO = 0b1100, 224 ACT_MACRO = 0b1100,
215 ACT_COMMAND = 0b1110, 225 ACT_COMMAND = 0b1110,
@@ -223,20 +233,20 @@ enum action_kind_id {
223#define ACTION(kind, param) ((kind)<<12 | (param)) 233#define ACTION(kind, param) ((kind)<<12 | (param))
224#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) 234#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F)
225 235
226/* Key */ 236/*
237 * Key
238 */
227#define ACTION_KEY(key) ACTION(ACT_LMODS, key) 239#define ACTION_KEY(key) ACTION(ACT_LMODS, key)
228/* Mods & key */ 240/* Mods & key */
229#define ACTION_LMODS(mods) ACTION(ACT_LMODS, MODS4(mods)<<8 | 0x00) 241#define ACTION_LMODS(mods) ACTION(ACT_LMODS, MODS4(mods)<<8 | 0x00)
230#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, MODS4(mods)<<8 | (key)) 242#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, MODS4(mods)<<8 | (key))
231#define ACTION_RMODS(mods) ACTION(ACT_RMODS, MODS4(mods)<<8 | 0x00) 243#define ACTION_RMODS(mods) ACTION(ACT_RMODS, MODS4(mods)<<8 | 0x00)
232#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, MODS4(mods)<<8 | (key)) 244#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, MODS4(mods)<<8 | (key))
233/* Mod & key */
234#define ACTION_LMOD(mod) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | 0x00) 245#define ACTION_LMOD(mod) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
235#define ACTION_LMOD_KEY(mod, key) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | (key)) 246#define ACTION_LMOD_KEY(mod, key) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | (key))
236#define ACTION_RMOD(mod) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | 0x00) 247#define ACTION_RMOD(mod) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
237#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key)) 248#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key))
238 249/* Tap key */
239/* Mods + Tap key */
240enum mods_codes { 250enum mods_codes {
241 MODS_ONESHOT = 0x00, 251 MODS_ONESHOT = 0x00,
242}; 252};
@@ -244,7 +254,6 @@ enum mods_codes {
244#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT) 254#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
245#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key)) 255#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key))
246#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT) 256#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
247/* Mod + Tap key */
248#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key)) 257#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
249#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) 258#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
250#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key)) 259#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
@@ -252,73 +261,77 @@ enum mods_codes {
252 261
253 262
254/* 263/*
255 * Switch layer 264 * Layer switching
256 */ 265 */
257enum layer_codes { 266enum layer_codes {
258 LAYER_MOMENTARY = 0, 267 LAYER_MOMENTARY = 0,
259 LAYER_ON_PRESS = 1, 268 LAYER_ON_PRESS = 1,
260 LAYER_ON_RELEASE = 2, 269 LAYER_ON_RELEASE = 2,
261 LAYER_DEFAULT =3, 270 LAYER_ON_BOTH =3,
262 LAYER_TAP_TOGGLE = 0xF0, 271 LAYER_TAP_TOGGLE = 0xF0,
263 LAYER_CHANGE_DEFAULT = 0xFF 272 LAYER_SET_DEFAULT_ON_PRESS = 0xFD,
273 LAYER_SET_DEFAULT_ON_RELEASE = 0xFE,
274 LAYER_SET_DEFAULT_ON_BOTH = 0xFF
264}; 275};
265enum layer_vals_default {
266 DEFAULT_ON_PRESS = 1,
267 DEFAULT_ON_RELEASE = 2,
268 DEFAULT_ON_BOTH = 3,
269};
270
271/* 276/*
272 * return to default layer 277 * Default layer
278 */
279/* set default layer */
280#define ACTION_LAYER_SET_DEFAULT(layer) ACTION_LAYER_SET_DEFAULT_R(layer)
281#define ACTION_LAYER_SET_DEFAULT_P(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_SET_DEFAULT_ON_PRESS)
282#define ACTION_LAYER_SET_DEFAULT_R(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_SET_DEFAULT_ON_RELEASE)
283#define ACTION_LAYER_SET_DEFAULT_B(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_SET_DEFAULT_ON_BOTH)
284/* bit-xor default layer */
285#define ACTION_LAYER_BIT_DEFAULT(bits) ACTION_LAYER_BIT_DEFAULT_R(bits)
286#define ACTION_LAYER_BIT_DEFAULT_P(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_SET_DEFAULT_ON_PRESS)
287#define ACTION_LAYER_BIT_DEFAULT_R(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_SET_DEFAULT_ON_RELEASE)
288#define ACTION_LAYER_BIT_DEFAULT_B(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_SET_DEFAULT_ON_BOTH)
289/*
290 * Current layer: Return to default layer
273 */ 291 */
274#define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R 292#define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R
275/* set default layer on press */ 293#define ACTION_LAYER_DEFAULT_P ACTION_LAYER_SET_P(0)
276#define ACTION_LAYER_DEFAULT_P ACTION(ACT_LAYER, DEFAULT_ON_PRESS<<8 | LAYER_DEFAULT) 294#define ACTION_LAYER_DEFAULT_R ACTION_LAYER_SET_R(0)
277/* set default layer on release */ 295#define ACTION_LAYER_DEFAULT_B ACTION_LAYER_SET_B(0)
278#define ACTION_LAYER_DEFAULT_R ACTION(ACT_LAYER, DEFAULT_ON_RELEASE<<8 | LAYER_DEFAULT)
279/* change default layer and set layer */
280
281/* 296/*
282 * Set layer 297 * Current layer: Set
283 */ 298 */
284/* set layer on press and none on release */
285#define ACTION_LAYER_SET(layer) ACTION_LAYER_SET_P(layer) 299#define ACTION_LAYER_SET(layer) ACTION_LAYER_SET_P(layer)
286/* set layer on press and set default on release (This is needed by legacy keymap support.) */
287#define ACTION_LAYER_SET_MOMENTARY(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_MOMENTARY) 300#define ACTION_LAYER_SET_MOMENTARY(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_MOMENTARY)
288/* set layer on press and none on release */
289#define ACTION_LAYER_SET_TOGGLE(layer) ACTION_LAYER_SET_R(layer) 301#define ACTION_LAYER_SET_TOGGLE(layer) ACTION_LAYER_SET_R(layer)
290/* set layer while hold and send key on tap */
291#define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key))
292/* set layer on press */
293#define ACTION_LAYER_SET_P(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_PRESS) 302#define ACTION_LAYER_SET_P(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_PRESS)
294/* set layer on release */
295#define ACTION_LAYER_SET_R(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_RELEASE) 303#define ACTION_LAYER_SET_R(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_RELEASE)
296/* set layer on hold and toggle on several taps */ 304#define ACTION_LAYER_SET_B(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_BOTH)
297#define ACTION_LAYER_SET_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_TAP_TOGGLE) 305#define ACTION_LAYER_SET_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_TAP_TOGGLE)
298/* set default layer on both press and release */ 306#define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key))
299#define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT)
300
301/* 307/*
302 * Bit-op layer 308 * Current layer: Bit-op
303 */ 309 */
304/* bit-xor on both press and release */
305#define ACTION_LAYER_BIT(bits) ACTION_LAYER_BIT_MOMENTARY(bits) 310#define ACTION_LAYER_BIT(bits) ACTION_LAYER_BIT_MOMENTARY(bits)
306#define ACTION_LAYER_BIT_MOMENTARY(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_MOMENTARY) 311#define ACTION_LAYER_BIT_MOMENTARY(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_MOMENTARY)
307/* bit-xor on press */
308#define ACTION_LAYER_BIT_TOGGLE(bits) ACTION_LAYER_BIT_R(bits) 312#define ACTION_LAYER_BIT_TOGGLE(bits) ACTION_LAYER_BIT_R(bits)
309/* bit-xor while hold and send key on tap */
310#define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key))
311/* bit-xor on press */
312#define ACTION_LAYER_BIT_P(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_PRESS) 313#define ACTION_LAYER_BIT_P(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_PRESS)
313/* bit-xor on release */
314#define ACTION_LAYER_BIT_R(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_RELEASE) 314#define ACTION_LAYER_BIT_R(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_RELEASE)
315/* bit-xor while hold and toggle on several taps */ 315#define ACTION_LAYER_BIT_B(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_BOTH)
316#define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE) 316#define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE)
317/* bit-xor default layer and set layer */ 317#define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key))
318#define ACTION_LAYER_BIT_DEFAULT(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_CHANGE_DEFAULT) 318/*
319 * Layer Stack
320 */
321/* momentary */
322#define ACTION_LAYER_STACK(layer) ACTION_LAYER_STACK_MOMENTARY(layer)
323#define ACTION_LAYER_STACK_MOMENTARY(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_MOMENTARY)
324#define ACTION_LAYER_STACK_TOGGLE(layer) ACTION_LAYER_STACK_R(layer)
325#define ACTION_LAYER_STACK_P(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_PRESS)
326#define ACTION_LAYER_STACK_R(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_RELEASE)
327#define ACTION_LAYER_STACK_B(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_ON_BOTH)
328#define ACTION_LAYER_STACK_TAP_TOGGLE(layer) ACTION(ACT_LAYER_STACK, (layer)<<8 | LAYER_TAP_TOGGLE)
329#define ACTION_LAYER_STACK_TAP_KEY(layer, key) ACTION(ACT_LAYER_STACK, (layer)<<8 | (key))
319 330
320 331
321/* HID Usage */ 332/*
333 * HID Usage
334 */
322enum usage_pages { 335enum usage_pages {
323 PAGE_SYSTEM, 336 PAGE_SYSTEM,
324 PAGE_CONSUMER 337 PAGE_CONSUMER