diff options
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 107 |
1 files changed, 40 insertions, 67 deletions
diff --git a/common/action.c b/common/action.c index 4f0a5f906..246fd99d8 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -27,12 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #include "layer_switch.h" | 27 | #include "layer_switch.h" |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | /* default layer indicates base layer */ | ||
| 31 | uint8_t default_layer = 0; | ||
| 32 | /* current layer indicates active layer at this time */ | ||
| 33 | uint8_t current_layer = 0; | ||
| 34 | |||
| 35 | |||
| 36 | static void process_action(keyrecord_t *record); | 30 | static void process_action(keyrecord_t *record); |
| 37 | static bool process_tapping(keyrecord_t *record); | 31 | static bool process_tapping(keyrecord_t *record); |
| 38 | static void waiting_buffer_scan_tap(void); | 32 | static void waiting_buffer_scan_tap(void); |
| @@ -219,17 +213,8 @@ static action_t get_action(key_t key) | |||
| 219 | return action; | 213 | return action; |
| 220 | } | 214 | } |
| 221 | 215 | ||
| 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 */ | 216 | /* default layer */ |
| 232 | debug("default layer: used. \n"); | 217 | //debug("get_aciton: default layer: "); debug_dec(default_layer); debug("\n"); |
| 233 | action = action_for_key(default_layer, key); | 218 | action = action_for_key(default_layer, key); |
| 234 | return action; | 219 | return action; |
| 235 | } | 220 | } |
| @@ -242,7 +227,8 @@ static void process_action(keyrecord_t *record) | |||
| 242 | if (IS_NOEVENT(event)) { return; } | 227 | if (IS_NOEVENT(event)) { return; } |
| 243 | 228 | ||
| 244 | action_t action = get_action(event.key); | 229 | action_t action = get_action(event.key); |
| 245 | debug("ACTION: "); debug_action(action); debug("\n"); | 230 | debug("ACTION: "); debug_action(action); debug(" "); |
| 231 | layer_switch_debug(); debug("["); debug_dec(default_layer); debug("]\n"); | ||
| 246 | 232 | ||
| 247 | switch (action.kind.id) { | 233 | switch (action.kind.id) { |
| 248 | /* Key and Mods */ | 234 | /* Key and Mods */ |
| @@ -383,57 +369,57 @@ static void process_action(keyrecord_t *record) | |||
| 383 | break; | 369 | break; |
| 384 | 370 | ||
| 385 | /* Layer key */ | 371 | /* Layer key */ |
| 386 | case ACT_LAYER: | 372 | case ACT_LAYER_SET: |
| 387 | switch (action.layer.code) { | 373 | switch (action.layer.code) { |
| 388 | case LAYER_MOMENTARY: /* momentary */ | 374 | case LAYER_MOMENTARY: /* momentary */ |
| 389 | if (event.pressed) { | 375 | if (event.pressed) { |
| 390 | layer_switch(action.layer.val); | 376 | layer_switch_move(action.layer.val); |
| 391 | } | 377 | } |
| 392 | else { | 378 | else { |
| 393 | // NOTE: This is needed by legacy keymap support | 379 | // NOTE: This is needed by legacy keymap support |
| 394 | layer_switch(0); | 380 | layer_switch_move(0); |
| 395 | } | 381 | } |
| 396 | break; | 382 | break; |
| 397 | case LAYER_ON_PRESS: | 383 | case LAYER_ON_PRESS: |
| 398 | if (event.pressed) { | 384 | if (event.pressed) { |
| 399 | layer_switch(action.layer.val); | 385 | layer_switch_move(action.layer.val); |
| 400 | } | 386 | } |
| 401 | break; | 387 | break; |
| 402 | case LAYER_ON_RELEASE: | 388 | case LAYER_ON_RELEASE: |
| 403 | if (!event.pressed) { | 389 | if (!event.pressed) { |
| 404 | layer_switch(action.layer.val); | 390 | layer_switch_move(action.layer.val); |
| 405 | } | 391 | } |
| 406 | break; | 392 | break; |
| 407 | case LAYER_ON_BOTH: | 393 | case LAYER_ON_BOTH: |
| 408 | layer_switch(action.layer.val); | 394 | layer_switch_move(action.layer.val); |
| 409 | break; | 395 | break; |
| 410 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 396 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 411 | if (event.pressed) { | 397 | if (event.pressed) { |
| 412 | if (tap_count < TAPPING_TOGGLE) { | 398 | if (tap_count < TAPPING_TOGGLE) { |
| 413 | layer_switch(action.layer.val); | 399 | layer_switch_move(action.layer.val); |
| 414 | } | 400 | } |
| 415 | } else { | 401 | } else { |
| 416 | if (tap_count >= TAPPING_TOGGLE) { | 402 | if (tap_count >= TAPPING_TOGGLE) { |
| 417 | debug("LAYER_PRESSED: tap toggle.\n"); | 403 | debug("LAYER_PRESSED: tap toggle.\n"); |
| 418 | layer_switch(action.layer.val); | 404 | layer_switch_move(action.layer.val); |
| 419 | } | 405 | } |
| 420 | } | 406 | } |
| 421 | break; | 407 | break; |
| 422 | case LAYER_SET_DEFAULT_ON_PRESS: | 408 | case LAYER_SET_DEFAULT_ON_PRESS: |
| 423 | if (event.pressed) { | 409 | if (event.pressed) { |
| 424 | default_layer = action.layer.val; | 410 | default_layer = action.layer.val; |
| 425 | layer_switch(0); | 411 | layer_switch_move(0); |
| 426 | } | 412 | } |
| 427 | break; | 413 | break; |
| 428 | case LAYER_SET_DEFAULT_ON_RELEASE: | 414 | case LAYER_SET_DEFAULT_ON_RELEASE: |
| 429 | if (!event.pressed) { | 415 | if (!event.pressed) { |
| 430 | default_layer = action.layer.val; | 416 | default_layer = action.layer.val; |
| 431 | layer_switch(0); | 417 | layer_switch_move(0); |
| 432 | } | 418 | } |
| 433 | break; | 419 | break; |
| 434 | case LAYER_SET_DEFAULT_ON_BOTH: | 420 | case LAYER_SET_DEFAULT_ON_BOTH: |
| 435 | default_layer = action.layer.val; | 421 | default_layer = action.layer.val; |
| 436 | layer_switch(0); | 422 | layer_switch_move(0); |
| 437 | break; | 423 | break; |
| 438 | default: | 424 | default: |
| 439 | /* tap key */ | 425 | /* tap key */ |
| @@ -443,7 +429,7 @@ static void process_action(keyrecord_t *record) | |||
| 443 | register_code(action.layer.code); | 429 | register_code(action.layer.code); |
| 444 | } else { | 430 | } else { |
| 445 | debug("LAYER_SET: No tap: layer_set(on press)\n"); | 431 | debug("LAYER_SET: No tap: layer_set(on press)\n"); |
| 446 | layer_switch(action.layer.val); | 432 | layer_switch_move(action.layer.val); |
| 447 | } | 433 | } |
| 448 | } else { | 434 | } else { |
| 449 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 435 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| @@ -452,7 +438,7 @@ static void process_action(keyrecord_t *record) | |||
| 452 | } else { | 438 | } else { |
| 453 | // NOTE: This is needed by legacy keymap support | 439 | // NOTE: This is needed by legacy keymap support |
| 454 | debug("LAYER_SET: No tap: return to default layer(on release)\n"); | 440 | debug("LAYER_SET: No tap: return to default layer(on release)\n"); |
| 455 | layer_switch(0); | 441 | layer_switch_move(0); |
| 456 | } | 442 | } |
| 457 | } | 443 | } |
| 458 | break; | 444 | break; |
| @@ -462,52 +448,52 @@ static void process_action(keyrecord_t *record) | |||
| 462 | switch (action.layer.code) { | 448 | switch (action.layer.code) { |
| 463 | case LAYER_MOMENTARY: /* momentary */ | 449 | case LAYER_MOMENTARY: /* momentary */ |
| 464 | if (event.pressed) { | 450 | if (event.pressed) { |
| 465 | layer_switch(current_layer | action.layer.val); | 451 | layer_switch_move(layer_switch_get_layer() | action.layer.val); |
| 466 | } else { | 452 | } else { |
| 467 | layer_switch(current_layer & ~action.layer.val); | 453 | layer_switch_move(layer_switch_get_layer() & ~action.layer.val); |
| 468 | } | 454 | } |
| 469 | break; | 455 | break; |
| 470 | case LAYER_ON_PRESS: | 456 | case LAYER_ON_PRESS: |
| 471 | if (event.pressed) { | 457 | if (event.pressed) { |
| 472 | layer_switch(current_layer ^ action.layer.val); | 458 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 473 | } | 459 | } |
| 474 | break; | 460 | break; |
| 475 | case LAYER_ON_RELEASE: | 461 | case LAYER_ON_RELEASE: |
| 476 | if (!event.pressed) { | 462 | if (!event.pressed) { |
| 477 | layer_switch(current_layer ^ action.layer.val); | 463 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 478 | } | 464 | } |
| 479 | break; | 465 | break; |
| 480 | case LAYER_ON_BOTH: | 466 | case LAYER_ON_BOTH: |
| 481 | layer_switch(current_layer ^ action.layer.val); | 467 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 482 | break; | 468 | break; |
| 483 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 469 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 484 | if (event.pressed) { | 470 | if (event.pressed) { |
| 485 | if (tap_count < TAPPING_TOGGLE) { | 471 | if (tap_count < TAPPING_TOGGLE) { |
| 486 | debug("LAYER_BIT: tap toggle(press).\n"); | 472 | debug("LAYER_BIT: tap toggle(press).\n"); |
| 487 | layer_switch(current_layer ^ action.layer.val); | 473 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 488 | } | 474 | } |
| 489 | } else { | 475 | } else { |
| 490 | if (tap_count <= TAPPING_TOGGLE) { | 476 | if (tap_count <= TAPPING_TOGGLE) { |
| 491 | debug("LAYER_BIT: tap toggle(release).\n"); | 477 | debug("LAYER_BIT: tap toggle(release).\n"); |
| 492 | layer_switch(current_layer ^ action.layer.val); | 478 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 493 | } | 479 | } |
| 494 | } | 480 | } |
| 495 | break; | 481 | break; |
| 496 | case LAYER_SET_DEFAULT_ON_PRESS: | 482 | case LAYER_SET_DEFAULT_ON_PRESS: |
| 497 | if (event.pressed) { | 483 | if (event.pressed) { |
| 498 | default_layer = default_layer ^ action.layer.val; | 484 | default_layer = default_layer ^ action.layer.val; |
| 499 | layer_switch(0); | 485 | layer_switch_move(default_layer); |
| 500 | } | 486 | } |
| 501 | break; | 487 | break; |
| 502 | case LAYER_SET_DEFAULT_ON_RELEASE: | 488 | case LAYER_SET_DEFAULT_ON_RELEASE: |
| 503 | if (!event.pressed) { | 489 | if (!event.pressed) { |
| 504 | default_layer = default_layer ^ action.layer.val; | 490 | default_layer = default_layer ^ action.layer.val; |
| 505 | layer_switch(0); | 491 | layer_switch_move(default_layer); |
| 506 | } | 492 | } |
| 507 | break; | 493 | break; |
| 508 | case LAYER_SET_DEFAULT_ON_BOTH: | 494 | case LAYER_SET_DEFAULT_ON_BOTH: |
| 509 | default_layer = default_layer ^ action.layer.val; | 495 | default_layer = default_layer ^ action.layer.val; |
| 510 | layer_switch(0); | 496 | layer_switch_move(default_layer); |
| 511 | break; | 497 | break; |
| 512 | default: | 498 | default: |
| 513 | // tap key | 499 | // tap key |
| @@ -517,7 +503,7 @@ static void process_action(keyrecord_t *record) | |||
| 517 | register_code(action.layer.code); | 503 | register_code(action.layer.code); |
| 518 | } else { | 504 | } else { |
| 519 | debug("LAYER_BIT: No tap: layer_bit(on press)\n"); | 505 | debug("LAYER_BIT: No tap: layer_bit(on press)\n"); |
| 520 | layer_switch(current_layer ^ action.layer.val); | 506 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 521 | } | 507 | } |
| 522 | } else { | 508 | } else { |
| 523 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 509 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| @@ -525,7 +511,7 @@ static void process_action(keyrecord_t *record) | |||
| 525 | unregister_code(action.layer.code); | 511 | unregister_code(action.layer.code); |
| 526 | } else { | 512 | } else { |
| 527 | debug("LAYER_BIT: No tap: layer_bit(on release)\n"); | 513 | debug("LAYER_BIT: No tap: layer_bit(on release)\n"); |
| 528 | layer_switch(current_layer ^ action.layer.val); | 514 | layer_switch_move(layer_switch_get_layer() ^ action.layer.val); |
| 529 | } | 515 | } |
| 530 | } | 516 | } |
| 531 | break; | 517 | break; |
| @@ -542,27 +528,27 @@ static void process_action(keyrecord_t *record) | |||
| 542 | break; | 528 | break; |
| 543 | case LAYER_ON_PRESS: | 529 | case LAYER_ON_PRESS: |
| 544 | if (event.pressed) { | 530 | if (event.pressed) { |
| 545 | layer_switch_inv(action.layer.val); | 531 | layer_switch_invert(action.layer.val); |
| 546 | } | 532 | } |
| 547 | break; | 533 | break; |
| 548 | case LAYER_ON_RELEASE: | 534 | case LAYER_ON_RELEASE: |
| 549 | if (!event.pressed) { | 535 | if (!event.pressed) { |
| 550 | layer_switch_inv(action.layer.val); | 536 | layer_switch_invert(action.layer.val); |
| 551 | } | 537 | } |
| 552 | break; | 538 | break; |
| 553 | case LAYER_ON_BOTH: | 539 | case LAYER_ON_BOTH: |
| 554 | layer_switch_inv(action.layer.val); | 540 | layer_switch_invert(action.layer.val); |
| 555 | break; | 541 | break; |
| 556 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 542 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ |
| 557 | if (event.pressed) { | 543 | if (event.pressed) { |
| 558 | if (tap_count < TAPPING_TOGGLE) { | 544 | if (tap_count < TAPPING_TOGGLE) { |
| 559 | debug("LAYER_SWITCH: tap toggle(press).\n"); | 545 | debug("LAYER_SWITCH: tap toggle(press).\n"); |
| 560 | layer_switch_inv(action.layer.val); | 546 | layer_switch_invert(action.layer.val); |
| 561 | } | 547 | } |
| 562 | } else { | 548 | } else { |
| 563 | if (tap_count <= TAPPING_TOGGLE) { | 549 | if (tap_count <= TAPPING_TOGGLE) { |
| 564 | debug("LAYER_SWITCH: tap toggle(release).\n"); | 550 | debug("LAYER_SWITCH: tap toggle(release).\n"); |
| 565 | layer_switch_inv(action.layer.val); | 551 | layer_switch_invert(action.layer.val); |
| 566 | } | 552 | } |
| 567 | } | 553 | } |
| 568 | break; | 554 | break; |
| @@ -573,16 +559,16 @@ static void process_action(keyrecord_t *record) | |||
| 573 | debug("LAYER_SWITCH: Tap: register_code\n"); | 559 | debug("LAYER_SWITCH: Tap: register_code\n"); |
| 574 | register_code(action.layer.code); | 560 | register_code(action.layer.code); |
| 575 | } else { | 561 | } else { |
| 576 | debug("LAYER_SWITCH: No tap: layer_switch(on press)\n"); | 562 | debug("LAYER_SWITCH: No tap: layer_switch on press\n"); |
| 577 | layer_switch_inv(action.layer.val); | 563 | layer_switch_invert(action.layer.val); |
| 578 | } | 564 | } |
| 579 | } else { | 565 | } else { |
| 580 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 566 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { |
| 581 | debug("LAYER_SWITCH: Tap: unregister_code\n"); | 567 | debug("LAYER_SWITCH: Tap: unregister_code\n"); |
| 582 | unregister_code(action.layer.code); | 568 | unregister_code(action.layer.code); |
| 583 | } else { | 569 | } else { |
| 584 | debug("LAYER_SWITCH: No tap: layer_switch(on release)\n"); | 570 | debug("LAYER_SWITCH: No tap: layer_switch on release\n"); |
| 585 | layer_switch_inv(action.layer.val); | 571 | layer_switch_invert(action.layer.val); |
| 586 | } | 572 | } |
| 587 | } | 573 | } |
| 588 | break; | 574 | break; |
| @@ -889,19 +875,6 @@ bool sending_anykey(void) | |||
| 889 | host_last_sysytem_report() || host_last_consumer_report()); | 875 | host_last_sysytem_report() || host_last_consumer_report()); |
| 890 | } | 876 | } |
| 891 | 877 | ||
| 892 | // TODO: rename or reinpl with new layer_switch.c | ||
| 893 | void layer_switch(uint8_t new_layer) | ||
| 894 | { | ||
| 895 | if (current_layer != new_layer) { | ||
| 896 | debug("Layer Switch: "); debug_hex(current_layer); | ||
| 897 | debug(" -> "); debug_hex(new_layer); debug("\n"); | ||
| 898 | |||
| 899 | current_layer = new_layer; | ||
| 900 | clear_keyboard_but_mods(); // To avoid stuck keys | ||
| 901 | // NOTE: update mods with full scan of matrix? if modifier changes between layers | ||
| 902 | } | ||
| 903 | } | ||
| 904 | |||
| 905 | bool is_tap_key(key_t key) | 878 | bool is_tap_key(key_t key) |
| 906 | { | 879 | { |
| 907 | action_t action = get_action(key); | 880 | action_t action = get_action(key); |
| @@ -910,7 +883,7 @@ bool is_tap_key(key_t key) | |||
| 910 | case ACT_LMODS_TAP: | 883 | case ACT_LMODS_TAP: |
| 911 | case ACT_RMODS_TAP: | 884 | case ACT_RMODS_TAP: |
| 912 | return true; | 885 | return true; |
| 913 | case ACT_LAYER: | 886 | case ACT_LAYER_SET: |
| 914 | case ACT_LAYER_BIT: | 887 | case ACT_LAYER_BIT: |
| 915 | switch (action.layer.code) { | 888 | switch (action.layer.code) { |
| 916 | case LAYER_MOMENTARY: | 889 | case LAYER_MOMENTARY: |
| @@ -956,9 +929,9 @@ static void debug_action(action_t action) | |||
| 956 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; | 929 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; |
| 957 | case ACT_USAGE: debug("ACT_USAGE"); break; | 930 | case ACT_USAGE: debug("ACT_USAGE"); break; |
| 958 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; | 931 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
| 959 | case ACT_LAYER: debug("ACT_LAYER"); break; | 932 | case ACT_LAYER_SET: debug("ACT_LAYER_SET"); break; |
| 960 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; | 933 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; |
| 961 | case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; | 934 | case ACT_LAYER_SWITCH: debug("ACT_LAYER_SWITCH"); break; |
| 962 | case ACT_MACRO: debug("ACT_MACRO"); break; | 935 | case ACT_MACRO: debug("ACT_MACRO"); break; |
| 963 | case ACT_COMMAND: debug("ACT_COMMAND"); break; | 936 | case ACT_COMMAND: debug("ACT_COMMAND"); break; |
| 964 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; | 937 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
