diff --git a/docs/feature_audio.md b/docs/feature_audio.md index 7511598bcf..5132dfe971 100644 --- a/docs/feature_audio.md +++ b/docs/feature_audio.md @@ -21,6 +21,8 @@ STARTUP_SONG // plays when the keyboard starts up (audio.c) GOODBYE_SONG // plays when you press the RESET key (quantum.c) AG_NORM_SONG // plays when you press AG_NORM (quantum.c) AG_SWAP_SONG // plays when you press AG_SWAP (quantum.c) +CG_NORM_SONG // plays when you press CG_NORM (quantum.c) +CG_SWAP_SONG // plays when you press CG_SWAP (quantum.c) MUSIC_ON_SONG // plays when music mode is activated (process_music.c) MUSIC_OFF_SONG // plays when music mode is deactivated (process_music.c) CHROMATIC_SONG // plays when the chromatic music mode is selected (process_music.c) diff --git a/docs/feature_bootmagic.md b/docs/feature_bootmagic.md index 225189ccb7..fc37a3302b 100644 --- a/docs/feature_bootmagic.md +++ b/docs/feature_bootmagic.md @@ -64,8 +64,11 @@ Hold down the Bootmagic key (Space by default) and the desired hotkey while plug |`MAGIC_NO_GUI` | |Disable the GUI keys (useful when gaming) | |`MAGIC_UNNO_GUI` | |Enable the GUI keys | |`MAGIC_SWAP_ALT_GUI` |`AG_SWAP`|Swap Alt and GUI on both sides (for macOS)| -|`MAGIC_UNSWAP_ALT_GUI` |`AG_NORM`|Unswap Left Alt and Left GUI | -|`MAGIC_TOGGLE_ALT_GUI` |`AG_TOGG`|Toggle Left Alt and GUI swap | +|`MAGIC_UNSWAP_ALT_GUI` |`AG_NORM`|Unswap Alt and GUI | +|`MAGIC_TOGGLE_ALT_GUI` |`AG_TOGG`|Toggle Alt and GUI swap | +|`MAGIC_SWAP_CTL_GUI` |`CG_SWAP`|Swap Ctrl and GUI on both sides (for macOS)| +|`MAGIC_UNSWAP_CTL_GUI` |`CG_NORM`|Unswap Ctrl and GUI | +|`MAGIC_TOGGLE_CTL_GUI` |`CG_TOGG`|Toggle Ctrl and GUI swap | |`MAGIC_SWAP_BACKSLASH_BACKSPACE` | |Swap `\` and Backspace | |`MAGIC_UNSWAP_BACKSLASH_BACKSPACE`| |Unswap `\` and Backspace | |`MAGIC_SWAP_CONTROL_CAPSLOCK` | |Swap Left Control and Caps Lock | @@ -76,6 +79,10 @@ Hold down the Bootmagic key (Space by default) and the desired hotkey while plug |`MAGIC_UNSWAP_LALT_LGUI` | |Unswap Left Alt and Left GUI | |`MAGIC_SWAP_RALT_RGUI` | |Swap Right Alt and Right GUI | |`MAGIC_UNSWAP_RALT_RGUI` | |Unswap Right Alt and Right GUI | +|`MAGIC_SWAP_LCTL_LGUI` | |Swap Left Control and Left GUI | +|`MAGIC_UNSWAP_LCTL_LGUI` | |Unswap Left Control and Left GUI | +|`MAGIC_SWAP_RCTL_RGUI` | |Swap Right Control and Right GUI | +|`MAGIC_UNSWAP_RCTL_RGUI` | |Unswap Right Control and Right GUI | ## Configuration diff --git a/docs/keycodes.md b/docs/keycodes.md index bd4dd61a5b..e17fef6fd2 100644 --- a/docs/keycodes.md +++ b/docs/keycodes.md @@ -261,6 +261,8 @@ This is a reference only. Each group of keys links to the page documenting their |----------------------------------|---------|------------------------------------| |`MAGIC_SWAP_CONTROL_CAPSLOCK` | |Swap Caps Lock and Left Control | |`MAGIC_CAPSLOCK_TO_CONTROL` | |Treat Caps Lock as Control | +|`MAGIC_SWAP_LCTL_LGUI` | |Swap Left Control and GUI | +|`MAGIC_SWAP_RCTL_RGUI` | |Swap Right Control and GUI | |`MAGIC_SWAP_LALT_LGUI` | |Swap Left Alt and GUI | |`MAGIC_SWAP_RALT_RGUI` | |Swap Right Alt and GUI | |`MAGIC_NO_GUI` | |Disable the GUI key | @@ -268,8 +270,11 @@ This is a reference only. Each group of keys links to the page documenting their |`MAGIC_SWAP_BACKSLASH_BACKSPACE` | |Swap `\` and Backspace | |`MAGIC_HOST_NKRO` | |Force NKRO on | |`MAGIC_SWAP_ALT_GUI` |`AG_SWAP`|Swap Alt and GUI on both sides | +|`MAGIC_SWAP_CTL_GUI` |`CG_SWAP`|Swap Ctrl and GUI on both sides (for macOS)| |`MAGIC_UNSWAP_CONTROL_CAPSLOCK` | |Unswap Caps Lock and Left Control | |`MAGIC_UNCAPSLOCK_TO_CONTROL` | |Stop treating Caps Lock as Control | +|`MAGIC_UNSWAP_LCTL_LGUI` | |Unswap Left Control and GUI | +|`MAGIC_UNSWAP_RCTL_RGUI` | |Unswap Right Control and GUI | |`MAGIC_UNSWAP_LALT_LGUI` | |Unswap Left Alt and GUI | |`MAGIC_UNSWAP_RALT_RGUI` | |Unswap Right Alt and GUI | |`MAGIC_UNNO_GUI` | |Enable the GUI key | @@ -277,8 +282,10 @@ This is a reference only. Each group of keys links to the page documenting their |`MAGIC_UNSWAP_BACKSLASH_BACKSPACE`| |Unswap `\` and Backspace | |`MAGIC_UNHOST_NKRO` | |Force NKRO off | |`MAGIC_UNSWAP_ALT_GUI` |`AG_NORM`|Unswap Alt and GUI on both sides | -|`MAGIC_TOGGLE_ALT_GUI` |`AG_TOGG`|Toggle Alt and GUI swap on both sides| -|`MAGIC_TOGGLE_NKRO` | |Turn NKRO on or off | +|`MAGIC_UNSWAP_CTL_GUI` |`CG_NORM`|Unswap Ctrl and GUI on both sides | +|`MAGIC_TOGGLE_ALT_GUI` |`AG_TOGG`|Toggle Alt and GUI swap on both sides | +|`MAGIC_TOGGLE_CTL_GUI` |`CG_TOGG`|Toggle Ctrl and GUI swap on both sides | +|`MAGIC_TOGGLE_NKRO` | |Turn NKRO on or off | ## [Bluetooth](feature_bluetooth.md) diff --git a/quantum/keycode_config.c b/quantum/keycode_config.c index 0dc5105d21..73fe15861d 100644 --- a/quantum/keycode_config.c +++ b/quantum/keycode_config.c @@ -31,6 +31,12 @@ uint16_t keycode_config(uint16_t keycode) { if (keymap_config.swap_control_capslock) { return KC_CAPSLOCK; } + if (keymap_config.swap_lctl_lgui) { + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_LGUI; + } return KC_LCTL; case KC_LALT: if (keymap_config.swap_lalt_lgui) { @@ -44,10 +50,21 @@ uint16_t keycode_config(uint16_t keycode) { if (keymap_config.swap_lalt_lgui) { return KC_LALT; } + if (keymap_config.swap_lctl_lgui) { + return KC_LCTRL; + } if (keymap_config.no_gui) { return KC_NO; } return KC_LGUI; + case KC_RCTL: + if (keymap_config.swap_rctl_rgui) { + if (keymap_config.no_gui) { + return KC_NO; + } + return KC_RGUI; + } + return KC_RCTL; case KC_RALT: if (keymap_config.swap_ralt_rgui) { if (keymap_config.no_gui) { @@ -60,6 +77,9 @@ uint16_t keycode_config(uint16_t keycode) { if (keymap_config.swap_ralt_rgui) { return KC_RALT; } + if (keymap_config.swap_rctl_rgui) { + return KC_RCTL; + } if (keymap_config.no_gui) { return KC_NO; } @@ -108,6 +128,24 @@ uint8_t mod_config(uint8_t mod) { mod |= MOD_RGUI; } } + if (keymap_config.swap_lctl_lgui) { + if ((mod & MOD_RGUI) == MOD_LGUI) { + mod &= ~MOD_LGUI; + mod |= MOD_LCTL; + } else if ((mod & MOD_RCTL) == MOD_LCTL) { + mod &= ~MOD_LCTL; + mod |= MOD_LGUI; + } + } + if (keymap_config.swap_rctl_rgui) { + if ((mod & MOD_RGUI) == MOD_RGUI) { + mod &= ~MOD_RGUI; + mod |= MOD_RCTL; + } else if ((mod & MOD_RCTL) == MOD_RCTL) { + mod &= ~MOD_RCTL; + mod |= MOD_RGUI; + } + } if (keymap_config.no_gui) { mod &= ~MOD_LGUI; mod &= ~MOD_RGUI; diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index 022f4bd19b..7b01fcea45 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -36,6 +36,8 @@ typedef union { bool swap_grave_esc:1; bool swap_backslash_backspace:1; bool nkro:1; + bool swap_lctl_lgui:1; + bool swap_rctl_rgui:1; }; } keymap_config_t; diff --git a/quantum/quantum.c b/quantum/quantum.c index 77cbbb2e77..f489c90310 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -65,9 +65,17 @@ extern backlight_config_t backlight_config; #ifndef AG_SWAP_SONG #define AG_SWAP_SONG SONG(AG_SWAP_SOUND) #endif + #ifndef CG_NORM_SONG + #define CG_NORM_SONG SONG(AG_NORM_SOUND) + #endif + #ifndef CG_SWAP_SONG + #define CG_SWAP_SONG SONG(AG_SWAP_SOUND) + #endif float goodbye_song[][2] = GOODBYE_SONG; float ag_norm_song[][2] = AG_NORM_SONG; float ag_swap_song[][2] = AG_SWAP_SONG; + float cg_norm_song[][2] = CG_NORM_SONG; + float cg_swap_song[][2] = CG_SWAP_SONG; #ifdef DEFAULT_LAYER_SONGS float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; #endif @@ -563,7 +571,8 @@ bool process_record_quantum(keyrecord_t *record) { return false; #endif #endif - case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: + case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: + case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { @@ -585,6 +594,12 @@ bool process_record_quantum(keyrecord_t *record) { case MAGIC_SWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = true; break; + case MAGIC_SWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = true; + break; + case MAGIC_SWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = true; + break; case MAGIC_NO_GUI: keymap_config.no_gui = true; break; @@ -604,6 +619,13 @@ bool process_record_quantum(keyrecord_t *record) { PLAY_SONG(ag_swap_song); #endif break; + case MAGIC_SWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = true; + keymap_config.swap_rctl_rgui = true; + #ifdef AUDIO_ENABLE + PLAY_SONG(cg_swap_song); + #endif + break; case MAGIC_UNSWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = false; break; @@ -616,6 +638,12 @@ bool process_record_quantum(keyrecord_t *record) { case MAGIC_UNSWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = false; break; + case MAGIC_UNSWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = false; + break; + case MAGIC_UNSWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = false; + break; case MAGIC_UNNO_GUI: keymap_config.no_gui = false; break; @@ -635,6 +663,13 @@ bool process_record_quantum(keyrecord_t *record) { PLAY_SONG(ag_norm_song); #endif break; + case MAGIC_UNSWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = false; + keymap_config.swap_rctl_rgui = false; + #ifdef AUDIO_ENABLE + PLAY_SONG(cg_norm_song); + #endif + break; case MAGIC_TOGGLE_ALT_GUI: keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui; @@ -646,6 +681,17 @@ bool process_record_quantum(keyrecord_t *record) { } #endif break; + case MAGIC_TOGGLE_CTL_GUI: + keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; + keymap_config.swap_rctl_rgui = !keymap_config.swap_rctl_rgui; + #ifdef AUDIO_ENABLE + if (keymap_config.swap_rctl_rgui) { + PLAY_SONG(cg_swap_song); + } else { + PLAY_SONG(cg_norm_song); + } + #endif + break; case MAGIC_TOGGLE_NKRO: keymap_config.nkro = !keymap_config.nkro; break; diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index b5c6783e5e..bb16da4d50 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -492,6 +492,15 @@ enum quantum_keycodes { CMB_ON, CMB_OFF, CMB_TOG, + + MAGIC_SWAP_LCTL_LGUI, + MAGIC_SWAP_RCTL_RGUI, + MAGIC_UNSWAP_LCTL_LGUI, + MAGIC_UNSWAP_RCTL_RGUI, + MAGIC_SWAP_CTL_GUI, + MAGIC_UNSWAP_CTL_GUI, + MAGIC_TOGGLE_CTL_GUI, + // always leave at the end SAFE_RANGE }; @@ -639,6 +648,10 @@ enum quantum_keycodes { #define AG_NORM MAGIC_UNSWAP_ALT_GUI #define AG_TOGG MAGIC_TOGGLE_ALT_GUI +#define CG_SWAP MAGIC_SWAP_CTL_GUI +#define CG_NORM MAGIC_UNSWAP_CTL_GUI +#define CG_TOGG MAGIC_TOGGLE_CTL_GUI + // GOTO layer - 16 layers max // when: // ON_PRESS = 1 diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index d3884d9fa9..949615ecf9 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -286,6 +286,8 @@ static void print_eeconfig(void) print("keymap_config.raw: "); print_hex8(kc.raw); print("\n"); print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n"); print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n"); + print(".swap_lctl_lgui: "); print_dec(kc.swap_lctl_lgui); print("\n"); + print(".swap_rctl_rgui: "); print_dec(kc.swap_rctl_rgui); print("\n"); print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n"); print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n"); print(".no_gui: "); print_dec(kc.no_gui); print("\n"); diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 4f440abc9c..28f5d3ad5e 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -39,7 +39,8 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_DEBUG, 0); eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); default_layer_state = 0; - eeprom_update_byte(EECONFIG_KEYMAP, 0); + eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); + eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0); eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default @@ -127,12 +128,17 @@ void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DE * * FIXME: needs doc */ -uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } +uint16_t eeconfig_read_keymap(void) { + return ( eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8) ); +} /** \brief eeconfig update keymap * * FIXME: needs doc */ -void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); } +void eeconfig_update_keymap(uint16_t val) { + eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF); + eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, ( val >> 8 ) & 0xFF ); +} /** \brief eeconfig read backlight * diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 3100041b4e..0d5c6a82fc 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -45,7 +45,8 @@ along with this program. If not, see . #define EECONFIG_HAPTIC (uint32_t *)24 #define EECONFIG_RGB_MATRIX (uint32_t *)28 #define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32 - +// TODO: Combine these into a single word and single block of EEPROM +#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33 /* debug bit */ #define EECONFIG_DEBUG_ENABLE (1<<0) #define EECONFIG_DEBUG_MATRIX (1<<1) @@ -62,6 +63,7 @@ along with this program. If not, see . #define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1<<6) #define EECONFIG_KEYMAP_NKRO (1<<7) +#define EECONFIG_KEYMAP_LOWER_BYTE EECONFIG_KEYMAP bool eeconfig_is_enabled(void); bool eeconfig_is_disabled(void); @@ -81,8 +83,8 @@ void eeconfig_update_debug(uint8_t val); uint8_t eeconfig_read_default_layer(void); void eeconfig_update_default_layer(uint8_t val); -uint8_t eeconfig_read_keymap(void); -void eeconfig_update_keymap(uint8_t val); +uint16_t eeconfig_read_keymap(void); +void eeconfig_update_keymap(uint16_t val); #ifdef BACKLIGHT_ENABLE uint8_t eeconfig_read_backlight(void);