diff options
Diffstat (limited to 'users/callum/oneshot.c')
| -rw-r--r-- | users/callum/oneshot.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/users/callum/oneshot.c b/users/callum/oneshot.c new file mode 100644 index 000000000..33ec3895e --- /dev/null +++ b/users/callum/oneshot.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #include "oneshot.h" | ||
| 2 | |||
| 3 | void update_oneshot( | ||
| 4 | oneshot_state *state, | ||
| 5 | uint16_t mod, | ||
| 6 | uint16_t trigger, | ||
| 7 | uint16_t keycode, | ||
| 8 | keyrecord_t *record | ||
| 9 | ) { | ||
| 10 | if (keycode == trigger) { | ||
| 11 | if (record->event.pressed) { | ||
| 12 | // Trigger keydown | ||
| 13 | if (*state == os_up_unqueued) { | ||
| 14 | register_code(mod); | ||
| 15 | } | ||
| 16 | *state = os_down_unused; | ||
| 17 | } else { | ||
| 18 | // Trigger keyup | ||
| 19 | switch (*state) { | ||
| 20 | case os_down_unused: | ||
| 21 | // If we didn't use the mod while trigger was held, queue it. | ||
| 22 | *state = os_up_queued; | ||
| 23 | break; | ||
| 24 | case os_down_used: | ||
| 25 | // If we did use the mod while trigger was held, unregister it. | ||
| 26 | *state = os_up_unqueued; | ||
| 27 | unregister_code(mod); | ||
| 28 | break; | ||
| 29 | default: | ||
| 30 | break; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } else { | ||
| 34 | if (record->event.pressed) { | ||
| 35 | if (is_oneshot_cancel_key(keycode) && *state != os_up_unqueued) { | ||
| 36 | // Cancel oneshot on designated cancel keydown. | ||
| 37 | *state = os_up_unqueued; | ||
| 38 | unregister_code(mod); | ||
| 39 | } | ||
| 40 | } else { | ||
| 41 | if (!is_oneshot_ignored_key(keycode)) { | ||
| 42 | // On non-ignored keyup, consider the oneshot used. | ||
| 43 | switch (*state) { | ||
| 44 | case os_down_unused: | ||
| 45 | *state = os_down_used; | ||
| 46 | break; | ||
| 47 | case os_up_queued: | ||
| 48 | *state = os_up_unqueued; | ||
| 49 | unregister_code(mod); | ||
| 50 | break; | ||
| 51 | default: | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
