Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: ui/base/ozone/event_factory_ozone.cc

Issue 16466003: Event handling support for ozone. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase-ed for removal of DRT Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/ozone/event_factory_ozone.h ('k') | ui/base/ozone/events_ozone.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3189f1dd7dbf3e28353ddfb515c5c5ac75b97e02
--- /dev/null
+++ b/ui/base/ozone/event_factory_ozone.cc
@@ -0,0 +1,66 @@
+// 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 <unistd.h>
+
+#include "base/message_pump_ozone.h"
+#include "base/stringprintf.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();
+ }
+}
+
+void EventFactoryOzone::CreateEvdevWatchers() {
+ // The number of devices in the directory is unknown without reading
+ // the contents of the directory. Further, with hot-plugging, the entries
+ // might decrease during the execution of this loop. So exciting from the
+ // loop on the first failure of open below is both cheaper and more
+ // reliable.
+ for (int id = 0; true; id++) {
+ std::string path = base::StringPrintf("/dev/input/event%d", id);
+ int fd = open(path.c_str(), 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;
+ }
+
+ 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
« no previous file with comments | « ui/base/ozone/event_factory_ozone.h ('k') | ui/base/ozone/events_ozone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698