Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| 25 } | |
| 26 | |
| 27 void EventFactoryOzone::CreateEvdevWatchers() { | |
| 28 for (int id = 0; true; id++) { | |
|
sky
2013/06/07 04:57:25
This is subtle enough that it's worth a comment.
rjkroege
2013/06/07 21:10:42
Done.
| |
| 29 char path[32]; | |
|
sky
2013/06/07 04:57:25
Can we use one of the stringprintf functions that
rjkroege
2013/06/07 21:10:42
Done.
| |
| 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 EventConverterOzone* watcher = NULL; | |
| 43 // TODO(rjkroege) Add more device types. Support hot-plugging. | |
| 44 if (evtype & (1 << EV_ABS)) | |
| 45 watcher = new TouchEventConverterOzone(fd, id); | |
| 46 else if (evtype & (1 << EV_KEY)) | |
| 47 watcher = new KeyEventConverterOzone(); | |
| 48 | |
| 49 if (watcher) { | |
| 50 base::MessagePumpLibevent::FileDescriptorWatcher* controller = | |
| 51 new base::MessagePumpLibevent::FileDescriptorWatcher(); | |
| 52 base::MessagePumpOzone::Current()->WatchFileDescriptor( | |
| 53 fd, true, base::MessagePumpLibevent::WATCH_READ, controller, watcher); | |
| 54 evdev_watchers_.push_back(watcher); | |
| 55 fd_controllers_.push_back(controller); | |
| 56 } else { | |
| 57 close(fd); | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 } // namespace ui | |
| OLD | NEW |