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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ozone/event_factory_ozone.h"
6
7 #include <fcntl.h>
8 #include <linux/input.h>
9 #include <poll.h>
10 #include <unistd.h>
11
12 #include "base/message_pump_ozone.h"
13 #include "base/stringprintf.h"
14 #include "ui/base/ozone/key_event_converter_ozone.h"
15 #include "ui/base/ozone/touch_event_converter_ozone.h"
16
17 namespace ui {
18
19 EventFactoryOzone::EventFactoryOzone() {}
20
21 EventFactoryOzone::~EventFactoryOzone() {
22 for (unsigned i = 0; i < fd_controllers_.size(); i++) {
23 fd_controllers_[i]->StopWatchingFileDescriptor();
24 }
25 }
26
27 void EventFactoryOzone::CreateEvdevWatchers() {
28 // The number of devices in the directory is unknown without reading
29 // the contents of the directory. Further, with hot-plugging, the entries
30 // might decrease during the execution of this loop. So exciting from the
31 // loop on the first failure of open below is both cheaper and more
32 // reliable.
33 for (int id = 0; true; id++) {
34 std::string path = base::StringPrintf("/dev/input/event%d", id);
35 int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
36 if (fd < 0)
37 break;
38 size_t evtype = 0;
39 COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough);
40 if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) {
41 DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path;
42 close(fd);
43 continue;
44 }
45
46 EventConverterOzone* watcher = NULL;
47 // TODO(rjkroege) Add more device types. Support hot-plugging.
48 if (evtype & (1 << EV_ABS))
49 watcher = new TouchEventConverterOzone(fd, id);
50 else if (evtype & (1 << EV_KEY))
51 watcher = new KeyEventConverterOzone();
52
53 if (watcher) {
54 base::MessagePumpLibevent::FileDescriptorWatcher* controller =
55 new base::MessagePumpLibevent::FileDescriptorWatcher();
56 base::MessagePumpOzone::Current()->WatchFileDescriptor(
57 fd, true, base::MessagePumpLibevent::WATCH_READ, controller, watcher);
58 evdev_watchers_.push_back(watcher);
59 fd_controllers_.push_back(controller);
60 } else {
61 close(fd);
62 }
63 }
64 }
65
66 } // namespace ui
OLDNEW
« 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