diff options
Diffstat (limited to 'users/danielo515/alt_tab.c')
| -rw-r--r-- | users/danielo515/alt_tab.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/users/danielo515/alt_tab.c b/users/danielo515/alt_tab.c new file mode 100644 index 000000000..1602ee6fb --- /dev/null +++ b/users/danielo515/alt_tab.c | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #include "danielo515.h" | ||
| 2 | #include "alt_tab.h" | ||
| 3 | |||
| 4 | bool altPressed = false; | ||
| 5 | __attribute__((weak)) void alt_tab_activated(void){}; | ||
| 6 | __attribute__((weak)) void alt_tab_deactivated(void){}; | ||
| 7 | extern bool onMac; | ||
| 8 | |||
| 9 | // =============== ALT_TAB single key handling | ||
| 10 | bool process_alt_tab(uint16_t keycode, keyrecord_t *record) { | ||
| 11 | switch (keycode) { | ||
| 12 | case ALT_TAB: | ||
| 13 | if (!record->event.pressed) { | ||
| 14 | return false; | ||
| 15 | } | ||
| 16 | if (altPressed) { | ||
| 17 | tap_code(KC_TAB); | ||
| 18 | } else { | ||
| 19 | altPressed = true; | ||
| 20 | onMac ? register_code(KC_LGUI) : register_code(KC_LALT); | ||
| 21 | tap_code(KC_TAB); | ||
| 22 | alt_tab_activated(); | ||
| 23 | } | ||
| 24 | // avoid alt releasing if the key is of movement | ||
| 25 | case KC_RIGHT ... KC_UP: | ||
| 26 | if (altPressed) { | ||
| 27 | return true; // yes QMK, do your stuff | ||
| 28 | } | ||
| 29 | } | ||
| 30 | // Reset sticky alt tab when any other key is pressed | ||
| 31 | if (altPressed) { | ||
| 32 | onMac ? unregister_code(KC_LGUI) : unregister_code(KC_LALT); | ||
| 33 | altPressed = false; | ||
| 34 | alt_tab_deactivated(); | ||
| 35 | return false; | ||
| 36 | } | ||
| 37 | return true; | ||
| 38 | }; | ||
