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

Unified Diff: ui/base/linux/event_factory_evdev.cc

Issue 13886018: Add a factory and defines for native Linux surfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get {base,ui,aura}_unittests working with native linux surface Created 7 years, 8 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
Index: ui/base/linux/event_factory_evdev.cc
diff --git a/ui/base/linux/event_factory_evdev.cc b/ui/base/linux/event_factory_evdev.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3dafd201d6bb5eca4bbad5289ca2b530f5d295d3
--- /dev/null
+++ b/ui/base/linux/event_factory_evdev.cc
@@ -0,0 +1,61 @@
+// 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/linux/event_factory_evdev.h"
+
+#include <fcntl.h>
+#include <linux/input.h>
+#include <poll.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "base/message_pump_linux.h"
+#include "ui/base/linux/touch_event_from_evdev_converter.h"
+
+namespace ui {
+
+EventFactoryEvdev::EventFactoryEvdev() {
+}
+
+EventFactoryEvdev::~EventFactoryEvdev() {
+ for (unsigned i = 0; i < fd_controllers_.size(); i++) {
+ fd_controllers_[i]->StopWatchingFileDescriptor();
+ }
+}
+
+void EventFactoryEvdev::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);
+
+ // TODO(rjkroege) Add more device types. Support hot-plugging.
+ if (evtype & (1 << EV_ABS)) {
+ TouchEventFromEvdevConverter* watcher =
+ new TouchEventFromEvdevConverter(fd, id);
+ base::MessagePumpLibevent::FileDescriptorWatcher* controller =
+ new base::MessagePumpLibevent::FileDescriptorWatcher();
+ base::MessagePumpLinux::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
+

Powered by Google App Engine
This is Rietveld 408576698