diff options
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 195 |
1 files changed, 142 insertions, 53 deletions
diff --git a/common/action.c b/common/action.c index 6528cd46c..9a8d75596 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "debug.h" | 25 | #include "debug.h" |
| 26 | #include "action.h" | 26 | #include "action.h" |
| 27 | #include "layer_stack.h" | ||
| 27 | 28 | ||
| 28 | 29 | ||
| 29 | /* default layer indicates base layer */ | 30 | /* default layer indicates base layer */ |
| @@ -209,14 +210,27 @@ void action_exec(keyevent_t event) | |||
| 209 | 210 | ||
| 210 | static action_t get_action(key_t key) | 211 | static action_t get_action(key_t key) |
| 211 | { | 212 | { |
| 212 | action_t action = action_for_key(current_layer, key); | 213 | action_t action; |
| 214 | action.code = ACTION_NO; | ||
| 213 | 215 | ||
| 214 | /* Transparently use default layer */ | 216 | /* layer stack */ |
| 215 | if (action.code == ACTION_TRANSPARENT) { | 217 | action = layer_stack_get_action(key); |
| 216 | // TODO: layer stacking | 218 | if (action.code != ACTION_TRANSPARENT) { |
| 217 | action = action_for_key(default_layer, key); | 219 | return action; |
| 218 | debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); | ||
| 219 | } | 220 | } |
| 221 | |||
| 222 | /* current layer: 0 means default layer */ | ||
| 223 | if (current_layer) { | ||
| 224 | action = action_for_key(current_layer, key); | ||
| 225 | if (action.code != ACTION_TRANSPARENT) { | ||
| 226 | debug("current layer: used. "); debug_dec(current_layer); debug("\n"); | ||
| 227 | return action; | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | /* default layer */ | ||
| 232 | debug("default layer: used. \n"); | ||
| 233 | action = action_for_key(default_layer, key); | ||
| 220 | return action; | 234 | return action; |
| 221 | } | 235 | } |
| 222 | 236 | ||
| @@ -287,7 +301,7 @@ static void process_action(keyrecord_t *record) | |||
| 287 | } else { | 301 | } else { |
| 288 | if (tap_count == 0) { | 302 | if (tap_count == 0) { |
| 289 | debug("MODS_TAP: Oneshot: cancel/del_mods\n"); | 303 | debug("MODS_TAP: Oneshot: cancel/del_mods\n"); |
| 290 | // cancel oneshot by holding. | 304 | // cancel oneshot on hold |
| 291 | oneshot_cancel(); | 305 | oneshot_cancel(); |
| 292 | del_mods(mods); | 306 | del_mods(mods); |
| 293 | } | 307 | } |
| @@ -377,7 +391,7 @@ static void process_action(keyrecord_t *record) | |||
| 377 | } | 391 | } |
| 378 | else { | 392 | else { |
| 379 | // NOTE: This is needed by legacy keymap support | 393 | // NOTE: This is needed by legacy keymap support |
| 380 | layer_switch(default_layer); | 394 | layer_switch(0); |
| 381 | } | 395 | } |
| 382 | break; | 396 | break; |
| 383 | case LAYER_ON_PRESS: | 397 | case LAYER_ON_PRESS: |
| @@ -390,22 +404,8 @@ static void process_action(keyrecord_t *record) | |||
| 390 | layer_switch(action.layer.val); | 404 | layer_switch(action.layer.val); |
| 391 | } | 405 | } |
| 392 | break; | 406 | break; |
| 393 | case LAYER_DEFAULT: /* default layer */ | 407 | case LAYER_ON_BOTH: |
| 394 | switch (action.layer.val) { | 408 | 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; | 409 | break; |
| 410 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 410 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 411 | if (event.pressed) { | 411 | if (event.pressed) { |
| @@ -419,30 +419,40 @@ static void process_action(keyrecord_t *record) | |||
| 419 | } | 419 | } |
| 420 | } | 420 | } |
| 421 | break; | 421 | break; |
| 422 | case LAYER_CHANGE_DEFAULT: /* change default layer */ | 422 | case LAYER_SET_DEFAULT_ON_PRESS: |
| 423 | if (event.pressed) { | 423 | if (event.pressed) { |
| 424 | default_layer = action.layer.val; | 424 | default_layer = action.layer.val; |
| 425 | layer_switch(default_layer); | 425 | layer_switch(0); |
| 426 | } | 426 | } |
| 427 | break; | 427 | break; |
| 428 | default: /* switch layer on hold and key on tap*/ | 428 | case LAYER_SET_DEFAULT_ON_RELEASE: |
| 429 | if (!event.pressed) { | ||
| 430 | default_layer = action.layer.val; | ||
| 431 | layer_switch(0); | ||
| 432 | } | ||
| 433 | break; | ||
| 434 | case LAYER_SET_DEFAULT_ON_BOTH: | ||
| 435 | default_layer = action.layer.val; | ||
| 436 | layer_switch(0); | ||
| 437 | break; | ||
| 438 | default: | ||
| 439 | /* tap key */ | ||
| 429 | if (event.pressed) { | 440 | if (event.pressed) { |
| 430 | if (tap_count > 0) { | 441 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 431 | debug("LAYER_PRESSED: Tap: register_code\n"); | 442 | debug("LAYER_SET: Tap: register_code\n"); |
| 432 | register_code(action.layer.code); | 443 | register_code(action.layer.code); |
| 433 | } else { | 444 | } else { |
| 434 | debug("LAYER_PRESSED: No tap: layer_switch\n"); | 445 | debug("LAYER_SET: No tap: layer_set(on press)\n"); |
| 435 | layer_switch(action.layer.val); | 446 | layer_switch(action.layer.val); |
| 436 | } | 447 | } |
| 437 | } else { | 448 | } else { |
| 438 | if (tap_count > 0) { | 449 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 439 | debug("LAYER_PRESSED: Tap: unregister_code\n"); | 450 | debug("LAYER_SET: Tap: unregister_code\n"); |
| 440 | unregister_code(action.layer.code); | 451 | unregister_code(action.layer.code); |
| 441 | } else { | 452 | } else { |
| 442 | //debug("LAYER_PRESSED: No tap: NO ACTION\n"); | ||
| 443 | // NOTE: This is needed by legacy keymap support | 453 | // NOTE: This is needed by legacy keymap support |
| 444 | debug("LAYER_PRESSED: No tap: return to default layer\n"); | 454 | debug("LAYER_SET: No tap: return to default layer(on release)\n"); |
| 445 | layer_switch(default_layer); | 455 | layer_switch(0); |
| 446 | } | 456 | } |
| 447 | } | 457 | } |
| 448 | break; | 458 | break; |
| @@ -452,9 +462,9 @@ static void process_action(keyrecord_t *record) | |||
| 452 | switch (action.layer.code) { | 462 | switch (action.layer.code) { |
| 453 | case LAYER_MOMENTARY: /* momentary */ | 463 | case LAYER_MOMENTARY: /* momentary */ |
| 454 | if (event.pressed) { | 464 | if (event.pressed) { |
| 455 | layer_switch(current_layer ^ action.layer.val); | 465 | layer_switch(current_layer | action.layer.val); |
| 456 | } else { | 466 | } else { |
| 457 | layer_switch(current_layer ^ action.layer.val); | 467 | layer_switch(current_layer & ~action.layer.val); |
| 458 | } | 468 | } |
| 459 | break; | 469 | break; |
| 460 | case LAYER_ON_PRESS: | 470 | case LAYER_ON_PRESS: |
| @@ -467,6 +477,9 @@ static void process_action(keyrecord_t *record) | |||
| 467 | layer_switch(current_layer ^ action.layer.val); | 477 | layer_switch(current_layer ^ action.layer.val); |
| 468 | } | 478 | } |
| 469 | break; | 479 | break; |
| 480 | case LAYER_ON_BOTH: | ||
| 481 | layer_switch(current_layer ^ action.layer.val); | ||
| 482 | break; | ||
| 470 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 483 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 471 | if (event.pressed) { | 484 | if (event.pressed) { |
| 472 | if (tap_count < TAPPING_TOGGLE) { | 485 | if (tap_count < TAPPING_TOGGLE) { |
| @@ -480,24 +493,30 @@ static void process_action(keyrecord_t *record) | |||
| 480 | } | 493 | } |
| 481 | } | 494 | } |
| 482 | break; | 495 | break; |
| 483 | case 0xFF: | 496 | case LAYER_SET_DEFAULT_ON_PRESS: |
| 484 | // change default layer | ||
| 485 | if (event.pressed) { | 497 | if (event.pressed) { |
| 486 | default_layer = current_layer ^ action.layer.val; | 498 | default_layer = default_layer ^ action.layer.val; |
| 487 | layer_switch(default_layer); | 499 | layer_switch(0); |
| 488 | } else { | 500 | } |
| 489 | default_layer = current_layer ^ action.layer.val; | 501 | break; |
| 490 | layer_switch(default_layer); | 502 | case LAYER_SET_DEFAULT_ON_RELEASE: |
| 503 | if (!event.pressed) { | ||
| 504 | default_layer = default_layer ^ action.layer.val; | ||
| 505 | layer_switch(0); | ||
| 491 | } | 506 | } |
| 492 | break; | 507 | break; |
| 508 | case LAYER_SET_DEFAULT_ON_BOTH: | ||
| 509 | default_layer = default_layer ^ action.layer.val; | ||
| 510 | layer_switch(0); | ||
| 511 | break; | ||
| 493 | default: | 512 | default: |
| 494 | // with tap key | 513 | // tap key |
| 495 | if (event.pressed) { | 514 | if (event.pressed) { |
| 496 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 515 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 497 | debug("LAYER_BIT: Tap: register_code\n"); | 516 | debug("LAYER_BIT: Tap: register_code\n"); |
| 498 | register_code(action.layer.code); | 517 | register_code(action.layer.code); |
| 499 | } else { | 518 | } else { |
| 500 | debug("LAYER_BIT: No tap: layer_switch(bit on)\n"); | 519 | debug("LAYER_BIT: No tap: layer_bit(on press)\n"); |
| 501 | layer_switch(current_layer ^ action.layer.val); | 520 | layer_switch(current_layer ^ action.layer.val); |
| 502 | } | 521 | } |
| 503 | } else { | 522 | } else { |
| @@ -505,13 +524,79 @@ static void process_action(keyrecord_t *record) | |||
| 505 | debug("LAYER_BIT: Tap: unregister_code\n"); | 524 | debug("LAYER_BIT: Tap: unregister_code\n"); |
| 506 | unregister_code(action.layer.code); | 525 | unregister_code(action.layer.code); |
| 507 | } else { | 526 | } else { |
| 508 | debug("LAYER_BIT: No tap: layer_switch(bit off)\n"); | 527 | debug("LAYER_BIT: No tap: layer_bit(on release)\n"); |
| 509 | layer_switch(current_layer ^ action.layer.val); | 528 | layer_switch(current_layer ^ action.layer.val); |
| 510 | } | 529 | } |
| 511 | } | 530 | } |
| 512 | break; | 531 | break; |
| 513 | } | 532 | } |
| 514 | break; | 533 | break; |
| 534 | case ACT_LAYER_STACK: | ||
| 535 | switch (action.layer.code) { | ||
| 536 | case LAYER_MOMENTARY: /* momentary */ | ||
| 537 | if (event.pressed) { | ||
| 538 | layer_stack_remove_then_push(action.layer.val); | ||
| 539 | layer_stack_debug(); | ||
| 540 | } else { | ||
| 541 | layer_stack_remove(action.layer.val); | ||
| 542 | layer_stack_debug(); | ||
| 543 | } | ||
| 544 | break; | ||
| 545 | case LAYER_ON_PRESS: | ||
| 546 | if (event.pressed) { | ||
| 547 | layer_stack_remove_or_push(action.layer.val); | ||
| 548 | layer_stack_debug(); | ||
| 549 | } | ||
| 550 | break; | ||
| 551 | case LAYER_ON_RELEASE: | ||
| 552 | if (!event.pressed) { | ||
| 553 | layer_stack_remove_or_push(action.layer.val); | ||
| 554 | layer_stack_debug(); | ||
| 555 | } | ||
| 556 | break; | ||
| 557 | case LAYER_ON_BOTH: | ||
| 558 | layer_stack_remove_or_push(action.layer.val); | ||
| 559 | layer_stack_debug(); | ||
| 560 | break; | ||
| 561 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | ||
| 562 | if (event.pressed) { | ||
| 563 | if (tap_count < TAPPING_TOGGLE) { | ||
| 564 | debug("LAYER_STACK: tap toggle(press).\n"); | ||
| 565 | layer_stack_remove_or_push(action.layer.val); | ||
| 566 | layer_stack_debug(); | ||
| 567 | } | ||
| 568 | } else { | ||
| 569 | if (tap_count <= TAPPING_TOGGLE) { | ||
| 570 | debug("LAYER_STACK: tap toggle(release).\n"); | ||
| 571 | layer_stack_remove_or_push(action.layer.val); | ||
| 572 | layer_stack_debug(); | ||
| 573 | } | ||
| 574 | } | ||
| 575 | break; | ||
| 576 | default: | ||
| 577 | // tap key | ||
| 578 | if (event.pressed) { | ||
| 579 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | ||
| 580 | debug("LAYER_STACK: Tap: register_code\n"); | ||
| 581 | register_code(action.layer.code); | ||
| 582 | } else { | ||
| 583 | debug("LAYER_STACK: No tap: layer_stack(on press)\n"); | ||
| 584 | layer_stack_remove_or_push(action.layer.val); | ||
| 585 | layer_stack_debug(); | ||
| 586 | } | ||
| 587 | } else { | ||
| 588 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | ||
| 589 | debug("LAYER_STACK: Tap: unregister_code\n"); | ||
| 590 | unregister_code(action.layer.code); | ||
| 591 | } else { | ||
| 592 | debug("LAYER_STACK: No tap: layer_stack(on release)\n"); | ||
| 593 | layer_stack_remove_or_push(action.layer.val); | ||
| 594 | layer_stack_debug(); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | break; | ||
| 598 | } | ||
| 599 | break; | ||
| 515 | 600 | ||
| 516 | /* Extentions */ | 601 | /* Extentions */ |
| 517 | case ACT_MACRO: | 602 | case ACT_MACRO: |
| @@ -839,7 +924,10 @@ bool is_tap_key(key_t key) | |||
| 839 | case LAYER_MOMENTARY: | 924 | case LAYER_MOMENTARY: |
| 840 | case LAYER_ON_PRESS: | 925 | case LAYER_ON_PRESS: |
| 841 | case LAYER_ON_RELEASE: | 926 | case LAYER_ON_RELEASE: |
| 842 | case LAYER_DEFAULT: | 927 | case LAYER_ON_BOTH: |
| 928 | case LAYER_SET_DEFAULT_ON_PRESS: | ||
| 929 | case LAYER_SET_DEFAULT_ON_RELEASE: | ||
| 930 | case LAYER_SET_DEFAULT_ON_BOTH: | ||
| 843 | return false; | 931 | return false; |
| 844 | case LAYER_TAP_TOGGLE: | 932 | case LAYER_TAP_TOGGLE: |
| 845 | default: /* tap key */ | 933 | default: /* tap key */ |
| @@ -876,8 +964,9 @@ static void debug_action(action_t action) | |||
| 876 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; | 964 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; |
| 877 | case ACT_USAGE: debug("ACT_USAGE"); break; | 965 | case ACT_USAGE: debug("ACT_USAGE"); break; |
| 878 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; | 966 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
| 879 | case ACT_LAYER: debug("ACT_LAYER"); break; | 967 | case ACT_LAYER: debug("ACT_LAYER"); break; |
| 880 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; | 968 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; |
| 969 | case ACT_LAYER_STACK: debug("ACT_LAYER_STACK"); break; | ||
| 881 | case ACT_MACRO: debug("ACT_MACRO"); break; | 970 | case ACT_MACRO: debug("ACT_MACRO"); break; |
| 882 | case ACT_COMMAND: debug("ACT_COMMAND"); break; | 971 | case ACT_COMMAND: debug("ACT_COMMAND"); break; |
| 883 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; | 972 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
