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/quantum.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/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index 36062866e..52062bb17 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -256,6 +256,9 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 256 | #ifdef MAGIC_KEYCODE_ENABLE | 256 | #ifdef MAGIC_KEYCODE_ENABLE |
| 257 | process_magic(keycode, record) && | 257 | process_magic(keycode, record) && |
| 258 | #endif | 258 | #endif |
| 259 | #ifdef GRAVE_ESC_ENABLE | ||
| 260 | process_grave_esc(keycode, record) && | ||
| 261 | #endif | ||
| 259 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 262 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 260 | process_rgb(keycode, record) && | 263 | process_rgb(keycode, record) && |
| 261 | #endif | 264 | #endif |
| @@ -316,58 +319,6 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 316 | } | 319 | } |
| 317 | } | 320 | } |
| 318 | 321 | ||
| 319 | // keycodes that depend on both pressed and non-pressed state | ||
| 320 | switch (keycode) { | ||
| 321 | case GRAVE_ESC: { | ||
| 322 | /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise. | ||
| 323 | * Used to ensure that the correct keycode is released if the key is released. | ||
| 324 | */ | ||
| 325 | static bool grave_esc_was_shifted = false; | ||
| 326 | |||
| 327 | uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))); | ||
| 328 | |||
| 329 | #ifdef GRAVE_ESC_ALT_OVERRIDE | ||
| 330 | // if ALT is pressed, ESC is always sent | ||
| 331 | // this is handy for the cmd+opt+esc shortcut on macOS, among other things. | ||
| 332 | if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { | ||
| 333 | shifted = 0; | ||
| 334 | } | ||
| 335 | #endif | ||
| 336 | |||
| 337 | #ifdef GRAVE_ESC_CTRL_OVERRIDE | ||
| 338 | // if CTRL is pressed, ESC is always sent | ||
| 339 | // this is handy for the ctrl+shift+esc shortcut on windows, among other things. | ||
| 340 | if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { | ||
| 341 | shifted = 0; | ||
| 342 | } | ||
| 343 | #endif | ||
| 344 | |||
| 345 | #ifdef GRAVE_ESC_GUI_OVERRIDE | ||
| 346 | // if GUI is pressed, ESC is always sent | ||
| 347 | if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { | ||
| 348 | shifted = 0; | ||
| 349 | } | ||
| 350 | #endif | ||
| 351 | |||
| 352 | #ifdef GRAVE_ESC_SHIFT_OVERRIDE | ||
| 353 | // if SHIFT is pressed, ESC is always sent | ||
| 354 | if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { | ||
| 355 | shifted = 0; | ||
| 356 | } | ||
| 357 | #endif | ||
| 358 | |||
| 359 | if (record->event.pressed) { | ||
| 360 | grave_esc_was_shifted = shifted; | ||
| 361 | add_key(shifted ? KC_GRAVE : KC_ESCAPE); | ||
| 362 | } else { | ||
| 363 | del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); | ||
| 364 | } | ||
| 365 | |||
| 366 | send_keyboard_report(); | ||
| 367 | return false; | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | return process_action_kb(record); | 322 | return process_action_kb(record); |
| 372 | } | 323 | } |
| 373 | 324 | ||
