diff options
| -rw-r--r-- | common_features.mk | 17 | ||||
| -rw-r--r-- | quantum/process_keycode/process_grave_esc.c | 71 | ||||
| -rw-r--r-- | quantum/process_keycode/process_grave_esc.h | 20 | ||||
| -rw-r--r-- | quantum/quantum.c | 55 | ||||
| -rw-r--r-- | quantum/quantum.h | 4 |
5 files changed, 110 insertions, 57 deletions
diff --git a/common_features.mk b/common_features.mk index 2c24eb28c..425d5b473 100644 --- a/common_features.mk +++ b/common_features.mk | |||
| @@ -420,6 +420,12 @@ ifeq ($(strip $(LEADER_ENABLE)), yes) | |||
| 420 | OPT_DEFS += -DLEADER_ENABLE | 420 | OPT_DEFS += -DLEADER_ENABLE |
| 421 | endif | 421 | endif |
| 422 | 422 | ||
| 423 | |||
| 424 | ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes) | ||
| 425 | SRC += $(QUANTUM_DIR)/dip_switch.c | ||
| 426 | OPT_DEFS += -DDIP_SWITCH_ENABLE | ||
| 427 | endif | ||
| 428 | |||
| 423 | include $(DRIVER_PATH)/qwiic/qwiic.mk | 429 | include $(DRIVER_PATH)/qwiic/qwiic.mk |
| 424 | 430 | ||
| 425 | QUANTUM_SRC:= \ | 431 | QUANTUM_SRC:= \ |
| @@ -505,12 +511,13 @@ ifeq ($(strip $(MAGIC_ENABLE)), yes) | |||
| 505 | OPT_DEFS += -DMAGIC_KEYCODE_ENABLE | 511 | OPT_DEFS += -DMAGIC_KEYCODE_ENABLE |
| 506 | endif | 512 | endif |
| 507 | 513 | ||
| 514 | GRAVE_ESC_ENABLE ?= yes | ||
| 515 | ifeq ($(strip $(GRAVE_ESC_ENABLE)), yes) | ||
| 516 | SRC += $(QUANTUM_DIR)/process_keycode/process_grave_esc.c | ||
| 517 | OPT_DEFS += -DGRAVE_ESC_ENABLE | ||
| 518 | endif | ||
| 519 | |||
| 508 | ifeq ($(strip $(DYNAMIC_MACRO_ENABLE)), yes) | 520 | ifeq ($(strip $(DYNAMIC_MACRO_ENABLE)), yes) |
| 509 | SRC += $(QUANTUM_DIR)/process_keycode/process_dynamic_macro.c | 521 | SRC += $(QUANTUM_DIR)/process_keycode/process_dynamic_macro.c |
| 510 | OPT_DEFS += -DDYNAMIC_MACRO_ENABLE | 522 | OPT_DEFS += -DDYNAMIC_MACRO_ENABLE |
| 511 | endif | 523 | endif |
| 512 | |||
| 513 | ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes) | ||
| 514 | SRC += $(QUANTUM_DIR)/dip_switch.c | ||
| 515 | OPT_DEFS += -DDIP_SWITCH_ENABLE | ||
| 516 | endif | ||
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 | } | ||
diff --git a/quantum/process_keycode/process_grave_esc.h b/quantum/process_keycode/process_grave_esc.h new file mode 100644 index 000000000..bbf448376 --- /dev/null +++ b/quantum/process_keycode/process_grave_esc.h | |||
| @@ -0,0 +1,20 @@ | |||
| 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 | #pragma once | ||
| 17 | |||
| 18 | #include "quantum.h" | ||
| 19 | |||
| 20 | bool process_grave_esc(uint16_t keycode, keyrecord_t *record); | ||
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 | ||
diff --git a/quantum/quantum.h b/quantum/quantum.h index 3b9eeaa6d..fbd5e9079 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -138,6 +138,10 @@ extern layer_state_t layer_state; | |||
| 138 | # include "process_magic.h" | 138 | # include "process_magic.h" |
| 139 | #endif | 139 | #endif |
| 140 | 140 | ||
| 141 | #ifdef GRAVE_ESC_ENABLE | ||
| 142 | # include "process_grave_esc.h" | ||
| 143 | #endif | ||
| 144 | |||
| 141 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 145 | #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 142 | # include "process_rgb.h" | 146 | # include "process_rgb.h" |
| 143 | #endif | 147 | #endif |
