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

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: 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
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 <stdio.h>
11 #include <unistd.h>
12
13 #include "base/message_pump_ozone.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 }
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
25 }
26
27 void EventFactoryOzone::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);
sadrul 2013/06/06 16:54:30 DLOG(INFO), or remove
rjkroege 2013/06/06 23:05:05 Done.
43
44 EventConverterOzone* watcher = NULL;
45 // TODO(rjkroege) Add more device types. Support hot-plugging.
46 if (evtype & (1 << EV_ABS))
47 watcher = new TouchEventConverterOzone(fd, id);
48 else if (evtype & (1 << EV_KEY))
49 watcher = new KeyEventConverterOzone();
50
51 if (watcher) {
52 base::MessagePumpLibevent::FileDescriptorWatcher* controller =
53 new base::MessagePumpLibevent::FileDescriptorWatcher();
54 base::MessagePumpOzone::Current()->WatchFileDescriptor(
55 fd, true, base::MessagePumpLibevent::WATCH_READ, controller, watcher);
56 evdev_watchers_.push_back(watcher);
57 fd_controllers_.push_back(controller);
58 } else {
59 close(fd);
60 }
61 }
62 }
63
64 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698