Skip to content

Commit

Permalink
PoC: Swap Escape and Caps (qmk#16336)
Browse files Browse the repository at this point in the history
  • Loading branch information
osamuaoki authored and nolanseaton committed Jan 23, 2023
1 parent 24ea005 commit 2ea6a69
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/keycodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions docs/keycodes_magic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions quantum/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions quantum/keycode_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions quantum/keycode_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions quantum/process_keycode/process_magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ea6a69

Please sign in to comment.