diff options
Diffstat (limited to 'common/action.c')
| -rw-r--r-- | common/action.c | 138 |
1 files changed, 67 insertions, 71 deletions
diff --git a/common/action.c b/common/action.c index 59c6f252d..ecd5a7e94 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 | } |
| @@ -105,11 +105,11 @@ void process_action(keyrecord_t *record) | |||
| 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 | dprint("MODS_TAP: Oneshot: add_mods\n"); |
| 108 | add_mods(mods); | 108 | register_mods(mods); |
| 109 | } | 109 | } |
| 110 | else if (tap_count == 1) { | 110 | else if (tap_count == 1) { |
| 111 | dprint("MODS_TAP: Oneshot: start\n"); | 111 | dprint("MODS_TAP: Oneshot: start\n"); |
| 112 | oneshot_start(mods); | 112 | set_oneshot_mods(mods); |
| 113 | } | 113 | } |
| 114 | else if (tap_count == TAPPING_TOGGLE) { | 114 | else if (tap_count == TAPPING_TOGGLE) { |
| 115 | dprint("MODS_TAP: Oneshot: toggle\n"); | 115 | dprint("MODS_TAP: Oneshot: toggle\n"); |
| @@ -118,25 +118,23 @@ void process_action(keyrecord_t *record) | |||
| 118 | else { | 118 | else { |
| 119 | dprint("MODS_TAP: Oneshot: cancel&add_mods\n"); | 119 | dprint("MODS_TAP: Oneshot: cancel&add_mods\n"); |
| 120 | // double tap cancels oneshot and works as normal modifier. | 120 | // double tap cancels oneshot and works as normal modifier. |
| 121 | oneshot_cancel(); | 121 | clear_oneshot_mods(); |
| 122 | add_mods(mods); | 122 | register_mods(mods); |
| 123 | } | 123 | } |
| 124 | } else { | 124 | } else { |
| 125 | if (tap_count == 0) { | 125 | if (tap_count == 0) { |
| 126 | dprint("MODS_TAP: Oneshot: cancel/del_mods\n"); | 126 | dprint("MODS_TAP: Oneshot: cancel/del_mods\n"); |
| 127 | // cancel oneshot on hold | 127 | // cancel oneshot on hold |
| 128 | oneshot_cancel(); | 128 | clear_oneshot_mods(); |
| 129 | del_mods(mods); | 129 | unregister_mods(mods); |
| 130 | } | 130 | } |
| 131 | else if (tap_count == 1) { | 131 | else if (tap_count == 1) { |
| 132 | dprint("MODS_TAP: Oneshot: del_mods\n"); | 132 | // Oneshot |
| 133 | // retain Oneshot | ||
| 134 | del_mods(mods); | ||
| 135 | } | 133 | } |
| 136 | else { | 134 | else { |
| 137 | dprint("MODS_TAP: Oneshot: del_mods\n"); | 135 | dprint("MODS_TAP: Oneshot: del_mods\n"); |
| 138 | // cancel Mods | 136 | // cancel Mods |
| 139 | del_mods(mods); | 137 | unregister_mods(mods); |
| 140 | } | 138 | } |
| 141 | } | 139 | } |
| 142 | break; | 140 | break; |
| @@ -148,14 +146,14 @@ void process_action(keyrecord_t *record) | |||
| 148 | dprint("MODS_TAP: Tap: Cancel: add_mods\n"); | 146 | dprint("MODS_TAP: Tap: Cancel: add_mods\n"); |
| 149 | // ad hoc: set 0 to cancel tap | 147 | // ad hoc: set 0 to cancel tap |
| 150 | record->tap.count = 0; | 148 | record->tap.count = 0; |
| 151 | add_mods(mods); | 149 | register_mods(mods); |
| 152 | } else { | 150 | } else { |
| 153 | dprint("MODS_TAP: Tap: register_code\n"); | 151 | dprint("MODS_TAP: Tap: register_code\n"); |
| 154 | register_code(action.key.code); | 152 | register_code(action.key.code); |
| 155 | } | 153 | } |
| 156 | } else { | 154 | } else { |
| 157 | dprint("MODS_TAP: No tap: add_mods\n"); | 155 | dprint("MODS_TAP: No tap: add_mods\n"); |
| 158 | add_mods(mods); | 156 | register_mods(mods); |
| 159 | } | 157 | } |
| 160 | } else { | 158 | } else { |
| 161 | if (tap_count > 0) { | 159 | if (tap_count > 0) { |
| @@ -163,7 +161,7 @@ void process_action(keyrecord_t *record) | |||
| 163 | unregister_code(action.key.code); | 161 | unregister_code(action.key.code); |
| 164 | } else { | 162 | } else { |
| 165 | dprint("MODS_TAP: No tap: add_mods\n"); | 163 | dprint("MODS_TAP: No tap: add_mods\n"); |
| 166 | del_mods(mods); | 164 | unregister_mods(mods); |
| 167 | } | 165 | } |
| 168 | } | 166 | } |
| 169 | break; | 167 | break; |
| @@ -343,30 +341,30 @@ void register_code(uint8_t code) | |||
| 343 | // Resync: ignore if caps lock already is on | 341 | // Resync: ignore if caps lock already is on |
| 344 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; | 342 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; |
| 345 | #endif | 343 | #endif |
| 346 | host_add_key(KC_CAPSLOCK); | 344 | add_key(KC_CAPSLOCK); |
| 347 | host_send_keyboard_report(); | 345 | send_keyboard_report(); |
| 348 | host_del_key(KC_CAPSLOCK); | 346 | del_key(KC_CAPSLOCK); |
| 349 | host_send_keyboard_report(); | 347 | send_keyboard_report(); |
| 350 | } | 348 | } |
| 351 | 349 | ||
| 352 | else if (KC_LOCKING_NUM == code) { | 350 | else if (KC_LOCKING_NUM == code) { |
| 353 | #ifdef LOCKING_RESYNC_ENABLE | 351 | #ifdef LOCKING_RESYNC_ENABLE |
| 354 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; | 352 | if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; |
| 355 | #endif | 353 | #endif |
| 356 | host_add_key(KC_NUMLOCK); | 354 | add_key(KC_NUMLOCK); |
| 357 | host_send_keyboard_report(); | 355 | send_keyboard_report(); |
| 358 | host_del_key(KC_NUMLOCK); | 356 | del_key(KC_NUMLOCK); |
| 359 | host_send_keyboard_report(); | 357 | send_keyboard_report(); |
| 360 | } | 358 | } |
| 361 | 359 | ||
| 362 | else if (KC_LOCKING_SCROLL == code) { | 360 | else if (KC_LOCKING_SCROLL == code) { |
| 363 | #ifdef LOCKING_RESYNC_ENABLE | 361 | #ifdef LOCKING_RESYNC_ENABLE |
| 364 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; | 362 | if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return; |
| 365 | #endif | 363 | #endif |
| 366 | host_add_key(KC_SCROLLLOCK); | 364 | add_key(KC_SCROLLLOCK); |
| 367 | host_send_keyboard_report(); | 365 | send_keyboard_report(); |
| 368 | host_del_key(KC_SCROLLLOCK); | 366 | del_key(KC_SCROLLLOCK); |
| 369 | host_send_keyboard_report(); | 367 | send_keyboard_report(); |
| 370 | } | 368 | } |
| 371 | #endif | 369 | #endif |
| 372 | 370 | ||
| @@ -375,25 +373,28 @@ void register_code(uint8_t code) | |||
| 375 | if (command_proc(code)) return; | 373 | if (command_proc(code)) return; |
| 376 | 374 | ||
| 377 | #ifndef NO_ACTION_ONESHOT | 375 | #ifndef NO_ACTION_ONESHOT |
| 376 | /* TODO: remove | ||
| 378 | if (oneshot_state.mods && !oneshot_state.disabled) { | 377 | if (oneshot_state.mods && !oneshot_state.disabled) { |
| 379 | uint8_t tmp_mods = host_get_mods(); | 378 | uint8_t tmp_mods = get_mods(); |
| 380 | host_add_mods(oneshot_state.mods); | 379 | add_mods(oneshot_state.mods); |
| 381 | 380 | ||
| 382 | host_add_key(code); | 381 | add_key(code); |
| 383 | host_send_keyboard_report(); | 382 | send_keyboard_report(); |
| 384 | 383 | ||
| 385 | host_set_mods(tmp_mods); | 384 | set_mods(tmp_mods); |
| 385 | send_keyboard_report(); | ||
| 386 | oneshot_cancel(); | 386 | oneshot_cancel(); |
| 387 | } else | 387 | } else |
| 388 | */ | ||
| 388 | #endif | 389 | #endif |
| 389 | { | 390 | { |
| 390 | host_add_key(code); | 391 | add_key(code); |
| 391 | host_send_keyboard_report(); | 392 | send_keyboard_report(); |
| 392 | } | 393 | } |
| 393 | } | 394 | } |
| 394 | else if IS_MOD(code) { | 395 | else if IS_MOD(code) { |
| 395 | host_add_mods(MOD_BIT(code)); | 396 | add_mods(MOD_BIT(code)); |
| 396 | host_send_keyboard_report(); | 397 | send_keyboard_report(); |
| 397 | } | 398 | } |
| 398 | else if IS_SYSTEM(code) { | 399 | else if IS_SYSTEM(code) { |
| 399 | host_system_send(KEYCODE2SYSTEM(code)); | 400 | host_system_send(KEYCODE2SYSTEM(code)); |
| @@ -415,40 +416,40 @@ void unregister_code(uint8_t code) | |||
| 415 | // Resync: ignore if caps lock already is off | 416 | // Resync: ignore if caps lock already is off |
| 416 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; | 417 | if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; |
| 417 | #endif | 418 | #endif |
| 418 | host_add_key(KC_CAPSLOCK); | 419 | add_key(KC_CAPSLOCK); |
| 419 | host_send_keyboard_report(); | 420 | send_keyboard_report(); |
| 420 | host_del_key(KC_CAPSLOCK); | 421 | del_key(KC_CAPSLOCK); |
| 421 | host_send_keyboard_report(); | 422 | send_keyboard_report(); |
| 422 | } | 423 | } |
| 423 | 424 | ||
| 424 | else if (KC_LOCKING_NUM == code) { | 425 | else if (KC_LOCKING_NUM == code) { |
| 425 | #ifdef LOCKING_RESYNC_ENABLE | 426 | #ifdef LOCKING_RESYNC_ENABLE |
| 426 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; | 427 | if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; |
| 427 | #endif | 428 | #endif |
| 428 | host_add_key(KC_NUMLOCK); | 429 | add_key(KC_NUMLOCK); |
| 429 | host_send_keyboard_report(); | 430 | send_keyboard_report(); |
| 430 | host_del_key(KC_NUMLOCK); | 431 | del_key(KC_NUMLOCK); |
| 431 | host_send_keyboard_report(); | 432 | send_keyboard_report(); |
| 432 | } | 433 | } |
| 433 | 434 | ||
| 434 | else if (KC_LOCKING_SCROLL == code) { | 435 | else if (KC_LOCKING_SCROLL == code) { |
| 435 | #ifdef LOCKING_RESYNC_ENABLE | 436 | #ifdef LOCKING_RESYNC_ENABLE |
| 436 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; | 437 | if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return; |
| 437 | #endif | 438 | #endif |
| 438 | host_add_key(KC_SCROLLLOCK); | 439 | add_key(KC_SCROLLLOCK); |
| 439 | host_send_keyboard_report(); | 440 | send_keyboard_report(); |
| 440 | host_del_key(KC_SCROLLLOCK); | 441 | del_key(KC_SCROLLLOCK); |
| 441 | host_send_keyboard_report(); | 442 | send_keyboard_report(); |
| 442 | } | 443 | } |
| 443 | #endif | 444 | #endif |
| 444 | 445 | ||
| 445 | else if IS_KEY(code) { | 446 | else if IS_KEY(code) { |
| 446 | host_del_key(code); | 447 | del_key(code); |
| 447 | host_send_keyboard_report(); | 448 | send_keyboard_report(); |
| 448 | } | 449 | } |
| 449 | else if IS_MOD(code) { | 450 | else if IS_MOD(code) { |
| 450 | host_del_mods(MOD_BIT(code)); | 451 | del_mods(MOD_BIT(code)); |
| 451 | host_send_keyboard_report(); | 452 | send_keyboard_report(); |
| 452 | } | 453 | } |
| 453 | else if IS_SYSTEM(code) { | 454 | else if IS_SYSTEM(code) { |
| 454 | host_system_send(0); | 455 | host_system_send(0); |
| @@ -458,38 +459,33 @@ void unregister_code(uint8_t code) | |||
| 458 | } | 459 | } |
| 459 | } | 460 | } |
| 460 | 461 | ||
| 461 | void add_mods(uint8_t mods) | 462 | void register_mods(uint8_t mods) |
| 462 | { | 463 | { |
| 463 | if (mods) { | 464 | if (mods) { |
| 464 | host_add_mods(mods); | 465 | add_mods(mods); |
| 465 | host_send_keyboard_report(); | 466 | send_keyboard_report(); |
| 466 | } | 467 | } |
| 467 | } | 468 | } |
| 468 | 469 | ||
| 469 | void del_mods(uint8_t mods) | 470 | void unregister_mods(uint8_t mods) |
| 470 | { | 471 | { |
| 471 | if (mods) { | 472 | if (mods) { |
| 472 | host_del_mods(mods); | 473 | del_mods(mods); |
| 473 | host_send_keyboard_report(); | 474 | send_keyboard_report(); |
| 474 | } | 475 | } |
| 475 | } | 476 | } |
| 476 | 477 | ||
| 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) | 478 | void clear_keyboard(void) |
| 484 | { | 479 | { |
| 485 | host_clear_mods(); | 480 | clear_mods(); |
| 486 | clear_keyboard_but_mods(); | 481 | clear_keyboard_but_mods(); |
| 487 | } | 482 | } |
| 488 | 483 | ||
| 489 | void clear_keyboard_but_mods(void) | 484 | void clear_keyboard_but_mods(void) |
| 490 | { | 485 | { |
| 491 | host_clear_keys(); | 486 | clear_weak_mods(); |
| 492 | host_send_keyboard_report(); | 487 | clear_keys(); |
| 488 | send_keyboard_report(); | ||
| 493 | #ifdef MOUSEKEY_ENABLE | 489 | #ifdef MOUSEKEY_ENABLE |
| 494 | mousekey_clear(); | 490 | mousekey_clear(); |
| 495 | mousekey_send(); | 491 | mousekey_send(); |
| @@ -502,7 +498,7 @@ void clear_keyboard_but_mods(void) | |||
| 502 | 498 | ||
| 503 | bool sending_anykey(void) | 499 | bool sending_anykey(void) |
| 504 | { | 500 | { |
| 505 | return (host_has_anykey() || host_mouse_in_use() || | 501 | return (has_anykey() || host_mouse_in_use() || |
| 506 | host_last_sysytem_report() || host_last_consumer_report()); | 502 | host_last_sysytem_report() || host_last_consumer_report()); |
| 507 | } | 503 | } |
| 508 | 504 | ||
