Chromium Code Reviews| Index: ui/base/ozone/event_factory_ozone.cc |
| diff --git a/ui/base/ozone/event_factory_ozone.cc b/ui/base/ozone/event_factory_ozone.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..46d0cb9178e3c41ff5c76254e2a9af360d08411d |
| --- /dev/null |
| +++ b/ui/base/ozone/event_factory_ozone.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/base/ozone/event_factory_ozone.h" |
| + |
| +#include <fcntl.h> |
| +#include <linux/input.h> |
| +#include <poll.h> |
| +#include <stdio.h> |
| +#include <unistd.h> |
| + |
| +#include "base/message_pump_ozone.h" |
| +#include "ui/base/ozone/key_event_converter_ozone.h" |
| +#include "ui/base/ozone/touch_event_converter_ozone.h" |
| + |
| +namespace ui { |
| + |
| +EventFactoryOzone::EventFactoryOzone() {} |
| + |
| +EventFactoryOzone::~EventFactoryOzone() { |
| + for (unsigned i = 0; i < fd_controllers_.size(); i++) { |
| + fd_controllers_[i]->StopWatchingFileDescriptor(); |
| + } |
|
sadrul
2013/06/06 16:54:30
Looks like FileDescriptorWatcher dtor does this. S
rjkroege
2013/06/06 23:05:05
true. I didn't want to trust to chance that the Wa
|
| +} |
| + |
| +void EventFactoryOzone::CreateEvdevWatchers() { |
| + for (int id = 0; true; id++) { |
| + char path[32]; |
| + snprintf(path, arraysize(path), "/dev/input/event%d", id); |
| + int fd = open(path, O_RDONLY | O_NONBLOCK); |
| + if (fd < 0) |
| + break; |
| + size_t evtype = 0; |
| + COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough); |
| + if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) { |
| + DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path; |
| + close(fd); |
| + continue; |
| + } |
| + |
| + fprintf(stderr, "watching dev input %s\n", path); |
|
sadrul
2013/06/06 16:54:30
DLOG(INFO), or remove
rjkroege
2013/06/06 23:05:05
Done.
|
| + |
| + EventConverterOzone* watcher = NULL; |
| + // TODO(rjkroege) Add more device types. Support hot-plugging. |
| + if (evtype & (1 << EV_ABS)) |
| + watcher = new TouchEventConverterOzone(fd, id); |
| + else if (evtype & (1 << EV_KEY)) |
| + watcher = new KeyEventConverterOzone(); |
| + |
| + if (watcher) { |
| + base::MessagePumpLibevent::FileDescriptorWatcher* controller = |
| + new base::MessagePumpLibevent::FileDescriptorWatcher(); |
| + base::MessagePumpOzone::Current()->WatchFileDescriptor( |
| + fd, true, base::MessagePumpLibevent::WATCH_READ, controller, watcher); |
| + evdev_watchers_.push_back(watcher); |
| + fd_controllers_.push_back(controller); |
| + } else { |
| + close(fd); |
| + } |
| + } |
| +} |
| + |
| +} // namespace ui |