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

bootmagic mods covering the case when swapped mods are pressed at the same time #21320

Merged
merged 6 commits into from
Jul 7, 2023
Merged
Changes from all 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
44 changes: 20 additions & 24 deletions quantum/keycode_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,36 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
*/

__attribute__((weak)) uint8_t mod_config(uint8_t mod) {
/**
* Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods.
* More info about the mods can be seen in modifiers.h.
*/
if (keymap_config.swap_lalt_lgui) {
if ((mod & MOD_RGUI) == MOD_LGUI) {
mod &= ~MOD_LGUI;
mod |= MOD_LALT;
} else if ((mod & MOD_RALT) == MOD_LALT) {
mod &= ~MOD_LALT;
mod |= MOD_LGUI;
/** If both modifiers pressed or neither pressed, do nothing
* Otherwise swap the values
* Note: The left mods are ANDed with the right-hand values to check
* if they were pressed with the right hand bit set
*/
if (((mod & MOD_RALT) == MOD_LALT) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
mod ^= (MOD_LALT | MOD_LGUI);
}
}
if (keymap_config.swap_ralt_rgui) {
if ((mod & MOD_RGUI) == MOD_RGUI) {
mod &= ~MOD_RGUI;
mod |= MOD_RALT;
} else if ((mod & MOD_RALT) == MOD_RALT) {
mod &= ~MOD_RALT;
mod |= MOD_RGUI;
if (((mod & MOD_RALT) == MOD_RALT) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
/* lefthand values to preserve the right hand bit */
mod ^= (MOD_LALT | MOD_LGUI);
}
}
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;
/* left mods ANDed with right-hand values to check for right hand bit */
if (((mod & MOD_RCTL) == MOD_LCTL) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
mod ^= (MOD_LCTL | 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 (((mod & MOD_RCTL) == MOD_RCTL) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
/* lefthand values to preserve the right hand bit */
mod ^= (MOD_LCTL | MOD_LGUI);
}
}
if (keymap_config.no_gui) {
Expand Down