Index: ui/events/ozone/evdev/event_factory_evdev.cc |
diff --git a/ui/events/ozone/evdev/event_factory_evdev.cc b/ui/events/ozone/evdev/event_factory_evdev.cc |
index 7dc288fc76554faced493aace085ca541eea1f16..139411c8bad78c2de79824ef71542e993c7fcafb 100644 |
--- a/ui/events/ozone/evdev/event_factory_evdev.cc |
+++ b/ui/events/ozone/evdev/event_factory_evdev.cc |
@@ -12,6 +12,7 @@ |
#include "base/task_runner.h" |
#include "base/thread_task_runner_handle.h" |
#include "base/threading/worker_pool.h" |
+#include "ui/events/device_data_manager.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" |
@@ -47,20 +48,21 @@ bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) { |
scoped_ptr<EventConverterEvdev> CreateConverter( |
int fd, |
const base::FilePath& path, |
- const EventDeviceInfo& devinfo, |
+ scoped_ptr<EventDeviceInfo> devinfo, |
const EventDispatchCallback& dispatch, |
EventModifiersEvdev* modifiers, |
CursorDelegateEvdev* cursor) { |
#if defined(USE_EVDEV_GESTURES) |
// Touchpad or mouse: use gestures library. |
// EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
- if (UseGesturesLibraryForDevice(devinfo)) { |
+ if (UseGesturesLibraryForDevice(*devinfo.get())) { |
spang
2014/09/29 23:54:35
.get() is unnecessary
dnicoara
2014/09/30 18:23:27
Done.
|
scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = make_scoped_ptr( |
new GestureInterpreterLibevdevCros(modifiers, cursor, dispatch)); |
scoped_ptr<EventReaderLibevdevCros> libevdev_reader = |
make_scoped_ptr(new EventReaderLibevdevCros( |
fd, |
path, |
+ devinfo.Pass(), |
gesture_interp.PassAs<EventReaderLibevdevCros::Delegate>())); |
return libevdev_reader.PassAs<EventConverterEvdev>(); |
} |
@@ -68,13 +70,13 @@ scoped_ptr<EventConverterEvdev> CreateConverter( |
// Touchscreen: use TouchEventConverterEvdev. |
scoped_ptr<EventConverterEvdev> converter; |
- if (devinfo.HasAbsXY()) |
+ if (devinfo->HasAbsXY()) |
return make_scoped_ptr<EventConverterEvdev>( |
- new TouchEventConverterEvdev(fd, path, devinfo, dispatch)); |
+ new TouchEventConverterEvdev(fd, path, devinfo.Pass(), dispatch)); |
// Everything else: use KeyEventConverterEvdev. |
- return make_scoped_ptr<EventConverterEvdev>( |
- new KeyEventConverterEvdev(fd, path, modifiers, dispatch)); |
+ return make_scoped_ptr<EventConverterEvdev>(new KeyEventConverterEvdev( |
+ fd, path, devinfo.Pass(), modifiers, dispatch)); |
} |
// Open an input device. Opening may put the calling thread to sleep, and |
@@ -87,6 +89,7 @@ void OpenInputDevice( |
const base::FilePath& path, |
EventModifiersEvdev* modifiers, |
CursorDelegateEvdev* cursor, |
+ int device_id, |
scoped_refptr<base::TaskRunner> reply_runner, |
const EventDispatchCallback& dispatch, |
base::Callback<void(scoped_ptr<EventConverterEvdev>)> reply_callback) { |
@@ -105,15 +108,15 @@ void OpenInputDevice( |
if (ioctl(fd, EVIOCSCLOCKID, &clk)) |
PLOG(ERROR) << "failed to set CLOCK_MONOTONIC"; |
- EventDeviceInfo devinfo; |
- if (!devinfo.Initialize(fd)) { |
+ scoped_ptr<EventDeviceInfo> devinfo(new EventDeviceInfo(device_id)); |
+ if (!devinfo->Initialize(fd)) { |
LOG(ERROR) << "failed to get device information for " << path.value(); |
close(fd); |
return; |
} |
scoped_ptr<EventConverterEvdev> converter = |
- CreateConverter(fd, path, devinfo, dispatch, modifiers, cursor); |
+ CreateConverter(fd, path, devinfo.Pass(), dispatch, modifiers, cursor); |
// Reply with the constructed converter. |
reply_runner->PostTask(FROM_HERE, |
@@ -131,10 +134,10 @@ void CloseInputDevice(const base::FilePath& path, |
} // namespace |
-EventFactoryEvdev::EventFactoryEvdev( |
- CursorDelegateEvdev* cursor, |
- DeviceManager* device_manager) |
- : device_manager_(device_manager), |
+EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
+ DeviceManager* device_manager) |
+ : last_allocated_device_id_(0), |
+ device_manager_(device_manager), |
cursor_(cursor), |
dispatch_callback_( |
base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
@@ -163,6 +166,8 @@ void EventFactoryEvdev::AttachInputDevice( |
// Add initialized device to map. |
converters_[path] = converter.release(); |
converters_[path]->Start(); |
+ |
+ NotifyHotplugEventObserver(converters_[path], true); |
} |
void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
@@ -181,6 +186,7 @@ void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
event.path(), |
&modifiers_, |
cursor_, |
+ ++last_allocated_device_id_, |
spang
2014/09/29 23:54:35
Make a function for this: NextDeviceId()
dnicoara
2014/09/30 18:23:27
Done.
|
ui_task_runner_, |
dispatch_callback_, |
base::Bind(&EventFactoryEvdev::AttachInputDevice, |
@@ -219,6 +225,8 @@ void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
// on UI since the polling happens on UI. |
converter->Stop(); |
+ NotifyHotplugEventObserver(converter.get(), false); |
+ |
// Dispatch task to close from the worker pool, since close may block. |
base::WorkerPool::PostTask( |
FROM_HERE, |
@@ -240,4 +248,35 @@ void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
} |
} |
+void EventFactoryEvdev::NotifyHotplugEventObserver( |
+ EventConverterEvdev* converter, bool created) { |
spang
2014/09/29 23:54:35
const EventConverterEvdev&
dnicoara
2014/09/30 18:23:27
Done.
|
+ EventDeviceInfo* device_info = converter->device_info(); |
+ // For now the only information propagated is related to touchscreens. Ignore |
+ // events for everything but touchscreens. |
+ if (!device_info->HasAbsXY() || !device_info->IsMappedToScreen()) |
spang
2014/09/29 23:54:35
Can you unify add/remove & just iterate the EventC
dnicoara
2014/09/30 18:23:27
Done.
|
+ return; |
+ |
+ DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
+ std::vector<TouchscreenDevice> touchscreens = |
+ DeviceDataManager::GetInstance()->touchscreen_devices(); |
+ if (created) { |
+ touchscreens.push_back(TouchscreenDevice( |
+ device_info->id(), |
+ gfx::Size(device_info->GetAbsMaximum(ABS_MT_POSITION_X) - |
+ device_info->GetAbsMinimum(ABS_MT_POSITION_X) + 1, |
+ device_info->GetAbsMaximum(ABS_MT_POSITION_Y) - |
+ device_info->GetAbsMinimum(ABS_MT_POSITION_Y) + 1), |
+ false)); |
+ } else { |
+ for (size_t i = 0; i < touchscreens.size(); ++i) { |
+ if (touchscreens[i].id == device_info->id()) { |
+ touchscreens.erase(touchscreens.begin() + i); |
+ break; |
+ } |
+ } |
+ } |
+ |
+ observer->OnTouchscreenDevicesUpdated(touchscreens); |
+} |
+ |
} // namespace ui |