diff options
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 151 |
1 files changed, 68 insertions, 83 deletions
diff --git a/common/action.c b/common/action.c index 59c6f252d..f7ae85b94 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -23,8 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | #include "backlight.h" | 23 | #include "backlight.h" |
| 24 | #include "action_layer.h" | 24 | #include "action_layer.h" |
| 25 | #include "action_tapping.h" | 25 | #include "action_tapping.h" |
| 26 | #include "action_oneshot.h" | ||
| 27 | #include "action_macro.h" | 26 | #include "action_macro.h" |
| 27 | #include "action_util.h" | ||
| 28 | #include "action.h" | 28 | #include "action.h" |
| 29 | 29 | ||
| 30 | #ifdef DEBUG_ACTION | 30 | #ifdef DEBUG_ACTION |
| @@ -79,15 +79,15 @@ void process_action(keyrecord_t *record) | |||
| 79 | action.key.mods<<4; | 79 | action.key.mods<<4; |
| 80 | if (event.pressed) { | 80 | if (event.pressed) { |
| 81 | if (mods) { | 81 | if (mods) { |
| 82 | host_add_mods(mods); | 82 | add_weak_mods(mods); |
| 83 | host_send_keyboard_report(); | 83 | send_keyboard_report(); |
| 84 | } | 84 | } |
| 85 | register_code(action.key.code); | 85 | register_code(action.key.code); |
| 86 | } else { | 86 | } else { |
| 87 | unregister_code(action.key.code); | 87 | unregister_code(action.key.code); |
| 88 | if (mods) { | 88 | if (mods) { |
| 89 | host_del_mods(mods); | 89 | del_weak_mods(mods); |
| 90 | host_send_keyboard_report(); | 90 | send_keyboard_report(); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| @@ -100,43 +100,30 @@ void process_action(keyrecord_t *record) | |||
| 100 | action.key.mods<<4; | 100 | action.key.mods<<4; |
| 101 | switch (action.layer_tap.code) { | 101 | switch (action.layer_tap.code) { |
| 102 | #ifndef NO_ACTION_ONESHOT | 102 | #ifndef NO_ACTION_ONESHOT |
| 103 | case 0x00: | 103 | case MODS_ONESHOT: |
| 104 | // Oneshot modifier | 104 | // Oneshot modifier |
| 105 | if (event.pressed) { | 105 | if (event.pressed) { |
| 106 | if (tap_count == 0) { | 106 | if (tap_count == 0) { |
| 107 | dprint("MODS_TAP: Oneshot: add_mods\n"); | 107 | register_mods(mods); |
| 108 | add_mods(mods); | ||
| 109 | } | 108 | } |
| 110 | else if (tap_count == 1) { | 109 | else if (tap_count == 1) { |
| 111 | dprint("MODS_TAP: Oneshot: start\n"); | 110 | dprint("MODS_TAP: Oneshot: start\n"); |
| 112 | oneshot_start(mods); | 111 | set_oneshot_mods(mods); |
| 113 | } | ||
| 114 | else if (tap_count == TAPPING_TOGGLE) { | ||
| 115 | dprint("MODS_TAP: Oneshot: toggle\n"); | ||
| 116 | oneshot_toggle(); | ||
| 117 | } | 112 | } |
| 118 | else { | 113 | else { |
| 119 | dprint("MODS_TAP: Oneshot: cancel&add_mods\n"); | 114 | register_mods(mods); |
| 120 | // double tap cancels oneshot and works as normal modifier. | ||
| 121 | oneshot_cancel(); | ||
| 122 | add_mods(mods); | ||
| 123 | } | 115 | } |
| 124 | } else { | 116 | } else { |
| 125 | if (tap_count == 0) { | 117 | if (tap_count == 0) { |
| 126 | dprint("MODS_TAP: Oneshot: cancel/del_mods\n"); | 118 | clear_oneshot_mods(); |
| 127 | // cancel oneshot on hold | 119 | unregister_mods(mods); |
| 128 | oneshot_cancel(); | ||
| 129 | del_mods(mods); | ||
| 130 | } | 120 | } |
| 131 | else if (tap_count == 1) { | 121 | else if (tap_count == 1) { |
| 132 | dprint("MODS_TAP: Oneshot: del_mods\n"); | 122 | // Retain Oneshot mods |
| 133 | // retain Oneshot | ||
| 134 | del_mods(mods); | ||
| 135 | } | 123 | } |
| 136 | else { | 124 | else { |
| 137 | dprint("MODS_TAP: Oneshot: del_mods\n"); | 125 | clear_oneshot_mods(); |
| 138 | // cancel Mods | 126 | unregister_mods(mods); |
| 139 | del_mods(mods); | ||
| 140 | } | 127 | } |
| 141 | } | 128 | } |
| 142 | break; | 129 | break; |
| @@ -148,14 +135,14 @@ void process_action(keyrecord_t *record) | |||
| 148 | dprint("MODS_TAP: Tap: Cancel: add_mods\n"); | 135 | dprint("MODS_TAP: Tap: Cancel: add_mods\n"); |
| 149 | // ad hoc: set 0 to cancel tap | 136 | // ad hoc: set 0 to cancel tap |
| 150 | record->tap.count = 0; | 137 | record->tap.count = 0; |
| 151 | add_mods(mods); | 138 | register_mods(mods); |
| 152 | } else { | 139 | } else { |
| 153 | dprint("MODS_TAP: Tap: register_code\n"); | 140 | dprint("MODS_TAP: Tap: register_code\n"); |
| 154 | register_code(action.key.code); | 141 | register_code(action.key.code); |
| 155 | } | 142 | } |
| 156 | } else { | 143 | } else { |
| 157 | dprint("MODS_TAP: No tap: add_mods\n"); | 144 | dprint("MODS_TAP: No tap: add_mods\n"); |
| 158 | add_mods(mods); | 145 | register_mods(mods); |
| 159 | } | 146 | } |
| 160 | } else { | 147 | } else { |
| 161 | if (tap_count > 0) { | 148 | if (tap_count > 0) { |
| @@ -163,7 +150,7 @@ void process_action(keyrecord_t *record) | |||
| 163 | unregister_code(action.key.code); | 150 | unregister_code(action.key.code); |
| 164 | } else { | 151 | } else { |
| 165 | dprint("MODS_TAP: No tap: add_mods\n"); | 152 | dprint("MODS_TAP: No tap: add_mods\n"); |
| 166 | del_mods(mods); | 153 | unregister_mods(mods); |
| 167 | } | 154 | } |
| 168 | } | 155 | } |
| 169 | break; | 156 | break; |
| @@ -343,30 +330,30 @@ void register_code(uint8_t code) | |||
| 343 | // Resync: ignore if caps lock already is on | 330 | // Resync: ignore if caps lock already is on |
| 344 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; | 331 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; |
| 345 | #endif | 332 | #endif |
| 346 | host_add_key(KC_CAPSLOCK); | 333 | add_key(KC_CAPSLOCK); |
| 347 | host_send_keyboard_report(); | 334 | send_keyboard_report(); |
| 348 | host_del_key(KC_CAPSLOCK); | 335 | del_key(KC_CAPSLOCK); |
| 349 | host_send_keyboard_report(); | 336 | send_keyboard_report(); |
| 350 | } | 337 | } |
| 351 | 338 | ||
| 352 | else if (KC_LOCKING_NUM == code) { | 339 | else if (KC_LOCKING_NUM == code) { |
| 353 | #ifdef LOCKING_RESYNC_ENABLE | 340 | #ifdef LOCKING_RESYNC_ENABLE |
| 354 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; | 341 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; |
| 355 | #endif | 342 | #endif |
| 356 | host_add_key(KC_NUMLOCK); | 343 | add_key(KC_NUMLOCK); |
| 357 | host_send_keyboard_report(); | 344 | send_keyboard_report(); |
| 358 | host_del_key(KC_NUMLOCK); | 345 | del_key(KC_NUMLOCK); |
| 359 | host_send_keyboard_report(); | 346 | send_keyboard_report(); |
| 360 | } | 347 | } |
| 361 | 348 | ||
| 362 | else if (KC_LOCKING_SCROLL == code) { | 349 | else if (KC_LOCKING_SCROLL == code) { |
| 363 | #ifdef LOCKING_RESYNC_ENABLE | 350 | #ifdef LOCKING_RESYNC_ENABLE |
| 364 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; | 351 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; |
| 365 | #endif | 352 | #endif |
| 366 | host_add_key(KC_SCROLLLOCK); | 353 | add_key(KC_SCROLLLOCK); |
| 367 | host_send_keyboard_report(); | 354 | send_keyboard_report(); |
| 368 | host_del_key(KC_SCROLLLOCK); | 355 | del_key(KC_SCROLLLOCK); |
| 369 | host_send_keyboard_report(); | 356 | send_keyboard_report(); |
| 370 | } | 357 | } |
| 371 | #endif | 358 | #endif |
| 372 | 359 | ||
| @@ -375,25 +362,28 @@ void register_code(uint8_t code) | |||
| 375 | if (command_proc(code)) return; | 362 | if (command_proc(code)) return; |
| 376 | 363 | ||
| 377 | #ifndef NO_ACTION_ONESHOT | 364 | #ifndef NO_ACTION_ONESHOT |
| 365 | /* TODO: remove | ||
| 378 | if (oneshot_state.mods && !oneshot_state.disabled) { | 366 | if (oneshot_state.mods && !oneshot_state.disabled) { |
| 379 | uint8_t tmp_mods = host_get_mods(); | 367 | uint8_t tmp_mods = get_mods(); |
| 380 | host_add_mods(oneshot_state.mods); | 368 | add_mods(oneshot_state.mods); |
| 381 | 369 | ||
| 382 | host_add_key(code); | 370 | add_key(code); |
| 383 | host_send_keyboard_report(); | 371 | send_keyboard_report(); |
| 384 | 372 | ||
| 385 | host_set_mods(tmp_mods); | 373 | set_mods(tmp_mods); |
| 374 | send_keyboard_report(); | ||
| 386 | oneshot_cancel(); | 375 | oneshot_cancel(); |
| 387 | } else | 376 | } else |
| 377 | */ | ||
| 388 | #endif | 378 | #endif |
| 389 | { | 379 | { |
| 390 | host_add_key(code); | 380 | add_key(code); |
| 391 | host_send_keyboard_report(); | 381 | send_keyboard_report(); |
| 392 | } | 382 | } |
| 393 | } | 383 | } |
| 394 | else if IS_MOD(code) { | 384 | else if IS_MOD(code) { |
| 395 | host_add_mods(MOD_BIT(code)); | 385 | add_mods(MOD_BIT(code)); |
| 396 | host_send_keyboard_report(); | 386 | send_keyboard_report(); |
| 397 | } | 387 | } |
| 398 | else if IS_SYSTEM(code) { | 388 | else if IS_SYSTEM(code) { |
| 399 | host_system_send(KEYCODE2SYSTEM(code)); | 389 | host_system_send(KEYCODE2SYSTEM(code)); |
| @@ -415,40 +405,40 @@ void unregister_code(uint8_t code) | |||
| 415 | // Resync: ignore if caps lock already is off | 405 | // Resync: ignore if caps lock already is off |
| 416 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; | 406 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; |
| 417 | #endif | 407 | #endif |
| 418 | host_add_key(KC_CAPSLOCK); | 408 | add_key(KC_CAPSLOCK); |
| 419 | host_send_keyboard_report(); | 409 | send_keyboard_report(); |
| 420 | host_del_key(KC_CAPSLOCK); | 410 | del_key(KC_CAPSLOCK); |
| 421 | host_send_keyboard_report(); | 411 | send_keyboard_report(); |
| 422 | } | 412 | } |
| 423 | 413 | ||
| 424 | else if (KC_LOCKING_NUM == code) { | 414 | else if (KC_LOCKING_NUM == code) { |
| 425 | #ifdef LOCKING_RESYNC_ENABLE | 415 | #ifdef LOCKING_RESYNC_ENABLE |
| 426 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; | 416 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; |
| 427 | #endif | 417 | #endif |
| 428 | host_add_key(KC_NUMLOCK); | 418 | add_key(KC_NUMLOCK); |
| 429 | host_send_keyboard_report(); | 419 | send_keyboard_report(); |
| 430 | host_del_key(KC_NUMLOCK); | 420 | del_key(KC_NUMLOCK); |
| 431 | host_send_keyboard_report(); | 421 | send_keyboard_report(); |
| 432 | } | 422 | } |
| 433 | 423 | ||
| 434 | else if (KC_LOCKING_SCROLL == code) { | 424 | else if (KC_LOCKING_SCROLL == code) { |
| 435 | #ifdef LOCKING_RESYNC_ENABLE | 425 | #ifdef LOCKING_RESYNC_ENABLE |
| 436 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; | 426 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; |
| 437 | #endif | 427 | #endif |
| 438 | host_add_key(KC_SCROLLLOCK); | 428 | add_key(KC_SCROLLLOCK); |
| 439 | host_send_keyboard_report(); | 429 | send_keyboard_report(); |
| 440 | host_del_key(KC_SCROLLLOCK); | 430 | del_key(KC_SCROLLLOCK); |
| 441 | host_send_keyboard_report(); | 431 | send_keyboard_report(); |
| 442 | } | 432 | } |
| 443 | #endif | 433 | #endif |
| 444 | 434 | ||
| 445 | else if IS_KEY(code) { | 435 | else if IS_KEY(code) { |
| 446 | host_del_key(code); | 436 | del_key(code); |
| 447 | host_send_keyboard_report(); | 437 | send_keyboard_report(); |
| 448 | } | 438 | } |
| 449 | else if IS_MOD(code) { | 439 | else if IS_MOD(code) { |
| 450 | host_del_mods(MOD_BIT(code)); | 440 | del_mods(MOD_BIT(code)); |
| 451 | host_send_keyboard_report(); | 441 | send_keyboard_report(); |
| 452 | } | 442 | } |
| 453 | else if IS_SYSTEM(code) { | 443 | else if IS_SYSTEM(code) { |
| 454 | host_system_send(0); | 444 | host_system_send(0); |
| @@ -458,38 +448,33 @@ void unregister_code(uint8_t code) | |||
| 458 | } | 448 | } |
| 459 | } | 449 | } |
| 460 | 450 | ||
| 461 | void add_mods(uint8_t mods) | 451 | void register_mods(uint8_t mods) |
| 462 | { | 452 | { |
| 463 | if (mods) { | 453 | if (mods) { |
| 464 | host_add_mods(mods); | 454 | add_mods(mods); |
| 465 | host_send_keyboard_report(); | 455 | send_keyboard_report(); |
| 466 | } | 456 | } |
| 467 | } | 457 | } |
| 468 | 458 | ||
| 469 | void del_mods(uint8_t mods) | 459 | void unregister_mods(uint8_t mods) |
| 470 | { | 460 | { |
| 471 | if (mods) { | 461 | if (mods) { |
| 472 | host_del_mods(mods); | 462 | del_mods(mods); |
| 473 | host_send_keyboard_report(); | 463 | send_keyboard_report(); |
| 474 | } | 464 | } |
| 475 | } | 465 | } |
| 476 | 466 | ||
| 477 | void set_mods(uint8_t mods) | ||
| 478 | { | ||
| 479 | host_set_mods(mods); | ||
| 480 | host_send_keyboard_report(); | ||
| 481 | } | ||
| 482 | |||
| 483 | void clear_keyboard(void) | 467 | void clear_keyboard(void) |
| 484 | { | 468 | { |
| 485 | host_clear_mods(); | 469 | clear_mods(); |
| 486 | clear_keyboard_but_mods(); | 470 | clear_keyboard_but_mods(); |
| 487 | } | 471 | } |
| 488 | 472 | ||
| 489 | void clear_keyboard_but_mods(void) | 473 | void clear_keyboard_but_mods(void) |
| 490 | { | 474 | { |
| 491 | host_clear_keys(); | 475 | clear_weak_mods(); |
| 492 | host_send_keyboard_report(); | 476 | clear_keys(); |
| 477 | send_keyboard_report(); | ||
| 493 | #ifdef MOUSEKEY_ENABLE | 478 | #ifdef MOUSEKEY_ENABLE |
| 494 | mousekey_clear(); | 479 | mousekey_clear(); |
| 495 | mousekey_send(); | 480 | mousekey_send(); |
| @@ -502,7 +487,7 @@ void clear_keyboard_but_mods(void) | |||
| 502 | 487 | ||
| 503 | bool sending_anykey(void) | 488 | bool sending_anykey(void) |
| 504 | { | 489 | { |
| 505 | return (host_has_anykey() || host_mouse_in_use() || | 490 | return (has_anykey() || host_mouse_in_use() || |
| 506 | host_last_sysytem_report() || host_last_consumer_report()); | 491 | host_last_sysytem_report() || host_last_consumer_report()); |
| 507 | } | 492 | } |
| 508 | 493 | ||
