Skip to content

Commit

Permalink
exo: Remove modifier_flags_ from exo::Keyboard.
Browse files Browse the repository at this point in the history
Now modifiers are tracked in XkbTracker, so remove the cache from
exo::Keyboard.
Instead, it is cached in WaylandKeyboardDelegate for re-sending
purpose.

BUG=1123705
TEST=Ran exo_unittests locally.

Change-Id: I2800f507a030a938d2e0d58163e2e5005f1de299
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426663
Reviewed-by: Jun Mukai <mukai@chromium.org>
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810019}
  • Loading branch information
Hidehiko Abe authored and Commit Bot committed Sep 23, 2020
1 parent c8899cd commit 2285197
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
17 changes: 2 additions & 15 deletions components/exo/keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions components/exo/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ class Keyboard : public ui::EventHandler,
// details.
base::flat_map<ui::DomCode, ui::DomCode> pressed_keys_;

// Current set of modifier flags.
int modifier_flags_ = 0;

// Key state changes that are expected to be acknowledged.
using KeyStateChange = std::pair<ui::KeyEvent, base::TimeTicks>;
base::flat_map<uint32_t, KeyStateChange> pending_key_acks_;
Expand Down
8 changes: 8 additions & 0 deletions components/exo/keyboard_modifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <stdint.h>

#include <tuple>

namespace exo {

// Represents keyboard modifiers.
Expand All @@ -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_
11 changes: 8 additions & 3 deletions components/exo/wayland/wayland_keyboard_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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());
}

Expand Down
5 changes: 4 additions & 1 deletion components/exo/wayland/wayland_keyboard_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,6 +79,9 @@ class WaylandKeyboardDelegate : public WaylandInputDelegate,
// zwp_text_input.
std::unique_ptr<XkbTracker> xkb_tracker_;

// Tracks the latest modifiers.
KeyboardModifiers current_modifiers_{};

DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDelegate);
#endif
};
Expand Down

0 comments on commit 2285197

Please sign in to comment.