diff options
author | Joel Challis <git@zvecr.com> | 2020-02-05 02:49:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-04 18:49:10 -0800 |
commit | 393937b43fe37a9faceb3a40e5f6fcc604659fb0 (patch) | |
tree | 16fc3d9226a68205021d7db2ce6530b38f6868e7 /quantum/process_keycode/process_grave_esc.c | |
parent | efe8bd8e9218f67a0845ccfa3eef7b074aebf7dc (diff) | |
download | qmk_firmware-393937b43fe37a9faceb3a40e5f6fcc604659fb0.tar.gz qmk_firmware-393937b43fe37a9faceb3a40e5f6fcc604659fb0.zip |
Relocate grave keycode processing (#8082)
* Relocate grave keycode processing
* Tidy up code
* Refactor grave -> grave_esc
Diffstat (limited to 'quantum/process_keycode/process_grave_esc.c')
-rw-r--r-- | quantum/process_keycode/process_grave_esc.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_grave_esc.c b/quantum/process_keycode/process_grave_esc.c new file mode 100644 index 000000000..41c50f5cb --- /dev/null +++ b/quantum/process_keycode/process_grave_esc.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* Copyright 2020 | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #include "process_grave_esc.h" | ||
17 | |||
18 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. | ||
19 | * Used to ensure that the correct keycode is released if the key is released. | ||
20 | */ | ||
21 | static bool grave_esc_was_shifted = false; | ||
22 | |||
23 | bool process_grave_esc(uint16_t keycode, keyrecord_t *record) { | ||
24 | if (keycode == GRAVE_ESC) { | ||
25 | const uint8_t mods = get_mods(); | ||
26 | uint8_t shifted = mods & MOD_MASK_SG; | ||
27 | |||
28 | #ifdef GRAVE_ESC_ALT_OVERRIDE | ||
29 | // if ALT is pressed, ESC is always sent | ||
30 | // this is handy for the cmd+opt+esc shortcut on macOS, among other things. | ||
31 | if (mods & MOD_MASK_ALT) { | ||
32 | shifted = 0; | ||
33 | } | ||
34 | #endif | ||
35 | |||
36 | #ifdef GRAVE_ESC_CTRL_OVERRIDE | ||
37 | // if CTRL is pressed, ESC is always sent | ||
38 | // this is handy for the ctrl+shift+esc shortcut on windows, among other things. | ||
39 | if (mods & MOD_MASK_CTRL) { | ||
40 | shifted = 0; | ||
41 | } | ||
42 | #endif | ||
43 | |||
44 | #ifdef GRAVE_ESC_GUI_OVERRIDE | ||
45 | // if GUI is pressed, ESC is always sent | ||
46 | if (mods & MOD_MASK_GUI) { | ||
47 | shifted = 0; | ||
48 | } | ||
49 | #endif | ||
50 | |||
51 | #ifdef GRAVE_ESC_SHIFT_OVERRIDE | ||
52 | // if SHIFT is pressed, ESC is always sent | ||
53 | if (mods & MOD_MASK_SHIFT) { | ||
54 | shifted = 0; | ||
55 | } | ||
56 | #endif | ||
57 | |||
58 | if (record->event.pressed) { | ||
59 | grave_esc_was_shifted = shifted; | ||
60 | add_key(shifted ? KC_GRAVE : KC_ESCAPE); | ||
61 | } else { | ||
62 | del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); | ||
63 | } | ||
64 | |||
65 | send_keyboard_report(); | ||
66 | return false; | ||
67 | } | ||
68 | |||
69 | // Not a grave keycode so continue processing | ||
70 | return true; | ||
71 | } | ||