Commit 23f5e81e authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

exo: Introduce KeyboardModifiers.

Preparation to move XkbTracker out from components/exo/wayland.
This CL now wraps the dependency to xkbcommon from
wayland_keyboard_delegate.cc

BUG=1123705
TEST=Built locally.

Change-Id: If732a97aff7ccf729f60ea17fc1b193f3244b275
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416153Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808727}
parent b5d9809a
...@@ -132,6 +132,7 @@ static_library("exo") { ...@@ -132,6 +132,7 @@ static_library("exo") {
"input_method_surface_manager.h", "input_method_surface_manager.h",
"keyboard.cc", "keyboard.cc",
"keyboard.h", "keyboard.h",
"keyboard_modifiers.h",
"notification.cc", "notification.cc",
"notification.h", "notification.h",
"notification_surface.cc", "notification_surface.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_
#define COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_
#include <stdint.h>
namespace exo {
// Represents keyboard modifiers.
struct KeyboardModifiers {
uint32_t depressed;
uint32_t locked;
uint32_t latched;
uint32_t group;
};
} // namespace exo
#endif // COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <wayland-server-protocol-core.h> #include <wayland-server-protocol-core.h>
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "components/exo/keyboard_modifiers.h"
#include "components/exo/wayland/serial_tracker.h" #include "components/exo/wayland/serial_tracker.h"
#include "components/exo/xkb_tracker.h" #include "components/exo/xkb_tracker.h"
#include "ui/events/keycodes/dom/dom_code.h" #include "ui/events/keycodes/dom/dom_code.h"
...@@ -109,13 +110,12 @@ uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const { ...@@ -109,13 +110,12 @@ uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const {
} }
void WaylandKeyboardDelegate::SendKeyboardModifiers() { void WaylandKeyboardDelegate::SendKeyboardModifiers() {
const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers();
wl_keyboard_send_modifiers( wl_keyboard_send_modifiers(
keyboard_resource_, keyboard_resource_,
serial_tracker_->GetNextSerial(SerialTracker::EventType::OTHER_EVENT), serial_tracker_->GetNextSerial(SerialTracker::EventType::OTHER_EVENT),
xkb_tracker_->GetSerializeMods(XKB_STATE_MODS_DEPRESSED), modifiers.depressed, modifiers.locked, modifiers.latched,
xkb_tracker_->GetSerializeMods(XKB_STATE_MODS_LOCKED), modifiers.group);
xkb_tracker_->GetSerializeMods(XKB_STATE_MODS_LATCHED),
xkb_tracker_->GetSerializeLayout(XKB_STATE_LAYOUT_EFFECTIVE));
wl_client_flush(client()); wl_client_flush(client());
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/exo/xkb_tracker.h" #include "components/exo/xkb_tracker.h"
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
#include "components/exo/keyboard_modifiers.h"
#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
#endif #endif
...@@ -50,12 +51,13 @@ std::unique_ptr<char, base::FreeDeleter> XkbTracker::GetKeymap() const { ...@@ -50,12 +51,13 @@ std::unique_ptr<char, base::FreeDeleter> XkbTracker::GetKeymap() const {
xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1)); xkb_keymap_get_as_string(xkb_keymap_.get(), XKB_KEYMAP_FORMAT_TEXT_V1));
} }
uint32_t XkbTracker::GetSerializeMods(xkb_state_component components) const { KeyboardModifiers XkbTracker::GetModifiers() const {
return xkb_state_serialize_mods(xkb_state_.get(), components); return {
} xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_DEPRESSED),
xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LOCKED),
uint32_t XkbTracker::GetSerializeLayout(xkb_state_component components) const { xkb_state_serialize_mods(xkb_state_.get(), XKB_STATE_MODS_LATCHED),
return xkb_state_serialize_layout(xkb_state_.get(), components); xkb_state_serialize_layout(xkb_state_.get(), XKB_STATE_LAYOUT_EFFECTIVE),
};
} }
void XkbTracker::UpdateKeyboardLayoutInternal(const xkb_rule_names* names) { void XkbTracker::UpdateKeyboardLayoutInternal(const xkb_rule_names* names) {
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
namespace exo { namespace exo {
struct KeyboardModifiers;
// Tracks the state of XKB. If Chrome is configured not to link against // Tracks the state of XKB. If Chrome is configured not to link against
// libxkbcommon this class is empty. // libxkbcommon this class is empty.
// TODO(hidehiko): Share the state between wl_keyboard and zwp_text_input. // TODO(hidehiko): Share the state between wl_keyboard and zwp_text_input.
...@@ -42,11 +44,8 @@ class XkbTracker { ...@@ -42,11 +44,8 @@ class XkbTracker {
// Returns the XKB keymap data. // Returns the XKB keymap data.
std::unique_ptr<char, base::FreeDeleter> GetKeymap() const; std::unique_ptr<char, base::FreeDeleter> GetKeymap() const;
// Returns the current modifier state of the given components. // Returns the current keyboard modifiers.
uint32_t GetSerializeMods(xkb_state_component components) const; KeyboardModifiers GetModifiers() const;
// Returns the current layout state of the given components.
uint32_t GetSerializeLayout(xkb_state_component components) const;
private: private:
void UpdateKeyboardLayoutInternal(const xkb_rule_names* names); void UpdateKeyboardLayoutInternal(const xkb_rule_names* names);
......
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