Commit f931255c authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Fix X11KeyboardImpl::ChangeKeyMapping

This fixes a regression after [1].  The issue is that
GetKeySymsForUnicode() doesn't handle all characters.  This CL ports
the relevant part of XStringToKeysym() to match the behavior before the
regression.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2436787/5/remoting/host/linux/x11_keyboard_impl.cc#108

R=rkjnsn

Bug: 1144251
Change-Id: I91a3d42d0029e57c9e5a8cb8ee74b7bc76c00100
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518282Reviewed-by: default avatarErik Jensen <rkjnsn@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Erik Jensen <rkjnsn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823782}
parent 61ecbac2
......@@ -42,6 +42,16 @@ bool FindKeycodeForKeySym(x11::Connection* connection,
return false;
}
// This is ported from XStringToKeysym
// https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/2b7598221d87049d03e9a95fcb541c37c8728184/src/StrKeysym.c#L147-154
uint32_t UnicodeToKeysym(uint32_t u) {
if (u > 0x10ffff || u < 0x20 || (u > 0x7e && u < 0xa0))
return 0;
if (u < 0x100)
return u;
return u | 0x01000000;
}
} // namespace
namespace remoting {
......@@ -101,11 +111,11 @@ bool X11KeyboardImpl::FindKeycode(uint32_t code_point,
}
bool X11KeyboardImpl::ChangeKeyMapping(uint32_t keycode, uint32_t code_point) {
bool res = false;
if (code_point > 0) {
for (auto keysym : GetKeySymsForUnicode(code_point)) {
if (keysym > 0xffff)
continue;
if (!code_point)
return false;
auto keysym = UnicodeToKeysym(code_point);
if (!keysym)
return false;
connection_->ChangeKeyboardMapping({
.keycode_count = 1,
.first_keycode = static_cast<x11::KeyCode>(keycode),
......@@ -113,10 +123,7 @@ bool X11KeyboardImpl::ChangeKeyMapping(uint32_t keycode, uint32_t code_point) {
.keysyms = {static_cast<x11::KeySym>(keysym) /* lower-case */,
static_cast<x11::KeySym>(keysym) /* upper-case */},
});
res = true;
}
}
return res;
return true;
}
void X11KeyboardImpl::Flush() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment