Commit 05e053f3 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[ozone/wayland] use KeyboardEvDev for keyboard handling

In WaylandKeyboard::Key's body, we deliberately duplicate some of the
logic in KeyboardEvdev::DispatchKey. The idea was to use the bits of
KeyboardEvDev needed for proper keyboard input handling.
It turns out that features like key repeat and specific cases involving
modifiers would need more duplication to get working.

Instead of continuing to duplicate stable and existing logic, this CL
adopts the use of KeyboardEvDev from WaylandKeyboard, fixing these
issues and being able to do some code clean ups (follow ups).

The CL also changes the KeyboardLayoutManager instantiation order in
OzonePlatformWayland::InitializeUI, so that it happens prior to
WaylandConnection instantiation.
Reason: once WaylandConnection creates WaylandKeyboard and (implicitly)
KeyboardEvDev, the later needs the KeyboardLayoutEngine properly set.

CL also reset modifiers upon ::Leave, for when alt+tab is supported to
change window focus (external window mode), where modifiers need to be
updated accordingly.

Last but not least, WaylandKeyboard::RepeatInfo sends delay and rate
information that is usefull for KeyboardEvdev. Thus, desired repeating
settings can be set. What is more, wayland documentation says if
rate is send as 0, then auto repeat should be turned off.

BUG=578890

