Commit a1f0e20a authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

x11, ime: Include Xkb 'group' field when injecting Gdk key events

After crrev.com/c/1789603, KeyEvent ctor for X11 assumes keyboard group
(which is used to determine which keyboard layout is in use), can be
extracted from XKeyEvent using XkbGroupForCoreState function [1], which
stored, along with other bit fields, in XKeyEvent::state field.

In order to be able support IME engines like IBus, GtkUi implementation
intercepts Gdk Events, translates them into XKeyEvents and inject them
into X11 Event Source. Such conversion was not including 'group' field,
which causes issues such as the one described in crbug.com/1021732.

[1] https://code.woboq.org/qt5/include/X11/extensions/XKB.h.html#_M/XkbGroupForCoreState

Bug: 1021732
Change-Id: Iec0246e4ccae2cb22a384e30b33b86b8b17588bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902426Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#713327}
parent 9c16d6eb
...@@ -16,6 +16,22 @@ ...@@ -16,6 +16,22 @@
namespace libgtkui { namespace libgtkui {
namespace {
// Xkb Events stores group attribute into XKeyEvent::state bit field while
// GdkEventKey objects has separate fields for that purpose, they are ::state
// and ::group respectively. So recompose them when build XKeyEvent from
// GdkEventKey here. This is similar to XkbBuildCoreState(), but takes takes a
// uint instead of assuming a 8-bit Xkb state.
//
// More details:
// https://code.woboq.org/qt5/include/X11/extensions/XKB.h.html#_M/XkbBuildCoreState
int BuildXkbStateFromGdkEvent(const GdkEventKey& keyev) {
return keyev.state | ((keyev.group & 0x3) << 13);
}
} // namespace
// static // static
GtkEventLoopX11* GtkEventLoopX11::GetInstance() { GtkEventLoopX11* GtkEventLoopX11::GetInstance() {
return base::Singleton<GtkEventLoopX11>::get(); return base::Singleton<GtkEventLoopX11>::get();
...@@ -69,7 +85,7 @@ void GtkEventLoopX11::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) { ...@@ -69,7 +85,7 @@ void GtkEventLoopX11::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) {
x_event.xkey.window = GDK_WINDOW_XID(gdk_event_key.window); x_event.xkey.window = GDK_WINDOW_XID(gdk_event_key.window);
x_event.xkey.root = DefaultRootWindow(x_event.xkey.display); x_event.xkey.root = DefaultRootWindow(x_event.xkey.display);
x_event.xkey.time = gdk_event_key.time; x_event.xkey.time = gdk_event_key.time;
x_event.xkey.state = gdk_event_key.state; x_event.xkey.state = BuildXkbStateFromGdkEvent(gdk_event_key);
x_event.xkey.keycode = gdk_event_key.hardware_keycode; x_event.xkey.keycode = gdk_event_key.hardware_keycode;
x_event.xkey.same_screen = true; x_event.xkey.same_screen = true;
......
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