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

[XProto] Handle XKB NewKeyboardNotify events

This fixes a regression where accelerators like Ctrl+T would not work
after changing the keyboard layout after [1].  XKB internally selects
and handles NewKeyboardNotify events, which get fired when changing
the keyboard layout.  This CL fixes the issue by manually selecting
and responding to these events.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2317767

R=sky
CC=nickdiego

Bug: 1125886
Change-Id: Ie8b84e1947da2deb527cd572f7a646b4f833b3ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402301
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805586}
parent 96b5f2c3
......@@ -75,6 +75,14 @@ void InitializeXkb(x11::Connection* connection) {
DVLOG(1) << "Could not set XKB auto repeat flag.";
}
}));
constexpr auto kXkbAllMapPartMask = static_cast<x11::Xkb::MapPart>(0xff);
xkb.SelectEvents({
.deviceSpec = static_cast<x11::Xkb::DeviceSpec>(x11::Xkb::Id::UseCoreKbd),
.affectWhich = x11::Xkb::EventType::NewKeyboardNotify,
.selectAll = x11::Xkb::EventType::NewKeyboardNotify,
.affectMap = kXkbAllMapPartMask,
});
}
x11::Time ExtractTimeFromXEvent(const x11::Event& xev) {
......
......@@ -22,6 +22,7 @@
#include "ui/gfx/x/randr.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_switches.h"
#include "ui/gfx/x/xkb.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gfx/x/xproto_internal.h"
#include "ui/gfx/x/xproto_types.h"
......@@ -488,9 +489,17 @@ void Connection::PreDispatchEvent(const Event& event) {
if (auto* mapping = event.As<MappingNotifyEvent>()) {
if (mapping->request == Mapping::Modifier ||
mapping->request == Mapping::Keyboard) {
setup_.min_keycode = mapping->first_keycode;
setup_.max_keycode = static_cast<x11::KeyCode>(
static_cast<int>(mapping->first_keycode) + mapping->count - 1);
ResetKeyboardState();
}
}
if (auto* notify = event.As<x11::Xkb::NewKeyboardNotifyEvent>()) {
setup_.min_keycode = notify->minKeyCode;
setup_.max_keycode = notify->maxKeyCode;
ResetKeyboardState();
}
// This is adapted from XRRUpdateConfiguration.
if (auto* configure = event.As<ConfigureNotifyEvent>()) {
......
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