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

Fix Layer Mod mishandling of right-handed mods, a mixup of 5-bit vs. 8-bit mods representation. #19845

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ action_t action_for_keycode(uint16_t keycode) {
case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
mod = mod_config(QK_LAYER_MOD_GET_MODS(keycode));
action_layer = QK_LAYER_MOD_GET_LAYER(keycode);
action.code = ACTION_LAYER_MODS(action_layer, mod);
action.code = ACTION_LAYER_MODS(action_layer, (mod & 0x10) ? mod << 4 : mod);
break;
#endif
#ifndef NO_ACTION_TAPPING
Expand Down
63 changes: 63 additions & 0 deletions tests/basic/test_action_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "test_common.hpp"

using testing::_;
using testing::AnyNumber;
using testing::InSequence;

class ActionLayer : public TestFixture {};
Expand Down Expand Up @@ -399,3 +400,65 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) {
EXPECT_TRUE(layer_state_is(0));
VERIFY_AND_CLEAR(driver);
}

TEST_F(ActionLayer, LayerModWithKeypress) {
TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, LM(1, MOD_RALT)};
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};
set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}});

// Allow any number of reports with no keys or only KC_RALT.
// clang-format off
EXPECT_CALL(driver, send_keyboard_mock(AnyOf(
KeyboardReport(),
KeyboardReport(KC_RALT))))
.Times(AnyNumber());
// clang-format on
EXPECT_REPORT(driver, (KC_RALT, KC_B)).Times(1);

layer_key.press();
run_one_scan_loop();
EXPECT_TRUE(layer_state_is(1));
EXPECT_EQ(get_mods(), MOD_BIT(KC_RALT));

tap_key(regular_key);

layer_key.release();
run_one_scan_loop();
EXPECT_TRUE(layer_state_is(0));
EXPECT_EQ(get_mods(), 0);

VERIFY_AND_CLEAR(driver);
}

TEST_F(ActionLayer, LayerModHonorsModConfig) {
TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, LM(1, MOD_RALT)};
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};
set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}});

// Allow any number of reports with no keys or only KC_RALT.
// clang-format off
EXPECT_CALL(driver, send_keyboard_mock(AnyOf(
KeyboardReport(),
KeyboardReport(KC_RGUI))))
.Times(AnyNumber());
// clang-format on
EXPECT_REPORT(driver, (KC_RGUI, KC_B)).Times(1);

keymap_config.swap_ralt_rgui = true;

layer_key.press();
run_one_scan_loop();
EXPECT_TRUE(layer_state_is(1));
EXPECT_EQ(get_mods(), MOD_BIT(KC_RGUI));

tap_key(regular_key);

layer_key.release();
run_one_scan_loop();
EXPECT_TRUE(layer_state_is(0));
EXPECT_EQ(get_mods(), 0);

VERIFY_AND_CLEAR(driver);
}