diff options
author | Nick Brassel <nick@tzarc.org> | 2022-07-03 00:16:33 +1000 |
---|---|---|
committer | Nick Brassel <nick@tzarc.org> | 2022-07-03 00:16:33 +1000 |
commit | ea14a93718f1d7b54c63d9eef7deedb868f65b30 (patch) | |
tree | 6cc6797ade5e3e55e721e2e199ad394d1c82d271 /users/gourdo1/custom_double_taps.h | |
parent | ac5e6b6a3bfad12ab7d9786a18fcc90f8bf4caf7 (diff) | |
parent | 5108d531691421be0fc4784a5a76fff7ab9aee63 (diff) |
Merge remote-tracking branch 'upstream/master' into develop
Diffstat (limited to 'users/gourdo1/custom_double_taps.h')
-rw-r--r-- | users/gourdo1/custom_double_taps.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/users/gourdo1/custom_double_taps.h b/users/gourdo1/custom_double_taps.h new file mode 100644 index 0000000000..4f551e1fa1 --- /dev/null +++ b/users/gourdo1/custom_double_taps.h @@ -0,0 +1,73 @@ +// Copyright 2022 Google LLC +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "gourdo1.h" + +static bool process_capsnum(uint16_t keycode, keyrecord_t * record) { + static bool toggled = false; + static bool tapped = false; + static uint16_t tap_timer = 0; + + if (keycode == CAPSNUM) { + if (user_config.double_tap_shift_for_capslock) { + // Act as TT(_NUMPADMOUSE) + if (record -> event.pressed) { // CAPSNUM key was pressed + // Check whether the key was recently tapped + if (tapped && !timer_expired(record -> event.time, tap_timer)) { + // This is a double tap (or possibly a triple tap or more) + // Toggle the layer on. + toggled = true; + } else if (toggled) { + // Otherwise if currently toggled, turn it off + toggled = false; + tapped = false; + layer_off(_NUMPADMOUSE); + } + // Set that the first tap occurred in a potential double tap + tapped = true; + tap_timer = record -> event.time + TAPPING_TERM; + layer_on(_NUMPADMOUSE); + } else if (!toggled) { + // If not currently toggled, turn off on key release + layer_off(_NUMPADMOUSE); + return false; + } + } else { // When double_tap_shift_for_capslock == false + // Act as KC_CAPS + if (record -> event.pressed) { + register_code(KC_CAPS); + } else { + unregister_code(KC_CAPS); + } + } + return false; + } else { + // On an event with any other key, reset the double tap state + tapped = false; + } + return true; +} + +static bool process_esc_to_base(uint16_t keycode, keyrecord_t * record) { + static bool tapped = false; + static uint16_t tap_timer = 0; + + if (keycode == KC_ESC) { + if (user_config.esc_double_tap_to_baselyr) { + if (record -> event.pressed) { + if (tapped && !timer_expired(record -> event.time, tap_timer)) { + // The key was double tapped. + layer_clear(); + } + tapped = true; + tap_timer = record -> event.time + TAPPING_TERM; + } + } + } else { + // On an event with any other key, reset the double tap state. + tapped = false; + } + return true; +} |