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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/base/linux/event_factory_evdev.h"
6
7 #include <fcntl.h>
8 #include <linux/input.h>
9 #include <poll.h>
10 #include <stdio.h>
11 #include <unistd.h>
12
13 #include "base/message_pump_linux.h"
14 #include "ui/base/linux/touch_event_from_evdev_converter.h"
15
16 namespace ui {
17
18 EventFactoryEvdev::EventFactoryEvdev() {
19 }
20
21 EventFactoryEvdev::~EventFactoryEvdev() {
22 for (unsigned i = 0; i < fd_controllers_.size(); i++) {
23 fd_controllers_[i]->StopWatchingFileDescriptor();
24 }
25 }
26
27 void EventFactoryEvdev::CreateEvdevWatchers() {
28 for (int id = 0; true; id++) {
29 char path[32];
30 snprintf(path, arraysize(path), "/dev/input/event%d", id);
31 int fd = open(path, O_RDONLY | O_NONBLOCK);
32 if (fd < 0)
33 break;
34 size_t evtype = 0;
35 COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough);
36 if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) {
37 DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path;
38 close(fd);
39 continue;
40 }
41
42 fprintf(stderr, "watching dev input %s\n", path);
43
44 // TODO(rjkroege) Add more device types. Support hot-plugging.
45 if (evtype & (1 << EV_ABS)) {
46 TouchEventFromEvdevConverter* watcher =
47 new TouchEventFromEvdevConverter(fd, id);
48 base::MessagePumpLibevent::FileDescriptorWatcher* controller =
49 new base::MessagePumpLibevent::FileDescriptorWatcher();
50 base::MessagePumpLinux::Current()->WatchFileDescriptor(
51 fd, true, base::MessagePumpLibevent::WATCH_READ, controller, watcher);
52 evdev_watchers_.push_back(watcher);
53 fd_controllers_.push_back(controller);
54 } else {
55 close(fd);
56 }
57 }
58 }
59
60 } // namespace ui
61
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698