Commit da116d0e authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Add property to identify internal or external deviecs

For all event devices, we'll use the device path to find out if it's
permanently attached. Expose this property on EventConverterEvdev and
use it when populating DeviceDataManager.

TEST=chrome on link_freon & rush_ryu
BUG=437539

Review URL: https://codereview.chromium.org/790153005

Cr-Commit-Position: refs/heads/master@{#308151}
parent 03eea596
......@@ -7,13 +7,15 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "ui/events/devices/input_device.h"
namespace ui {
EventConverterEvdev::EventConverterEvdev(int fd,
const base::FilePath& path,
int id)
: fd_(fd), path_(path), id_(id) {
int id,
InputDeviceType type)
: fd_(fd), path_(path), id_(id), type_(type) {
}
EventConverterEvdev::~EventConverterEvdev() {
......@@ -42,8 +44,4 @@ gfx::Size EventConverterEvdev::GetTouchscreenSize() const {
return gfx::Size();
}
bool EventConverterEvdev::IsInternal() const {
return false;
}
} // namespace ui
......@@ -8,6 +8,7 @@
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/ozone/evdev/event_dispatch_callback.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#include "ui/gfx/geometry/size.h"
......@@ -17,13 +18,18 @@ namespace ui {
class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
: public base::MessagePumpLibevent::Watcher {
public:
EventConverterEvdev(int fd, const base::FilePath& path, int id);
EventConverterEvdev(int fd,
const base::FilePath& path,
int id,
InputDeviceType type);
~EventConverterEvdev() override;
int id() const { return id_; }
const base::FilePath& path() const { return path_; }
InputDeviceType type() const { return type_; }
// Start reading events.
void Start();
......@@ -37,9 +43,6 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
// touchscreen device.
virtual gfx::Size GetTouchscreenSize() const;
// Returns true if the converter is used with an internal device.
virtual bool IsInternal() const;
protected:
// base::MessagePumpLibevent::Watcher:
void OnFileCanWriteWithoutBlocking(int fd) override;
......@@ -53,6 +56,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdev
// Uniquely identifies an event converter.
int id_;
// Type (internal or external).
InputDeviceType type_;
// Controller for watching the input fd.
base::MessagePumpLibevent::FileDescriptorWatcher controller_;
......
......@@ -18,12 +18,13 @@ EventConverterEvdevImpl::EventConverterEvdevImpl(
int fd,
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
MouseButtonMapEvdev* button_map,
CursorDelegateEvdev* cursor,
KeyboardEvdev* keyboard,
const EventDispatchCallback& callback)
: EventConverterEvdev(fd, path, id),
: EventConverterEvdev(fd, path, id, type),
x_offset_(0),
y_offset_(0),
cursor_(cursor),
......
......@@ -7,6 +7,7 @@
#include "base/files/file_path.h"
#include "base/message_loop/message_pump_libevent.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/event.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/event_converter_evdev.h"
......@@ -25,6 +26,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventConverterEvdevImpl
EventConverterEvdevImpl(int fd,
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
MouseButtonMapEvdev* button_map,
CursorDelegateEvdev* cursor,
......
......@@ -31,6 +31,7 @@ class MockEventConverterEvdevImpl : public EventConverterEvdevImpl {
: EventConverterEvdevImpl(fd,
base::FilePath(kTestDevicePath),
1,
INPUT_DEVICE_UNKNOWN,
modifiers,
button_map,
cursor,
......
......@@ -13,6 +13,8 @@
#include "base/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/device_util_linux.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/ozone/device/device_event.h"
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
......@@ -74,6 +76,7 @@ bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) {
scoped_ptr<EventConverterEvdev> CreateConverter(
const OpenInputDeviceParams& params,
int fd,
InputDeviceType type,
const EventDeviceInfo& devinfo) {
#if defined(USE_EVDEV_GESTURES)
// Touchpad or mouse: use gestures library.
......@@ -85,14 +88,14 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
params.keyboard, params.gesture_property_provider,
params.dispatch_callback));
return make_scoped_ptr(new EventReaderLibevdevCros(
fd, params.path, params.id, gesture_interp.Pass()));
fd, params.path, params.id, type, gesture_interp.Pass()));
}
#endif
// Touchscreen: use TouchEventConverterEvdev.
if (devinfo.HasMTAbsXY()) {
scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev(
fd, params.path, params.id, params.dispatch_callback));
fd, params.path, params.id, type, params.dispatch_callback));
converter->Initialize(devinfo);
return converter.Pass();
}
......@@ -100,13 +103,14 @@ scoped_ptr<EventConverterEvdev> CreateConverter(
// Graphics tablet
if (devinfo.HasAbsXY())
return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev(
fd, params.path, params.id, params.modifiers, params.cursor, devinfo,
params.dispatch_callback));
fd, params.path, params.id, type, params.modifiers, params.cursor,
devinfo, params.dispatch_callback));
// Everything else: use EventConverterEvdevImpl.
return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl(
fd, params.path, params.id, params.modifiers, params.button_map,
params.cursor, params.keyboard, params.dispatch_callback));
fd, params.path, params.id, type, params.modifiers,
params.button_map, params.cursor, params.keyboard,
params.dispatch_callback));
}
// Open an input device. Opening may put the calling thread to sleep, and
......@@ -142,8 +146,10 @@ void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params,
return;
}
InputDeviceType type = GetInputDeviceTypeFromPath(path);
scoped_ptr<EventConverterEvdev> converter =
CreateConverter(*params, fd, devinfo);
CreateConverter(*params, fd, type, devinfo);
// Reply with the constructed converter.
reply_runner->PostTask(FROM_HERE,
......@@ -318,13 +324,9 @@ void EventFactoryEvdev::NotifyHotplugEventObserver(
std::vector<TouchscreenDevice> touchscreens;
for (auto it = converters_.begin(); it != converters_.end(); ++it) {
if (it->second->HasTouchscreen()) {
InputDeviceType device_type = InputDeviceType::INPUT_DEVICE_EXTERNAL;
if (it->second->IsInternal())
device_type = InputDeviceType::INPUT_DEVICE_INTERNAL;
touchscreens.push_back(
TouchscreenDevice(it->second->id(),
device_type,
it->second->type(),
std::string(), /* Device name */
it->second->GetTouchscreenSize()));
}
......
......@@ -28,8 +28,9 @@ std::string FormatLog(const char* fmt, va_list args) {
EventReaderLibevdevCros::EventReaderLibevdevCros(int fd,
const base::FilePath& path,
int id,
InputDeviceType type,
scoped_ptr<Delegate> delegate)
: EventConverterEvdev(fd, path, id), delegate_(delegate.Pass()) {
: EventConverterEvdev(fd, path, id, type), delegate_(delegate.Pass()) {
memset(&evdev_, 0, sizeof(evdev_));
evdev_.log = OnLogMessage;
evdev_.log_udata = this;
......
......@@ -38,6 +38,7 @@ class EventReaderLibevdevCros : public EventConverterEvdev {
EventReaderLibevdevCros(int fd,
const base::FilePath& path,
int id,
InputDeviceType type,
scoped_ptr<Delegate> delegate);
~EventReaderLibevdevCros();
......
......@@ -16,11 +16,12 @@ TabletEventConverterEvdev::TabletEventConverterEvdev(
int fd,
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const EventDeviceInfo& info,
const EventDispatchCallback& callback)
: EventConverterEvdev(fd, path, id),
: EventConverterEvdev(fd, path, id, type),
cursor_(cursor),
modifiers_(modifiers),
callback_(callback),
......
......@@ -24,6 +24,7 @@ class EVENTS_OZONE_EVDEV_EXPORT TabletEventConverterEvdev
TabletEventConverterEvdev(int fd,
base::FilePath path,
int id,
InputDeviceType type,
EventModifiersEvdev* modifiers,
CursorDelegateEvdev* cursor,
const EventDeviceInfo& info,
......
......@@ -108,6 +108,7 @@ MockTabletEventConverterEvdev::MockTabletEventConverterEvdev(
fd,
path,
1,
INPUT_DEVICE_UNKNOWN,
modifiers,
cursor,
EventDeviceInfo(),
......
......@@ -74,13 +74,13 @@ TouchEventConverterEvdev::TouchEventConverterEvdev(
int fd,
base::FilePath path,
int id,
InputDeviceType type,
const EventDispatchCallback& callback)
: EventConverterEvdev(fd, path, id),
: EventConverterEvdev(fd, path, id, type),
callback_(callback),
syn_dropped_(false),
is_type_a_(false),
current_slot_(0),
is_internal_(GetInputDeviceTypeFromPath(path) == INPUT_DEVICE_INTERNAL) {
current_slot_(0) {
}
TouchEventConverterEvdev::~TouchEventConverterEvdev() {
......@@ -97,7 +97,7 @@ void TouchEventConverterEvdev::Initialize(const EventDeviceInfo& info) {
y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1;
// Apply --touch-calibration.
if (is_internal_) {
if (type() == INPUT_DEVICE_INTERNAL) {
TouchCalibration cal = {};
GetTouchCalibration(&cal);
x_min_tuxels_ += cal.bezel_left;
......@@ -144,10 +144,6 @@ gfx::Size TouchEventConverterEvdev::GetTouchscreenSize() const {
return native_size_;
}
bool TouchEventConverterEvdev::IsInternal() const {
return is_internal_;
}
void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
input_event inputs[MAX_FINGERS * 6 + 1];
ssize_t read_size = read(fd, inputs, sizeof(inputs));
......
......@@ -28,13 +28,13 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
TouchEventConverterEvdev(int fd,
base::FilePath path,
int id,
InputDeviceType type,
const EventDispatchCallback& dispatch);
~TouchEventConverterEvdev() override;
// EventConverterEvdev:
bool HasTouchscreen() const override;
gfx::Size GetTouchscreenSize() const override;
bool IsInternal() const override;
// Unsafe part of initialization.
virtual void Initialize(const EventDeviceInfo& info);
......@@ -103,8 +103,6 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
// In-progress touch points.
InProgressEvents events_[MAX_FINGERS];
bool is_internal_;
DISALLOW_COPY_AND_ASSIGN(TouchEventConverterEvdev);
};
......
......@@ -82,6 +82,7 @@ MockTouchEventConverterEvdev::MockTouchEventConverterEvdev(int fd,
fd,
path,
1,
INPUT_DEVICE_UNKNOWN,
base::Bind(&MockTouchEventConverterEvdev::DispatchCallback,
base::Unretained(this))) {
pressure_min_ = 30;
......
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