Change-Id: I8ca392da7b10ba6c62f703e1e4b571c1e3d310a1
Reviewed-on: https://chromium-review.googlesource.com/822871
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523750}
parent d6d2e794
...@@ -61,6 +61,7 @@ source_set("wayland") { ...@@ -61,6 +61,7 @@ source_set("wayland") {
"//ui/display/manager", "//ui/display/manager",
"//ui/events", "//ui/events",
"//ui/events:dom_keycode_converter", "//ui/events:dom_keycode_converter",
"//ui/events/ozone:events_ozone_evdev",
"//ui/events/ozone:events_ozone_layout", "//ui/events/ozone:events_ozone_layout",
"//ui/events/platform", "//ui/events/platform",
"//ui/gfx", "//ui/gfx",
......
...@@ -75,10 +75,6 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -75,10 +75,6 @@ class OzonePlatformWayland : public OzonePlatform {
} }
void InitializeUI(const InitParams& args) override { void InitializeUI(const InitParams& args) override {
connection_.reset(new WaylandConnection);
if (!connection_->Initialize())
LOG(FATAL) << "Failed to initialize Wayland platform";
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
std::make_unique<WaylandXkbKeyboardLayoutEngine>( std::make_unique<WaylandXkbKeyboardLayoutEngine>(
...@@ -87,6 +83,9 @@ class OzonePlatformWayland : public OzonePlatform { ...@@ -87,6 +83,9 @@ class OzonePlatformWayland : public OzonePlatform {
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
std::make_unique<StubKeyboardLayoutEngine>()); std::make_unique<StubKeyboardLayoutEngine>());
#endif #endif
connection_.reset(new WaylandConnection);
if (!connection_->Initialize())
LOG(FATAL) << "Failed to initialize Wayland platform";
cursor_factory_.reset(new BitmapCursorFactoryOzone); cursor_factory_.reset(new BitmapCursorFactoryOzone);
overlay_manager_.reset(new StubOverlayManager); overlay_manager_.reset(new StubOverlayManager);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "ui/base/ui_features.h" #include "ui/base/ui_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/dom/keycode_converter.h" #include "ui/events/keycodes/dom/keycode_converter.h"
...@@ -23,15 +24,13 @@ ...@@ -23,15 +24,13 @@
namespace ui { namespace ui {
namespace {
const int kXkbKeycodeOffset = 8;
} // namespace
WaylandKeyboard::WaylandKeyboard(wl_keyboard* keyboard, WaylandKeyboard::WaylandKeyboard(wl_keyboard* keyboard,
const EventDispatchCallback& callback) const EventDispatchCallback& callback)
: obj_(keyboard), callback_(callback) { : obj_(keyboard),
callback_(callback),
evdev_keyboard_(&modifiers_,
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(),
callback_) {
static const wl_keyboard_listener listener = { static const wl_keyboard_listener listener = {
&WaylandKeyboard::Keymap, &WaylandKeyboard::Enter, &WaylandKeyboard::Keymap, &WaylandKeyboard::Enter,
&WaylandKeyboard::Leave, &WaylandKeyboard::Key, &WaylandKeyboard::Leave, &WaylandKeyboard::Key,
...@@ -79,6 +78,12 @@ void WaylandKeyboard::Leave(void* data, ...@@ -79,6 +78,12 @@ void WaylandKeyboard::Leave(void* data,
uint32_t serial, uint32_t serial,
wl_surface* surface) { wl_surface* surface) {
WaylandWindow::FromSurface(surface)->set_keyboard_focus(false); WaylandWindow::FromSurface(surface)->set_keyboard_focus(false);
WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
// Reset all modifiers once focus is lost. Otherwise, the modifiers may be
// left with old flags, which are no longer valid.
keyboard->modifiers_.ResetKeyboardModifiers();
} }
void WaylandKeyboard::Key(void* data, void WaylandKeyboard::Key(void* data,
...@@ -90,26 +95,9 @@ void WaylandKeyboard::Key(void* data, ...@@ -90,26 +95,9 @@ void WaylandKeyboard::Key(void* data,
WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data); WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
keyboard->connection_->set_serial(serial); keyboard->connection_->set_serial(serial);
DomCode dom_code = keyboard->evdev_keyboard_.OnKeyChange(
KeycodeConverter::NativeKeycodeToDomCode(key + kXkbKeycodeOffset); key, state == WL_KEYBOARD_KEY_STATE_PRESSED, false, EventTimeForNow(),
if (dom_code == ui::DomCode::NONE) keyboard->obj_.id());
return;
uint8_t flags = keyboard->modifiers_;
DomKey dom_key;
KeyboardCode key_code;
if (!KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()->Lookup(
dom_code, flags, &dom_key, &key_code))
return;
// TODO(tonikitoo): handle repeat here.
bool down = state == WL_KEYBOARD_KEY_STATE_PRESSED;
ui::KeyEvent event(
down ? ET_KEY_PRESSED : ET_KEY_RELEASED, key_code, dom_code,
keyboard->modifiers_, dom_key,
base::TimeTicks() + base::TimeDelta::FromMilliseconds(time));
event.set_source_device_id(keyboard->obj_.id());
keyboard->callback_.Run(&event);
} }
void WaylandKeyboard::Modifiers(void* data, void WaylandKeyboard::Modifiers(void* data,
...@@ -119,23 +107,20 @@ void WaylandKeyboard::Modifiers(void* data, ...@@ -119,23 +107,20 @@ void WaylandKeyboard::Modifiers(void* data,
uint32_t mods_latched, uint32_t mods_latched,
uint32_t mods_locked, uint32_t mods_locked,
uint32_t group) { uint32_t group) {
#if BUILDFLAG(USE_XKBCOMMON) // KeyboardEvDev handles modifiers.
WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
auto* engine = static_cast<WaylandXkbKeyboardLayoutEngine*>(
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine());
keyboard->modifiers_ =
engine->UpdateModifiers(mods_depressed, mods_latched, mods_locked, group);
#endif
} }
void WaylandKeyboard::RepeatInfo(void* data, void WaylandKeyboard::RepeatInfo(void* data,
wl_keyboard* obj, wl_keyboard* obj,
int32_t rate, int32_t rate,
int32_t delay) { int32_t delay) {
// TODO(tonikitoo): Implement proper repeat handling. WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data);
NOTIMPLEMENTED(); keyboard->evdev_keyboard_.SetAutoRepeatRate(
base::TimeDelta::FromMilliseconds(delay),
base::TimeDelta::FromMilliseconds(rate));
// Keyboard rate less than 0 means, wayland wants to disable autorepeat.
keyboard->evdev_keyboard_.SetAutoRepeatEnabled(rate > 0 ? true : false);
} }
} // namespace ui } // namespace ui
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_KEYBOARD_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_WAYLAND_KEYBOARD_H_
#define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_KEYBOARD_H_ #define UI_OZONE_PLATFORM_WAYLAND_WAYLAND_KEYBOARD_H_
#include "ui/events/event_modifiers.h"
#include "ui/events/ozone/evdev/event_dispatch_callback.h" #include "ui/events/ozone/evdev/event_dispatch_callback.h"
#include "ui/events/ozone/evdev/keyboard_evdev.h"
#include "ui/ozone/platform/wayland/wayland_object.h" #include "ui/ozone/platform/wayland/wayland_object.h"
namespace ui { namespace ui {
...@@ -21,7 +23,7 @@ class WaylandKeyboard { ...@@ -21,7 +23,7 @@ class WaylandKeyboard {
connection_ = connection; connection_ = connection;
} }
int modifiers() { return modifiers_; } int modifiers() { return modifiers_.GetModifierFlags(); }
private: private:
// wl_keyboard_listener // wl_keyboard_listener
...@@ -60,7 +62,9 @@ class WaylandKeyboard { ...@@ -60,7 +62,9 @@ class WaylandKeyboard {
WaylandConnection* connection_ = nullptr; WaylandConnection* connection_ = nullptr;
wl::Object<wl_keyboard> obj_; wl::Object<wl_keyboard> obj_;
EventDispatchCallback callback_; EventDispatchCallback callback_;
int modifiers_ = 0;
EventModifiers modifiers_;
KeyboardEvdev evdev_keyboard_;
}; };
} // namespace ui } // namespace ui
......
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