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

Co-authored-by: Nimish Gåtam <nimishg@gmail.com>
This commit is contained in:
Nick Brassel 2023-07-08 10:15:51 +10:00 committed by GitHub
parent 9a19b80c0c
commit f41bc8ce20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 24 deletions

View File

@ -122,40 +122,36 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
*/ */
__attribute__((weak)) uint8_t mod_config(uint8_t mod) { __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 (keymap_config.swap_lalt_lgui) {
if ((mod & MOD_RGUI) == MOD_LGUI) { /** If both modifiers pressed or neither pressed, do nothing
mod &= ~MOD_LGUI; * Otherwise swap the values
mod |= MOD_LALT; * Note: The left mods are ANDed with the right-hand values to check
} else if ((mod & MOD_RALT) == MOD_LALT) { * if they were pressed with the right hand bit set
mod &= ~MOD_LALT; */
mod |= MOD_LGUI; if (((mod & MOD_RALT) == MOD_LALT) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
mod ^= (MOD_LALT | MOD_LGUI);
} }
} }
if (keymap_config.swap_ralt_rgui) { if (keymap_config.swap_ralt_rgui) {
if ((mod & MOD_RGUI) == MOD_RGUI) { if (((mod & MOD_RALT) == MOD_RALT) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
mod &= ~MOD_RGUI; /* lefthand values to preserve the right hand bit */
mod |= MOD_RALT; mod ^= (MOD_LALT | MOD_LGUI);
} else if ((mod & MOD_RALT) == MOD_RALT) {
mod &= ~MOD_RALT;
mod |= MOD_RGUI;
} }
} }
if (keymap_config.swap_lctl_lgui) { if (keymap_config.swap_lctl_lgui) {
if ((mod & MOD_RGUI) == MOD_LGUI) { /* left mods ANDed with right-hand values to check for right hand bit */
mod &= ~MOD_LGUI; if (((mod & MOD_RCTL) == MOD_LCTL) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
mod |= MOD_LCTL; mod ^= (MOD_LCTL | MOD_LGUI);
} else if ((mod & MOD_RCTL) == MOD_LCTL) {
mod &= ~MOD_LCTL;
mod |= MOD_LGUI;
} }
} }
if (keymap_config.swap_rctl_rgui) { if (keymap_config.swap_rctl_rgui) {
if ((mod & MOD_RGUI) == MOD_RGUI) { if (((mod & MOD_RCTL) == MOD_RCTL) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
mod &= ~MOD_RGUI; /* lefthand values to preserve the right hand bit */
mod |= MOD_RCTL; mod ^= (MOD_LCTL | MOD_LGUI);
} else if ((mod & MOD_RCTL) == MOD_RCTL) {
mod &= ~MOD_RCTL;
mod |= MOD_RGUI;
} }
} }
if (keymap_config.no_gui) { if (keymap_config.no_gui) {