| Index: ui/events/ozone/evdev/keyboard_evdev.cc
|
| diff --git a/ui/events/ozone/evdev/key_event_converter_evdev.cc b/ui/events/ozone/evdev/keyboard_evdev.cc
|
| similarity index 78%
|
| copy from ui/events/ozone/evdev/key_event_converter_evdev.cc
|
| copy to ui/events/ozone/evdev/keyboard_evdev.cc
|
| index 195b5142d453bc81decd88f884cca2250ee54371..829f303c7c2d0653fb1f300c93c2d64db2ea5609 100644
|
| --- a/ui/events/ozone/evdev/key_event_converter_evdev.cc
|
| +++ b/ui/events/ozone/evdev/keyboard_evdev.cc
|
| @@ -2,15 +2,10 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "ui/events/ozone/evdev/key_event_converter_evdev.h"
|
| +#include "ui/events/ozone/evdev/keyboard_evdev.h"
|
|
|
| -#include <errno.h>
|
| -#include <linux/input.h>
|
| -
|
| -#include "base/message_loop/message_loop.h"
|
| #include "ui/events/event.h"
|
| #include "ui/events/keycodes/dom4/keycode_converter.h"
|
| -#include "ui/events/keycodes/keyboard_codes.h"
|
| #include "ui/events/ozone/evdev/event_modifiers_evdev.h"
|
|
|
| namespace ui {
|
| @@ -19,7 +14,7 @@ namespace {
|
|
|
| const int kXkbKeycodeOffset = 8;
|
|
|
| -ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) {
|
| +ui::KeyboardCode KeyboardCodeFromEvdevKey(unsigned int code) {
|
| static const ui::KeyboardCode kLinuxBaseKeyMap[] = {
|
| ui::VKEY_UNKNOWN, // KEY_RESERVED
|
| ui::VKEY_ESCAPE, // KEY_ESC
|
| @@ -158,7 +153,7 @@ ui::KeyboardCode KeyboardCodeFromButton(unsigned int code) {
|
| return ui::VKEY_UNKNOWN;
|
| }
|
|
|
| -int ModifierFromButton(unsigned int code) {
|
| +int ModifierFromEvdevKey(unsigned int code) {
|
| switch (code) {
|
| case KEY_CAPSLOCK:
|
| return EVDEV_MODIFIER_CAPS_LOCK;
|
| @@ -185,71 +180,53 @@ int ModifierFromButton(unsigned int code) {
|
| }
|
| }
|
|
|
| -bool IsLockButton(unsigned int code) { return code == KEY_CAPSLOCK; }
|
| +bool IsModifierLockKeyFromEvdevKey(unsigned int code) {
|
| + return code == KEY_CAPSLOCK;
|
| +}
|
|
|
| } // namespace
|
|
|
| -KeyEventConverterEvdev::KeyEventConverterEvdev(
|
| - int fd,
|
| - base::FilePath path,
|
| - int id,
|
| - EventModifiersEvdev* modifiers,
|
| - const EventDispatchCallback& callback)
|
| - : EventConverterEvdev(fd, path, id),
|
| - callback_(callback),
|
| - modifiers_(modifiers) {
|
| - // TODO(spang): Initialize modifiers using EVIOCGKEY.
|
| +KeyboardEvdev::KeyboardEvdev(EventModifiersEvdev* modifiers,
|
| + const EventDispatchCallback& callback)
|
| + : callback_(callback), modifiers_(modifiers) {
|
| + memset(&key_state_, 0, sizeof(key_state_));
|
| }
|
|
|
| -KeyEventConverterEvdev::~KeyEventConverterEvdev() {
|
| - Stop();
|
| - close(fd_);
|
| +KeyboardEvdev::~KeyboardEvdev() {
|
| }
|
|
|
| -void KeyEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
|
| - input_event inputs[4];
|
| - ssize_t read_size = read(fd, inputs, sizeof(inputs));
|
| - if (read_size < 0) {
|
| - if (errno == EINTR || errno == EAGAIN)
|
| - return;
|
| - if (errno != ENODEV)
|
| - PLOG(ERROR) << "error reading device " << path_.value();
|
| - Stop();
|
| +void KeyboardEvdev::OnKeyChange(unsigned int key, bool down) {
|
| + if (key > KEY_MAX)
|
| return;
|
| - }
|
|
|
| - DCHECK_EQ(read_size % sizeof(*inputs), 0u);
|
| - ProcessEvents(inputs, read_size / sizeof(*inputs));
|
| -}
|
| + if (down != EvdevBitIsSet(key_state_, key)) {
|
| + // State transition: !(down) -> (down)
|
| + if (down)
|
| + EvdevSetBit(key_state_, key);
|
| + else
|
| + EvdevClearBit(key_state_, key);
|
|
|
| -void KeyEventConverterEvdev::ProcessEvents(const input_event* inputs,
|
| - int count) {
|
| - for (int i = 0; i < count; ++i) {
|
| - const input_event& input = inputs[i];
|
| - if (input.type == EV_KEY) {
|
| - ConvertKeyEvent(input.code, input.value);
|
| - } else if (input.type == EV_SYN) {
|
| - // TODO(sadrul): Handle this case appropriately.
|
| - }
|
| + UpdateModifier(key, down);
|
| }
|
| +
|
| + DispatchKey(key, down);
|
| }
|
|
|
| -void KeyEventConverterEvdev::ConvertKeyEvent(int key, int value) {
|
| - int down = (value != 0);
|
| - int repeat = (value == 2);
|
| - int modifier = ModifierFromButton(key);
|
| - ui::KeyboardCode code = KeyboardCodeFromButton(key);
|
| +void KeyboardEvdev::UpdateModifier(unsigned int key, bool down) {
|
| + int modifier = ModifierFromEvdevKey(key);
|
| + int locking = IsModifierLockKeyFromEvdevKey(key);
|
|
|
| - if (!repeat && (modifier != EVDEV_MODIFIER_NONE)) {
|
| - if (IsLockButton(key)) {
|
| - // Locking modifier keys: CapsLock.
|
| - modifiers_->UpdateModifierLock(modifier, down);
|
| - } else {
|
| - // Regular modifier keys: Shift, Ctrl, Alt, etc.
|
| - modifiers_->UpdateModifier(modifier, down);
|
| - }
|
| - }
|
| + if (modifier == EVDEV_MODIFIER_NONE)
|
| + return;
|
| +
|
| + if (locking)
|
| + modifiers_->UpdateModifierLock(modifier, down);
|
| + else
|
| + modifiers_->UpdateModifier(modifier, down);
|
| +}
|
|
|
| +void KeyboardEvdev::DispatchKey(unsigned int key, bool down) {
|
| + ui::KeyboardCode code = KeyboardCodeFromEvdevKey(key);
|
| int flags = modifiers_->GetModifierFlags();
|
|
|
| KeyEvent key_event(
|
|
|