Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keycodes for swapping and unswapping the Control and OS keys #6110

Merged
merged 17 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/feature_audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions docs/feature_bootmagic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Left GUI |
|`MAGIC_TOGGLE_ALT_GUI` |`AG_TOGG`|Toggle Alt and GUI swap |
|`MAGIC_SWAP_CTL_GUI` |`CG_SWAP`|Swap Alt and GUI on both sides (for macOS)|
|`MAGIC_UNSWAP_CTL_GUI` |`CG_NORM`|Unswap Alt and Left GUI |
|`MAGIC_TOGGLE_CTL_GUI` |`CG_TOGG`|Toggle Alt 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 |
Expand All @@ -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

Expand Down
11 changes: 9 additions & 2 deletions docs/keycodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,31 @@ 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 |
|`MAGIC_SWAP_GRAVE_ESC` | |Swap <code>&#96;</code> and Escape |
|`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 |
|`MAGIC_UNSWAP_GRAVE_ESC` | |Unswap <code>&#96;</code> and Escape|
|`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)

Expand Down
38 changes: 38 additions & 0 deletions quantum/keycode_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Copy link
Contributor

@yanfali yanfali Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels like these two lines should be a more descriptive macro, like CANCEL_AND_SET_MOD(MOD_LCTL, MOD_LGUI)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean for the whole function?
If so, the function is from tmk originally, and is used extensively, IIRC.

Otherwise, we don't actually have a function to modify mods in a variable. So, something would need to be added, to do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, just the inner block. It would be clearer what's going on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. unfortunately, no function exists for that right now. But it could be useful.

For now, though, I don't think this is a change that needs to be added here. It's something that would be better in a more general-ish overhaul.

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;
Expand Down
2 changes: 2 additions & 0 deletions quantum/keycode_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
48 changes: 47 additions & 1 deletion quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can assign these at the same time:
keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could lead to odd behavior. What if lctl_lgui is true and rctl_rgui is false. Is that intended?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same as ALT-GUI. But I suspect that no, it wasn't intended.

However, I don't feel that this is something that needs to be addressed here.

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;
Expand Down
13 changes: 13 additions & 0 deletions quantum/quantum_keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tmk_core/common/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 9 additions & 3 deletions tmk_core/common/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 5 additions & 3 deletions tmk_core/common/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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)
Expand All @@ -62,6 +63,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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);
Expand All @@ -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);
Expand Down