Skip to content

Commit

Permalink
Fix VKEY_{L,R}WIN key remapping by original key location.
Browse files Browse the repository at this point in the history
Currently, L/RWIN key remapping is not respecting the original key
location, so occasionally, RWIN is mapped to LWIN.

This CL remaps VKEY_L/RWIN keys based on the original key location
so that the result will be consistent.

BUG=1494936
TEST=Tryjob

Change-Id: Ie17e0246f6fa5019824926485bbfbc4ee0bf98f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4982612
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: David Padlipsky <dpad@google.com>
Cr-Commit-Position: refs/heads/main@{#1216569}
  • Loading branch information
Hidehiko Abe authored and Chromium LUCI CQ committed Oct 28, 2023
1 parent 95686a3 commit 5dd8d00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/ash/events/event_rewriter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ TEST_F(EventRewriterTest, TestRewriteCommandToControl) {
{ui::ET_KEY_PRESSED,
{ui::VKEY_RWIN, ui::DomCode::META_RIGHT,
ui::EF_COMMAND_DOWN | ui::EF_ALT_DOWN, ui::DomKey::META},
{ui::VKEY_LWIN, ui::DomCode::META_RIGHT,
{ui::VKEY_RWIN, ui::DomCode::META_RIGHT,
ui::EF_COMMAND_DOWN | ui::EF_ALT_DOWN, ui::DomKey::META}},
});
}
Expand Down Expand Up @@ -692,7 +692,7 @@ TEST_F(EventRewriterTest, TestRewriteExternalMetaKey) {
{ui::ET_KEY_PRESSED,
{ui::VKEY_RWIN, ui::DomCode::META_RIGHT,
ui::EF_COMMAND_DOWN | ui::EF_ALT_DOWN, ui::DomKey::META},
{ui::VKEY_LWIN, ui::DomCode::META_RIGHT,
{ui::VKEY_RWIN, ui::DomCode::META_RIGHT,
ui::EF_COMMAND_DOWN | ui::EF_ALT_DOWN, ui::DomKey::META}},
});

Expand Down
20 changes: 18 additions & 2 deletions ui/events/ash/event_rewriter_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ DomCode RelocateModifier(DomCode code, DomKeyLocation location) {
return code;
}

KeyboardCode RelocateKeyboardCode(KeyboardCode key_code,
DomKeyLocation location) {
// Note: currently, we're using SHIFT/CONTROL, instead of
// LSFHIT,RSHIFT/LCONTROL,RCONTROL, so {L,R}WIN are only candidate to be
// replaced.
switch (key_code) {
case VKEY_LWIN:
case VKEY_RWIN:
return location == DomKeyLocation::RIGHT ? VKEY_RWIN : VKEY_LWIN;
default:
break;
}
return key_code;
}

// Returns true if |mouse_event| was generated from a touchpad device.
bool IsFromTouchpadDevice(const MouseEvent& mouse_event) {
for (const InputDevice& touchpad :
Expand Down Expand Up @@ -1150,8 +1165,9 @@ bool EventRewriterAsh::RewriteModifierKeys(const KeyEvent& key_event,
if (remapped_key->remap_to == ui::mojom::ModifierKey::kCapsLock) {
characteristic_flag |= EF_CAPS_LOCK_ON;
}
state->code = RelocateModifier(
state->code, KeycodeConverter::DomCodeToLocation(incoming.code));
auto original_location = KeycodeConverter::DomCodeToLocation(incoming.code);
state->code = RelocateModifier(state->code, original_location);
state->key_code = RelocateKeyboardCode(state->key_code, original_location);
}

// Next, remap modifier bits.
Expand Down

0 comments on commit 5dd8d00

Please sign in to comment.