PoC: Swap Escape and Caps (#16336)

master^2
Osamu Aoki 2022-07-02 21:08:48 +09:00 committed by GitHub
parent c7d8adfeaa
commit 871eeae4ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 0 deletions

View File

@ -337,6 +337,9 @@ See also: [Magic Keycodes](keycodes_magic.md)
|`MAGIC_SWAP_CONTROL_CAPSLOCK` |`CL_SWAP`|Swap Caps Lock and Left Control |
|`MAGIC_UNSWAP_CONTROL_CAPSLOCK` |`CL_NORM`|Unswap Caps Lock and Left Control |
|`MAGIC_TOGGLE_CONTROL_CAPSLOCK` |`CL_TOGG`|Toggle Caps Lock and Left Control swap |
|`MAGIC_SWAP_ESCAPE_CAPSLOCK` |`EC_SWAP`|Swap Caps Lock and Escape |
|`MAGIC_UNSWAP_ESCAPE_CAPSLOCK` |`EC_NORM`|Unswap Caps Lock and Escape |
|`MAGIC_TOGGLE_ESCAPE_CAPSLOCK` |`EC_TOGG`|Toggle Caps Lock and Escape swap |
|`MAGIC_CAPSLOCK_TO_CONTROL` |`CL_CTRL`|Treat Caps Lock as Control |
|`MAGIC_UNCAPSLOCK_TO_CONTROL` |`CL_CAPS`|Stop treating Caps Lock as Control |
|`MAGIC_SWAP_LCTL_LGUI` |`LCG_SWP`|Swap Left Control and GUI |

View File

@ -7,6 +7,9 @@
|`MAGIC_SWAP_CONTROL_CAPSLOCK` |`CL_SWAP`|Swap Caps Lock and Left Control |
|`MAGIC_UNSWAP_CONTROL_CAPSLOCK` |`CL_NORM`|Unswap Caps Lock and Left Control |
|`MAGIC_TOGGLE_CONTROL_CAPSLOCK` |`CL_TOGG`|Toggle Caps Lock and Left Control swap |
|`MAGIC_SWAP_ESCAPE_CAPSLOCK` |`EC_SWAP`|Swap Caps Lock and Escape |
|`MAGIC_UNSWAP_ESCAPE_CAPSLOCK` |`EC_NORM`|Unswap Caps Lock and Escape |
|`MAGIC_TOGGLE_ESCAPE_CAPSLOCK` |`EC_TOGG`|Toggle Caps Lock and Escape swap |
|`MAGIC_CAPSLOCK_TO_CONTROL` |`CL_CTRL`|Treat Caps Lock as Control |
|`MAGIC_UNCAPSLOCK_TO_CONTROL` |`CL_CAPS`|Stop treating Caps Lock as Control |
|`MAGIC_SWAP_LCTL_LGUI` |`LCG_SWP`|Swap Left Control and GUI |

View File

@ -282,6 +282,7 @@ static void print_eeconfig(void) {
".swap_grave_esc: %u\n"
".swap_backslash_backspace: %u\n"
".nkro: %u\n"
".swap_escape_capslock: %u\n"
, kc.raw
, kc.swap_control_capslock
@ -294,6 +295,7 @@ static void print_eeconfig(void) {
, kc.swap_grave_esc
, kc.swap_backslash_backspace
, kc.nkro
, kc.swap_escape_capslock
); /* clang-format on */
# ifdef BACKLIGHT_ENABLE

View File

@ -29,6 +29,8 @@ uint16_t keycode_config(uint16_t keycode) {
case KC_LOCKING_CAPS_LOCK:
if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
return KC_LEFT_CTRL;
} else if (keymap_config.swap_escape_capslock) {
return KC_ESCAPE;
}
return keycode;
case KC_LEFT_CTRL:
@ -96,6 +98,8 @@ uint16_t keycode_config(uint16_t keycode) {
case KC_ESCAPE:
if (keymap_config.swap_grave_esc) {
return KC_GRAVE;
} else if (keymap_config.swap_escape_capslock) {
return KC_CAPS_LOCK;
}
return KC_ESCAPE;
case KC_BACKSLASH:

View File

@ -38,6 +38,7 @@ typedef union {
bool swap_lctl_lgui : 1;
bool swap_rctl_rgui : 1;
bool oneshot_enable : 1;
bool swap_escape_capslock : 1;
};
} keymap_config_t;

View File

@ -45,12 +45,16 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) {
case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT:
case MAGIC_TOGGLE_GUI:
case MAGIC_TOGGLE_CONTROL_CAPSLOCK:
case MAGIC_SWAP_ESCAPE_CAPSLOCK ... MAGIC_TOGGLE_ESCAPE_CAPSLOCK:
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();
switch (keycode) {
case MAGIC_SWAP_CONTROL_CAPSLOCK:
keymap_config.swap_control_capslock = true;
break;
case MAGIC_SWAP_ESCAPE_CAPSLOCK:
keymap_config.swap_escape_capslock = true;
break;
case MAGIC_CAPSLOCK_TO_CONTROL:
keymap_config.capslock_to_control = true;
break;
@ -94,6 +98,9 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) {
case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
keymap_config.swap_control_capslock = false;
break;
case MAGIC_UNSWAP_ESCAPE_CAPSLOCK:
keymap_config.swap_escape_capslock = false;
break;
case MAGIC_UNCAPSLOCK_TO_CONTROL:
keymap_config.capslock_to_control = false;
break;
@ -172,6 +179,9 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) {
case MAGIC_TOGGLE_CONTROL_CAPSLOCK:
keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
break;
case MAGIC_TOGGLE_ESCAPE_CAPSLOCK:
keymap_config.swap_escape_capslock = !keymap_config.swap_escape_capslock;
break;
}
eeconfig_update_keymap(keymap_config.raw);

View File

@ -605,6 +605,10 @@ enum quantum_keycodes {
CAPS_WORD,
MAGIC_SWAP_ESCAPE_CAPSLOCK,
MAGIC_UNSWAP_ESCAPE_CAPSLOCK,
MAGIC_TOGGLE_ESCAPE_CAPSLOCK,
// Start of custom keycode range for keyboards and keymaps - always leave at the end
SAFE_RANGE
};
@ -756,6 +760,10 @@ enum quantum_keycodes {
#define CL_CAPS MAGIC_UNCAPSLOCK_TO_CONTROL
#define CL_TOGG MAGIC_TOGGLE_CONTROL_CAPSLOCK
#define EC_SWAP MAGIC_SWAP_ESCAPE_CAPSLOCK
#define EC_NORM MAGIC_UNSWAP_ESCAPE_CAPSLOCK
#define EC_TOGG MAGIC_TOGGLE_ESCAPE_CAPSLOCK
#define LCG_SWP MAGIC_SWAP_LCTL_LGUI
#define LCG_NRM MAGIC_UNSWAP_LCTL_LGUI
#define RCG_SWP MAGIC_SWAP_RCTL_RGUI