diff --git a/components/exo/keyboard.cc b/components/exo/keyboard.cc index 301992ae114c1c..5cd88fae26654d 100644 --- a/components/exo/keyboard.cc +++ b/components/exo/keyboard.cc @@ -33,14 +33,6 @@ namespace { // Delay until a key state change expected to be acknowledged is expired. const int kExpirationDelayForPendingKeyAcksMs = 1000; -// These modifiers reflect what clients are supposed to be aware of. -// I.e. EF_SCROLL_LOCK_ON is missing because clients are not supposed -// to be aware scroll lock. -const int kModifierMask = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | - ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN | - ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN | - ui::EF_NUM_LOCK_ON | ui::EF_CAPS_LOCK_ON; - // The accelerator keys reserved to be processed by chrome. const struct { ui::KeyboardCode keycode; @@ -286,11 +278,7 @@ void Keyboard::OnKeyEvent(ui::KeyEvent* event) { ConsumedByIme(focus_, event); // Always update modifiers. - int modifier_flags = event->flags() & kModifierMask; - if (modifier_flags != modifier_flags_) { - modifier_flags_ = modifier_flags; - delegate_->OnKeyboardModifiers(modifier_flags_); - } + delegate_->OnKeyboardModifiers(event->flags()); // TODO(yhanada): This is a quick fix for https://crbug.com/859071. Remove // ARC-specific code path once we can find a way to manage press/release @@ -427,9 +415,8 @@ void Keyboard::SetFocus(Surface* surface) { pending_key_acks_.clear(); } if (surface) { - modifier_flags_ = seat_->modifier_flags() & kModifierMask; pressed_keys_ = seat_->pressed_keys(); - delegate_->OnKeyboardModifiers(modifier_flags_); + delegate_->OnKeyboardModifiers(seat_->modifier_flags()); delegate_->OnKeyboardEnter(surface, pressed_keys_); focus_ = surface; focus_->AddSurfaceObserver(this); diff --git a/components/exo/keyboard.h b/components/exo/keyboard.h index 774b864a59f6aa..98bdf7345487fa 100644 --- a/components/exo/keyboard.h +++ b/components/exo/keyboard.h @@ -117,9 +117,6 @@ class Keyboard : public ui::EventHandler, // details. base::flat_map pressed_keys_; - // Current set of modifier flags. - int modifier_flags_ = 0; - // Key state changes that are expected to be acknowledged. using KeyStateChange = std::pair; base::flat_map pending_key_acks_; diff --git a/components/exo/keyboard_modifiers.h b/components/exo/keyboard_modifiers.h index c2b2b21a251f2e..a232988faf232a 100644 --- a/components/exo/keyboard_modifiers.h +++ b/components/exo/keyboard_modifiers.h @@ -7,6 +7,8 @@ #include +#include + namespace exo { // Represents keyboard modifiers. @@ -17,6 +19,12 @@ struct KeyboardModifiers { uint32_t group; }; +inline bool operator==(const KeyboardModifiers& lhs, + const KeyboardModifiers& rhs) { + return std::tie(lhs.depressed, lhs.locked, lhs.latched, lhs.group) == + std::tie(rhs.depressed, rhs.locked, rhs.latched, rhs.group); +} + } // namespace exo #endif // COMPONENTS_EXO_KEYBOARD_MODIFIERS_H_ diff --git a/components/exo/wayland/wayland_keyboard_delegate.cc b/components/exo/wayland/wayland_keyboard_delegate.cc index 569f1b81f7cd7c..e8d9d386263d40 100644 --- a/components/exo/wayland/wayland_keyboard_delegate.cc +++ b/components/exo/wayland/wayland_keyboard_delegate.cc @@ -90,6 +90,12 @@ uint32_t WaylandKeyboardDelegate::OnKeyboardKey(base::TimeTicks time_stamp, void WaylandKeyboardDelegate::OnKeyboardModifiers(int modifier_flags) { xkb_tracker_->UpdateKeyboardModifiers(modifier_flags); + + // Send the update only when they're different. + const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers(); + if (current_modifiers_ == modifiers) + return; + current_modifiers_ = modifiers; SendKeyboardModifiers(); } @@ -110,12 +116,11 @@ uint32_t WaylandKeyboardDelegate::DomCodeToKey(ui::DomCode code) const { } void WaylandKeyboardDelegate::SendKeyboardModifiers() { - const KeyboardModifiers modifiers = xkb_tracker_->GetModifiers(); wl_keyboard_send_modifiers( keyboard_resource_, serial_tracker_->GetNextSerial(SerialTracker::EventType::OTHER_EVENT), - modifiers.depressed, modifiers.locked, modifiers.latched, - modifiers.group); + current_modifiers_.depressed, current_modifiers_.locked, + current_modifiers_.latched, current_modifiers_.group); wl_client_flush(client()); } diff --git a/components/exo/wayland/wayland_keyboard_delegate.h b/components/exo/wayland/wayland_keyboard_delegate.h index 6d602021bb1e1c..98be676cd8692b 100644 --- a/components/exo/wayland/wayland_keyboard_delegate.h +++ b/components/exo/wayland/wayland_keyboard_delegate.h @@ -10,7 +10,7 @@ #include "base/time/time.h" #include "build/buildflag.h" #include "components/exo/keyboard_delegate.h" -#include "components/exo/keyboard_observer.h" +#include "components/exo/keyboard_modifiers.h" #include "components/exo/wayland/server_util.h" #include "components/exo/wayland/wayland_input_delegate.h" #include "ui/base/buildflags.h" @@ -79,6 +79,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate, // zwp_text_input. std::unique_ptr xkb_tracker_; + // Tracks the latest modifiers. + KeyboardModifiers current_modifiers_{}; + DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDelegate); #endif };