diff options
| author | tmk <nobody@nowhere> | 2013-03-05 15:45:15 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-05 15:45:15 +0900 |
| commit | 38bbe976e00a9a7bf6f8157016717e80503bf6a9 (patch) | |
| tree | 9113cd57c1bff3deef394ee966e2fdac8731a244 /common/action.c | |
| parent | 1720cf34caa518a2cf85f286d1ca077ebe1a1451 (diff) | |
| parent | 5808317b694004c43a6e0f76e9715415cce19a25 (diff) | |
| download | qmk_firmware-38bbe976e00a9a7bf6f8157016717e80503bf6a9.tar.gz qmk_firmware-38bbe976e00a9a7bf6f8157016717e80503bf6a9.zip | |
Merge branch 'overlays'
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 443 |
1 files changed, 294 insertions, 149 deletions
diff --git a/common/action.c b/common/action.c index 6528cd46c..15e125a3e 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -23,15 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | #include "command.h" | 23 | #include "command.h" |
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "debug.h" | 25 | #include "debug.h" |
| 26 | #include "layer_switch.h" | ||
| 27 | #include "action_macro.h" | ||
| 26 | #include "action.h" | 28 | #include "action.h" |
| 27 | 29 | ||
| 28 | 30 | ||
| 29 | /* default layer indicates base layer */ | ||
| 30 | uint8_t default_layer = 0; | ||
| 31 | /* current layer indicates active layer at this time */ | ||
| 32 | uint8_t current_layer = 0; | ||
| 33 | |||
| 34 | |||
| 35 | static void process_action(keyrecord_t *record); | 31 | static void process_action(keyrecord_t *record); |
| 36 | static bool process_tapping(keyrecord_t *record); | 32 | static bool process_tapping(keyrecord_t *record); |
| 37 | static void waiting_buffer_scan_tap(void); | 33 | static void waiting_buffer_scan_tap(void); |
| @@ -207,28 +203,18 @@ void action_exec(keyevent_t event) | |||
| 207 | } | 203 | } |
| 208 | } | 204 | } |
| 209 | 205 | ||
| 210 | static action_t get_action(key_t key) | ||
| 211 | { | ||
| 212 | action_t action = action_for_key(current_layer, key); | ||
| 213 | |||
| 214 | /* Transparently use default layer */ | ||
| 215 | 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"); | ||
| 219 | } | ||
| 220 | return action; | ||
| 221 | } | ||
| 222 | |||
| 223 | static void process_action(keyrecord_t *record) | 206 | static void process_action(keyrecord_t *record) |
| 224 | { | 207 | { |
| 225 | keyevent_t event = record->event; | 208 | keyevent_t event = record->event; |
| 226 | uint8_t tap_count = record->tap_count; | 209 | uint8_t tap_count = record->tap.count; |
| 227 | 210 | ||
| 228 | if (IS_NOEVENT(event)) { return; } | 211 | if (IS_NOEVENT(event)) { return; } |
| 229 | 212 | ||
| 230 | action_t action = get_action(event.key); | 213 | action_t action = layer_switch_get_action(event.key); |
| 231 | debug("ACTION: "); debug_action(action); debug("\n"); | 214 | debug("ACTION: "); debug_action(action); |
| 215 | debug(" overlays: "); overlay_debug(); | ||
| 216 | debug(" keymaps: "); keymap_debug(); | ||
| 217 | debug(" default_layer: "); debug_dec(default_layer); debug("\n"); | ||
| 232 | 218 | ||
| 233 | switch (action.kind.id) { | 219 | switch (action.kind.id) { |
| 234 | /* Key and Mods */ | 220 | /* Key and Mods */ |
| @@ -287,7 +273,7 @@ static void process_action(keyrecord_t *record) | |||
| 287 | } else { | 273 | } else { |
| 288 | if (tap_count == 0) { | 274 | if (tap_count == 0) { |
| 289 | debug("MODS_TAP: Oneshot: cancel/del_mods\n"); | 275 | debug("MODS_TAP: Oneshot: cancel/del_mods\n"); |
| 290 | // cancel oneshot by holding. | 276 | // cancel oneshot on hold |
| 291 | oneshot_cancel(); | 277 | oneshot_cancel(); |
| 292 | del_mods(mods); | 278 | del_mods(mods); |
| 293 | } | 279 | } |
| @@ -309,7 +295,7 @@ static void process_action(keyrecord_t *record) | |||
| 309 | if (waiting_buffer_has_anykey_pressed()) { | 295 | if (waiting_buffer_has_anykey_pressed()) { |
| 310 | debug("MODS_TAP: Tap: Cancel: add_mods\n"); | 296 | debug("MODS_TAP: Tap: Cancel: add_mods\n"); |
| 311 | // ad hoc: set 0 to cancel tap | 297 | // ad hoc: set 0 to cancel tap |
| 312 | record->tap_count = 0; | 298 | record->tap.count = 0; |
| 313 | add_mods(mods); | 299 | add_mods(mods); |
| 314 | } else { | 300 | } else { |
| 315 | debug("MODS_TAP: Tap: register_code\n"); | 301 | debug("MODS_TAP: Tap: register_code\n"); |
| @@ -368,145 +354,316 @@ static void process_action(keyrecord_t *record) | |||
| 368 | #endif | 354 | #endif |
| 369 | break; | 355 | break; |
| 370 | 356 | ||
| 371 | /* Layer key */ | 357 | case ACT_KEYMAP: |
| 372 | case ACT_LAYER: | ||
| 373 | switch (action.layer.code) { | 358 | switch (action.layer.code) { |
| 374 | case LAYER_MOMENTARY: /* momentary */ | 359 | /* Keymap clear */ |
| 375 | if (event.pressed) { | 360 | case OP_RESET: |
| 376 | layer_switch(action.layer.val); | 361 | switch (action.layer.val & 0x03) { |
| 377 | } | 362 | case 0: |
| 378 | else { | 363 | // NOTE: reserved |
| 379 | // NOTE: This is needed by legacy keymap support | 364 | overlay_clear(); |
| 380 | layer_switch(default_layer); | 365 | keymap_clear(); |
| 381 | } | ||
| 382 | break; | ||
| 383 | case LAYER_ON_PRESS: | ||
| 384 | if (event.pressed) { | ||
| 385 | layer_switch(action.layer.val); | ||
| 386 | } | ||
| 387 | break; | ||
| 388 | case LAYER_ON_RELEASE: | ||
| 389 | if (!event.pressed) { | ||
| 390 | layer_switch(action.layer.val); | ||
| 391 | } | ||
| 392 | break; | ||
| 393 | case LAYER_DEFAULT: /* default layer */ | ||
| 394 | switch (action.layer.val) { | ||
| 395 | case DEFAULT_ON_BOTH: | ||
| 396 | layer_switch(default_layer); | ||
| 397 | break; | 366 | break; |
| 398 | case DEFAULT_ON_PRESS: | 367 | case ON_PRESS: |
| 399 | if (event.pressed) { | 368 | if (event.pressed) { |
| 400 | layer_switch(default_layer); | 369 | overlay_clear(); |
| 370 | keymap_clear(); | ||
| 401 | } | 371 | } |
| 402 | break; | 372 | break; |
| 403 | case DEFAULT_ON_RELEASE: | 373 | case ON_RELEASE: |
| 404 | if (!event.pressed) { | 374 | if (!event.pressed) { |
| 405 | layer_switch(default_layer); | 375 | overlay_clear(); |
| 376 | keymap_clear(); | ||
| 406 | } | 377 | } |
| 407 | break; | 378 | break; |
| 379 | case ON_BOTH: | ||
| 380 | overlay_clear(); | ||
| 381 | keymap_clear(); | ||
| 382 | break; | ||
| 383 | /* NOTE: 4-7 rserved */ | ||
| 408 | } | 384 | } |
| 409 | break; | 385 | break; |
| 410 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 386 | /* Keymap Reset default layer */ |
| 387 | case (OP_RESET | ON_PRESS): | ||
| 388 | if (event.pressed) { | ||
| 389 | default_layer_set(action.layer.val); | ||
| 390 | } | ||
| 391 | break; | ||
| 392 | case (OP_RESET | ON_RELEASE): | ||
| 393 | if (!event.pressed) { | ||
| 394 | default_layer_set(action.layer.val); | ||
| 395 | } | ||
| 396 | break; | ||
| 397 | case (OP_RESET | ON_BOTH): | ||
| 398 | default_layer_set(action.layer.val); | ||
| 399 | break; | ||
| 400 | |||
| 401 | /* Keymap Bit invert */ | ||
| 402 | case OP_INV: | ||
| 403 | /* with tap toggle */ | ||
| 411 | if (event.pressed) { | 404 | if (event.pressed) { |
| 412 | if (tap_count < TAPPING_TOGGLE) { | 405 | if (tap_count < TAPPING_TOGGLE) { |
| 413 | layer_switch(action.layer.val); | 406 | debug("KEYMAP_INV: tap toggle(press).\n"); |
| 407 | keymap_invert(action.layer.val); | ||
| 414 | } | 408 | } |
| 415 | } else { | 409 | } else { |
| 416 | if (tap_count >= TAPPING_TOGGLE) { | 410 | if (tap_count <= TAPPING_TOGGLE) { |
| 417 | debug("LAYER_PRESSED: tap toggle.\n"); | 411 | debug("KEYMAP_INV: tap toggle(release).\n"); |
| 418 | layer_switch(action.layer.val); | 412 | keymap_invert(action.layer.val); |
| 419 | } | 413 | } |
| 420 | } | 414 | } |
| 421 | break; | 415 | break; |
| 422 | case LAYER_CHANGE_DEFAULT: /* change default layer */ | 416 | case (OP_INV | ON_PRESS): |
| 423 | if (event.pressed) { | 417 | if (event.pressed) { |
| 424 | default_layer = action.layer.val; | 418 | keymap_invert(action.layer.val); |
| 425 | layer_switch(default_layer); | 419 | } |
| 420 | break; | ||
| 421 | case (OP_INV | ON_RELEASE): | ||
| 422 | if (!event.pressed) { | ||
| 423 | keymap_invert(action.layer.val); | ||
| 426 | } | 424 | } |
| 427 | break; | 425 | break; |
| 428 | default: /* switch layer on hold and key on tap*/ | 426 | case (OP_INV | ON_BOTH): |
| 427 | keymap_invert(action.layer.val); | ||
| 428 | break; | ||
| 429 | |||
| 430 | /* Keymap Bit on */ | ||
| 431 | case OP_ON: | ||
| 432 | if (event.pressed) { | ||
| 433 | keymap_on(action.layer.val); | ||
| 434 | } else { | ||
| 435 | keymap_off(action.layer.val); | ||
| 436 | } | ||
| 437 | break; | ||
| 438 | case (OP_ON | ON_PRESS): | ||
| 439 | if (event.pressed) { | ||
| 440 | keymap_on(action.layer.val); | ||
| 441 | } | ||
| 442 | break; | ||
| 443 | case (OP_ON | ON_RELEASE): | ||
| 444 | if (!event.pressed) { | ||
| 445 | keymap_on(action.layer.val); | ||
| 446 | } | ||
| 447 | break; | ||
| 448 | case (OP_ON | ON_BOTH): | ||
| 449 | keymap_on(action.layer.val); | ||
| 450 | break; | ||
| 451 | |||
| 452 | /* Keymap Bit off */ | ||
| 453 | case OP_OFF: | ||
| 454 | if (event.pressed) { | ||
| 455 | keymap_off(action.layer.val); | ||
| 456 | } else { | ||
| 457 | keymap_on(action.layer.val); | ||
| 458 | } | ||
| 459 | break; | ||
| 460 | case (OP_OFF | ON_PRESS): | ||
| 461 | if (event.pressed) { | ||
| 462 | keymap_off(action.layer.val); | ||
| 463 | } | ||
| 464 | break; | ||
| 465 | case (OP_OFF | ON_RELEASE): | ||
| 466 | if (!event.pressed) { | ||
| 467 | keymap_off(action.layer.val); | ||
| 468 | } | ||
| 469 | break; | ||
| 470 | case (OP_OFF | ON_BOTH): | ||
| 471 | keymap_off(action.layer.val); | ||
| 472 | break; | ||
| 473 | |||
| 474 | /* Keymap Bit set */ | ||
| 475 | case OP_SET: | ||
| 476 | if (event.pressed) { | ||
| 477 | keymap_set(action.layer.val); | ||
| 478 | } else { | ||
| 479 | keymap_clear(); | ||
| 480 | } | ||
| 481 | break; | ||
| 482 | case (OP_SET | ON_PRESS): | ||
| 483 | if (event.pressed) { | ||
| 484 | keymap_set(action.layer.val); | ||
| 485 | } | ||
| 486 | break; | ||
| 487 | case (OP_SET | ON_RELEASE): | ||
| 488 | if (!event.pressed) { | ||
| 489 | keymap_set(action.layer.val); | ||
| 490 | } | ||
| 491 | break; | ||
| 492 | case (OP_SET | ON_BOTH): | ||
| 493 | keymap_set(action.layer.val); | ||
| 494 | break; | ||
| 495 | |||
| 496 | /* Keymap Bit invert with tap key */ | ||
| 497 | default: | ||
| 429 | if (event.pressed) { | 498 | if (event.pressed) { |
| 430 | if (tap_count > 0) { | 499 | if (tap_count > 0) { |
| 431 | debug("LAYER_PRESSED: Tap: register_code\n"); | 500 | debug("KEYMAP_TAP_KEY: Tap: register_code\n"); |
| 432 | register_code(action.layer.code); | 501 | register_code(action.layer.code); |
| 433 | } else { | 502 | } else { |
| 434 | debug("LAYER_PRESSED: No tap: layer_switch\n"); | 503 | debug("KEYMAP_TAP_KEY: No tap: On on press\n"); |
| 435 | layer_switch(action.layer.val); | 504 | keymap_on(action.layer.val); |
| 436 | } | 505 | } |
| 437 | } else { | 506 | } else { |
| 438 | if (tap_count > 0) { | 507 | if (tap_count > 0) { |
| 439 | debug("LAYER_PRESSED: Tap: unregister_code\n"); | 508 | debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); |
| 440 | unregister_code(action.layer.code); | 509 | unregister_code(action.layer.code); |
| 441 | } else { | 510 | } else { |
| 442 | //debug("LAYER_PRESSED: No tap: NO ACTION\n"); | 511 | debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); |
| 443 | // NOTE: This is needed by legacy keymap support | 512 | keymap_off(action.layer.val); |
| 444 | debug("LAYER_PRESSED: No tap: return to default layer\n"); | ||
| 445 | layer_switch(default_layer); | ||
| 446 | } | 513 | } |
| 447 | } | 514 | } |
| 448 | break; | 515 | break; |
| 449 | } | 516 | } |
| 450 | break; | 517 | break; |
| 451 | case ACT_LAYER_BIT: | 518 | |
| 519 | case ACT_OVERLAY: | ||
| 452 | switch (action.layer.code) { | 520 | switch (action.layer.code) { |
| 453 | case LAYER_MOMENTARY: /* momentary */ | 521 | // Overlay Invert bit4 |
| 454 | if (event.pressed) { | 522 | case OP_INV4 | 0: |
| 455 | layer_switch(current_layer ^ action.layer.val); | 523 | if (action.layer.val == 0) { |
| 524 | // NOTE: reserved for future use | ||
| 525 | overlay_clear(); | ||
| 456 | } else { | 526 | } else { |
| 457 | layer_switch(current_layer ^ action.layer.val); | 527 | overlay_set(overlay_stat ^ action.layer.val); |
| 458 | } | 528 | } |
| 459 | break; | 529 | break; |
| 460 | case LAYER_ON_PRESS: | 530 | case OP_INV4 | 1: |
| 461 | if (event.pressed) { | 531 | if (action.layer.val == 0) { |
| 462 | layer_switch(current_layer ^ action.layer.val); | 532 | // on pressed |
| 533 | if (event.pressed) overlay_clear(); | ||
| 534 | } else { | ||
| 535 | overlay_set(overlay_stat ^ action.layer.val<<4); | ||
| 463 | } | 536 | } |
| 464 | break; | 537 | break; |
| 465 | case LAYER_ON_RELEASE: | 538 | case OP_INV4 | 2: |
| 466 | if (!event.pressed) { | 539 | if (action.layer.val == 0) { |
| 467 | layer_switch(current_layer ^ action.layer.val); | 540 | // on released |
| 541 | if (!event.pressed) overlay_clear(); | ||
| 542 | } else { | ||
| 543 | overlay_set(overlay_stat ^ action.layer.val<<8); | ||
| 544 | } | ||
| 545 | break; | ||
| 546 | case OP_INV4 | 3: | ||
| 547 | if (action.layer.val == 0) { | ||
| 548 | // on both | ||
| 549 | overlay_clear(); | ||
| 550 | } else { | ||
| 551 | overlay_set(overlay_stat ^ action.layer.val<<12); | ||
| 468 | } | 552 | } |
| 469 | break; | 553 | break; |
| 470 | case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */ | 554 | |
| 555 | /* Overlay Bit invert */ | ||
| 556 | case OP_INV: | ||
| 557 | /* with tap toggle */ | ||
| 471 | if (event.pressed) { | 558 | if (event.pressed) { |
| 472 | if (tap_count < TAPPING_TOGGLE) { | 559 | if (tap_count < TAPPING_TOGGLE) { |
| 473 | debug("LAYER_BIT: tap toggle(press).\n"); | 560 | debug("OVERLAY_INV: tap toggle(press).\n"); |
| 474 | layer_switch(current_layer ^ action.layer.val); | 561 | overlay_invert(action.layer.val); |
| 475 | } | 562 | } |
| 476 | } else { | 563 | } else { |
| 477 | if (tap_count <= TAPPING_TOGGLE) { | 564 | if (tap_count <= TAPPING_TOGGLE) { |
| 478 | debug("LAYER_BIT: tap toggle(release).\n"); | 565 | debug("OVERLAY_INV: tap toggle(release).\n"); |
| 479 | layer_switch(current_layer ^ action.layer.val); | 566 | overlay_invert(action.layer.val); |
| 480 | } | 567 | } |
| 481 | } | 568 | } |
| 482 | break; | 569 | break; |
| 483 | case 0xFF: | 570 | case (OP_INV | ON_PRESS): |
| 484 | // change default layer | 571 | if (event.pressed) { |
| 572 | overlay_invert(action.layer.val); | ||
| 573 | } | ||
| 574 | break; | ||
| 575 | case (OP_INV | ON_RELEASE): | ||
| 576 | if (!event.pressed) { | ||
| 577 | overlay_invert(action.layer.val); | ||
| 578 | } | ||
| 579 | break; | ||
| 580 | case (OP_INV | ON_BOTH): | ||
| 581 | overlay_invert(action.layer.val); | ||
| 582 | break; | ||
| 583 | |||
| 584 | /* Overlay Bit on */ | ||
| 585 | case OP_ON: | ||
| 485 | if (event.pressed) { | 586 | if (event.pressed) { |
| 486 | default_layer = current_layer ^ action.layer.val; | 587 | overlay_on(action.layer.val); |
| 487 | layer_switch(default_layer); | ||
| 488 | } else { | 588 | } else { |
| 489 | default_layer = current_layer ^ action.layer.val; | 589 | overlay_off(action.layer.val); |
| 490 | layer_switch(default_layer); | 590 | } |
| 591 | break; | ||
| 592 | case (OP_ON | ON_PRESS): | ||
| 593 | if (event.pressed) { | ||
| 594 | overlay_on(action.layer.val); | ||
| 491 | } | 595 | } |
| 492 | break; | 596 | break; |
| 597 | case (OP_ON | ON_RELEASE): | ||
| 598 | if (!event.pressed) { | ||
| 599 | overlay_on(action.layer.val); | ||
| 600 | } | ||
| 601 | break; | ||
| 602 | case (OP_ON | ON_BOTH): | ||
| 603 | overlay_on(action.layer.val); | ||
| 604 | break; | ||
| 605 | |||
| 606 | /* Overlay Bit off */ | ||
| 607 | case OP_OFF: | ||
| 608 | if (event.pressed) { | ||
| 609 | overlay_off(action.layer.val); | ||
| 610 | } else { | ||
| 611 | overlay_on(action.layer.val); | ||
| 612 | } | ||
| 613 | break; | ||
| 614 | case (OP_OFF | ON_PRESS): | ||
| 615 | if (event.pressed) { | ||
| 616 | overlay_off(action.layer.val); | ||
| 617 | } | ||
| 618 | break; | ||
| 619 | case (OP_OFF | ON_RELEASE): | ||
| 620 | if (!event.pressed) { | ||
| 621 | overlay_off(action.layer.val); | ||
| 622 | } | ||
| 623 | break; | ||
| 624 | case (OP_OFF | ON_BOTH): | ||
| 625 | overlay_off(action.layer.val); | ||
| 626 | break; | ||
| 627 | |||
| 628 | /* Overlay Bit set */ | ||
| 629 | case OP_SET: | ||
| 630 | if (event.pressed) { | ||
| 631 | overlay_move(action.layer.val); | ||
| 632 | } else { | ||
| 633 | overlay_clear(); | ||
| 634 | } | ||
| 635 | break; | ||
| 636 | case (OP_SET | ON_PRESS): | ||
| 637 | if (event.pressed) { | ||
| 638 | overlay_move(action.layer.val); | ||
| 639 | } | ||
| 640 | break; | ||
| 641 | case (OP_SET | ON_RELEASE): | ||
| 642 | if (!event.pressed) { | ||
| 643 | overlay_move(action.layer.val); | ||
| 644 | } | ||
| 645 | break; | ||
| 646 | case (OP_SET | ON_BOTH): | ||
| 647 | overlay_move(action.layer.val); | ||
| 648 | break; | ||
| 649 | |||
| 650 | /* Overlay Bit invert with tap key */ | ||
| 493 | default: | 651 | default: |
| 494 | // with tap key | ||
| 495 | if (event.pressed) { | 652 | if (event.pressed) { |
| 496 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 653 | if (tap_count > 0) { |
| 497 | debug("LAYER_BIT: Tap: register_code\n"); | 654 | debug("OVERLAY_TAP_KEY: Tap: register_code\n"); |
| 498 | register_code(action.layer.code); | 655 | register_code(action.layer.code); |
| 499 | } else { | 656 | } else { |
| 500 | debug("LAYER_BIT: No tap: layer_switch(bit on)\n"); | 657 | debug("OVERLAY_TAP_KEY: No tap: On on press\n"); |
| 501 | layer_switch(current_layer ^ action.layer.val); | 658 | overlay_on(action.layer.val); |
| 502 | } | 659 | } |
| 503 | } else { | 660 | } else { |
| 504 | if (IS_TAPPING_KEY(event.key) && tap_count > 0) { | 661 | if (tap_count > 0) { |
| 505 | debug("LAYER_BIT: Tap: unregister_code\n"); | 662 | debug("OVERLAY_TAP_KEY: Tap: unregister_code\n"); |
| 506 | unregister_code(action.layer.code); | 663 | unregister_code(action.layer.code); |
| 507 | } else { | 664 | } else { |
| 508 | debug("LAYER_BIT: No tap: layer_switch(bit off)\n"); | 665 | debug("OVERLAY_TAP_KEY: No tap: Off on release\n"); |
| 509 | layer_switch(current_layer ^ action.layer.val); | 666 | overlay_off(action.layer.val); |
| 510 | } | 667 | } |
| 511 | } | 668 | } |
| 512 | break; | 669 | break; |
| @@ -515,7 +672,7 @@ static void process_action(keyrecord_t *record) | |||
| 515 | 672 | ||
| 516 | /* Extentions */ | 673 | /* Extentions */ |
| 517 | case ACT_MACRO: | 674 | case ACT_MACRO: |
| 518 | // TODO | 675 | action_macro_play(action_get_macro(record, action.func.id, action.func.opt)); |
| 519 | break; | 676 | break; |
| 520 | case ACT_COMMAND: | 677 | case ACT_COMMAND: |
| 521 | break; | 678 | break; |
| @@ -540,16 +697,17 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 540 | // if tapping | 697 | // if tapping |
| 541 | if (IS_TAPPING_PRESSED()) { | 698 | if (IS_TAPPING_PRESSED()) { |
| 542 | if (WITHIN_TAPPING_TERM(event)) { | 699 | if (WITHIN_TAPPING_TERM(event)) { |
| 543 | if (tapping_key.tap_count == 0) { | 700 | if (tapping_key.tap.count == 0) { |
| 544 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 701 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 545 | // first tap! | 702 | // first tap! |
| 546 | debug("Tapping: First tap(0->1).\n"); | 703 | debug("Tapping: First tap(0->1).\n"); |
| 547 | tapping_key.tap_count = 1; | 704 | tapping_key.tap.count = 1; |
| 705 | tapping_key.tap.interrupted = (waiting_buffer_has_anykey_pressed() ? true : false); | ||
| 548 | debug_tapping_key(); | 706 | debug_tapping_key(); |
| 549 | process_action(&tapping_key); | 707 | process_action(&tapping_key); |
| 550 | 708 | ||
| 551 | // enqueue | 709 | // enqueue |
| 552 | keyp->tap_count = tapping_key.tap_count; | 710 | keyp->tap = tapping_key.tap; |
| 553 | return false; | 711 | return false; |
| 554 | } | 712 | } |
| 555 | #if TAPPING_TERM >= 500 | 713 | #if TAPPING_TERM >= 500 |
| @@ -573,19 +731,19 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 573 | // tap_count > 0 | 731 | // tap_count > 0 |
| 574 | else { | 732 | else { |
| 575 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 733 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 576 | debug("Tapping: Tap release("); debug_dec(tapping_key.tap_count); debug(")\n"); | 734 | debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); |
| 577 | keyp->tap_count = tapping_key.tap_count; | 735 | keyp->tap = tapping_key.tap; |
| 578 | process_action(keyp); | 736 | process_action(keyp); |
| 579 | tapping_key = *keyp; | 737 | tapping_key = *keyp; |
| 580 | debug_tapping_key(); | 738 | debug_tapping_key(); |
| 581 | return true; | 739 | return true; |
| 582 | } | 740 | } |
| 583 | else if (is_tap_key(keyp->event.key) && event.pressed) { | 741 | else if (is_tap_key(keyp->event.key) && event.pressed) { |
| 584 | if (tapping_key.tap_count > 1) { | 742 | if (tapping_key.tap.count > 1) { |
| 585 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); | 743 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); |
| 586 | // unregister key | 744 | // unregister key |
| 587 | process_action(&(keyrecord_t){ | 745 | process_action(&(keyrecord_t){ |
| 588 | .tap_count = tapping_key.tap_count, | 746 | .tap = tapping_key.tap, |
| 589 | .event.key = tapping_key.event.key, | 747 | .event.key = tapping_key.event.key, |
| 590 | .event.time = event.time, | 748 | .event.time = event.time, |
| 591 | .event.pressed = false | 749 | .event.pressed = false |
| @@ -609,7 +767,7 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 609 | } | 767 | } |
| 610 | // after TAPPING_TERM | 768 | // after TAPPING_TERM |
| 611 | else { | 769 | else { |
| 612 | if (tapping_key.tap_count == 0) { | 770 | if (tapping_key.tap.count == 0) { |
| 613 | debug("Tapping: End. Timeout. Not tap(0): "); | 771 | debug("Tapping: End. Timeout. Not tap(0): "); |
| 614 | debug_event(event); debug("\n"); | 772 | debug_event(event); debug("\n"); |
| 615 | process_action(&tapping_key); | 773 | process_action(&tapping_key); |
| @@ -619,17 +777,17 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 619 | } else { | 777 | } else { |
| 620 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 778 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { |
| 621 | debug("Tapping: End. last timeout tap release(>0)."); | 779 | debug("Tapping: End. last timeout tap release(>0)."); |
| 622 | keyp->tap_count = tapping_key.tap_count; | 780 | keyp->tap = tapping_key.tap; |
| 623 | process_action(keyp); | 781 | process_action(keyp); |
| 624 | tapping_key = (keyrecord_t){}; | 782 | tapping_key = (keyrecord_t){}; |
| 625 | return true; | 783 | return true; |
| 626 | } | 784 | } |
| 627 | else if (is_tap_key(keyp->event.key) && event.pressed) { | 785 | else if (is_tap_key(keyp->event.key) && event.pressed) { |
| 628 | if (tapping_key.tap_count > 1) { | 786 | if (tapping_key.tap.count > 1) { |
| 629 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); | 787 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); |
| 630 | // unregister key | 788 | // unregister key |
| 631 | process_action(&(keyrecord_t){ | 789 | process_action(&(keyrecord_t){ |
| 632 | .tap_count = tapping_key.tap_count, | 790 | .tap = tapping_key.tap, |
| 633 | .event.key = tapping_key.event.key, | 791 | .event.key = tapping_key.event.key, |
| 634 | .event.time = event.time, | 792 | .event.time = event.time, |
| 635 | .event.pressed = false | 793 | .event.pressed = false |
| @@ -653,10 +811,11 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 653 | } | 811 | } |
| 654 | } else if (IS_TAPPING_RELEASED()) { | 812 | } else if (IS_TAPPING_RELEASED()) { |
| 655 | if (WITHIN_TAPPING_TERM(event)) { | 813 | if (WITHIN_TAPPING_TERM(event)) { |
| 656 | if (tapping_key.tap_count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { | 814 | if (tapping_key.tap.count > 0 && IS_TAPPING_KEY(event.key) && event.pressed) { |
| 657 | // sequential tap. | 815 | // sequential tap. |
| 658 | keyp->tap_count = tapping_key.tap_count + 1; | 816 | keyp->tap = tapping_key.tap; |
| 659 | debug("Tapping: Tap press("); debug_dec(keyp->tap_count); debug(")\n"); | 817 | keyp->tap.count += 1; |
| 818 | debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); | ||
| 660 | process_action(keyp); | 819 | process_action(keyp); |
| 661 | tapping_key = *keyp; | 820 | tapping_key = *keyp; |
| 662 | debug_tapping_key(); | 821 | debug_tapping_key(); |
| @@ -701,16 +860,16 @@ static bool process_tapping(keyrecord_t *keyp) | |||
| 701 | static void waiting_buffer_scan_tap(void) | 860 | static void waiting_buffer_scan_tap(void) |
| 702 | { | 861 | { |
| 703 | // tapping already is settled | 862 | // tapping already is settled |
| 704 | if (tapping_key.tap_count > 0) return; | 863 | if (tapping_key.tap.count > 0) return; |
| 705 | // invalid state: tapping_key released && tap_count == 0 | 864 | // invalid state: tapping_key released && tap.count == 0 |
| 706 | if (!tapping_key.event.pressed) return; | 865 | if (!tapping_key.event.pressed) return; |
| 707 | 866 | ||
| 708 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 867 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
| 709 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && | 868 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && |
| 710 | !waiting_buffer[i].event.pressed && | 869 | !waiting_buffer[i].event.pressed && |
| 711 | WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { | 870 | WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { |
| 712 | tapping_key.tap_count = 1; | 871 | tapping_key.tap.count = 1; |
| 713 | waiting_buffer[i].tap_count = 1; | 872 | waiting_buffer[i].tap.count = 1; |
| 714 | process_action(&tapping_key); | 873 | process_action(&tapping_key); |
| 715 | 874 | ||
| 716 | debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); | 875 | debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); |
| @@ -813,39 +972,24 @@ bool sending_anykey(void) | |||
| 813 | host_last_sysytem_report() || host_last_consumer_report()); | 972 | host_last_sysytem_report() || host_last_consumer_report()); |
| 814 | } | 973 | } |
| 815 | 974 | ||
| 816 | void layer_switch(uint8_t new_layer) | ||
| 817 | { | ||
| 818 | if (current_layer != new_layer) { | ||
| 819 | debug("Layer Switch: "); debug_hex(current_layer); | ||
| 820 | debug(" -> "); debug_hex(new_layer); debug("\n"); | ||
| 821 | |||
| 822 | current_layer = new_layer; | ||
| 823 | clear_keyboard_but_mods(); // To avoid stuck keys | ||
| 824 | // NOTE: update mods with full scan of matrix? if modifier changes between layers | ||
| 825 | } | ||
| 826 | } | ||
| 827 | |||
| 828 | bool is_tap_key(key_t key) | 975 | bool is_tap_key(key_t key) |
| 829 | { | 976 | { |
| 830 | action_t action = get_action(key); | 977 | action_t action = layer_switch_get_action(key); |
| 831 | 978 | ||
| 832 | switch (action.kind.id) { | 979 | switch (action.kind.id) { |
| 833 | case ACT_LMODS_TAP: | 980 | case ACT_LMODS_TAP: |
| 834 | case ACT_RMODS_TAP: | 981 | case ACT_RMODS_TAP: |
| 835 | return true; | 982 | return true; |
| 836 | case ACT_LAYER: | 983 | case ACT_KEYMAP: |
| 837 | case ACT_LAYER_BIT: | 984 | case ACT_OVERLAY: |
| 838 | switch (action.layer.code) { | 985 | switch (action.layer.code) { |
| 839 | case LAYER_MOMENTARY: | 986 | case 0x04 ... 0xEF: /* tap key */ |
| 840 | case LAYER_ON_PRESS: | 987 | case OP_INV: |
| 841 | case LAYER_ON_RELEASE: | ||
| 842 | case LAYER_DEFAULT: | ||
| 843 | return false; | ||
| 844 | case LAYER_TAP_TOGGLE: | ||
| 845 | default: /* tap key */ | ||
| 846 | return true; | 988 | return true; |
| 989 | default: | ||
| 990 | return false; | ||
| 847 | } | 991 | } |
| 848 | return false; | 992 | case ACT_MACRO: |
| 849 | case ACT_FUNCTION: | 993 | case ACT_FUNCTION: |
| 850 | if (action.func.opt & FUNC_TAP) { return true; } | 994 | if (action.func.opt & FUNC_TAP) { return true; } |
| 851 | return false; | 995 | return false; |
| @@ -865,7 +1009,8 @@ static void debug_event(keyevent_t event) | |||
| 865 | } | 1009 | } |
| 866 | static void debug_record(keyrecord_t record) | 1010 | static void debug_record(keyrecord_t record) |
| 867 | { | 1011 | { |
| 868 | debug_event(record.event); debug(":"); debug_dec(record.tap_count); | 1012 | debug_event(record.event); debug(":"); debug_dec(record.tap.count); |
| 1013 | if (record.tap.interrupted) debug("-"); | ||
| 869 | } | 1014 | } |
| 870 | static void debug_action(action_t action) | 1015 | static void debug_action(action_t action) |
| 871 | { | 1016 | { |
| @@ -876,8 +1021,8 @@ static void debug_action(action_t action) | |||
| 876 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; | 1021 | case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; |
| 877 | case ACT_USAGE: debug("ACT_USAGE"); break; | 1022 | case ACT_USAGE: debug("ACT_USAGE"); break; |
| 878 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; | 1023 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
| 879 | case ACT_LAYER: debug("ACT_LAYER"); break; | 1024 | case ACT_KEYMAP: debug("ACT_KEYMAP"); break; |
| 880 | case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break; | 1025 | case ACT_OVERLAY: debug("ACT_OVERLAY"); break; |
| 881 | case ACT_MACRO: debug("ACT_MACRO"); break; | 1026 | case ACT_MACRO: debug("ACT_MACRO"); break; |
| 882 | case ACT_COMMAND: debug("ACT_COMMAND"); break; | 1027 | case ACT_COMMAND: debug("ACT_COMMAND"); break; |
| 883 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; | 1028 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
