summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-11-01 09:42:25 +0100
committerStanislaw Halik <sthalik@misaki.pl>2014-11-01 09:42:25 +0100
commit730ad505abee026791b3d4b5b3e4551559f8216a (patch)
tree183f141ef8177cfe7168b643c4d390d0f1e3e52e /ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
parent46916ed93ba34558099590f33a5ed5ba6094353e (diff)
evdev: prevent hang on exit with no events
Diffstat (limited to 'ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp')
-rw-r--r--ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
index 3e63e07d..4ad3c624 100644
--- a/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
+++ b/ftnoir_tracker_libevdev/ftnoir_tracker_libevdev.cpp
@@ -38,7 +38,7 @@ void FTNoIR_Tracker::start_tracker(QFrame*)
std::string str = (QString("/dev/input/by-id/") + node_name).toStdString();
const char* filename = str.c_str();
- fd = open(filename, 0, O_RDWR);
+ fd = open(filename, O_NONBLOCK, O_RDWR);
if (fd == -1)
{
qDebug() << "error opening" << filename;
@@ -73,20 +73,25 @@ void FTNoIR_Tracker::run()
{
while (!should_quit)
{
- struct input_event ev;
- int status = libevdev_next_event(node, LIBEVDEV_READ_FLAG_NORMAL, &ev);
- if (status != LIBEVDEV_READ_STATUS_SUCCESS)
- continue;
- if (ev.type == EV_ABS || ev.type == EV_MSC)
+ msleep(1);
+
+ while (1)
{
- const int code = ev.code;
- for (int i = 0; i < 6; i++)
+ struct input_event ev;
+ int status = libevdev_next_event(node, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+ if (status != LIBEVDEV_READ_STATUS_SUCCESS)
+ break;
+ if (ev.type == EV_ABS)
{
- if (ot_libevdev_joystick_axes[i] == code)
+ const int code = ev.code;
+ for (int i = 0; i < 6; i++)
{
- QMutexLocker l(&mtx);
- values[i] = ev.value;
- break;
+ if (ot_libevdev_joystick_axes[i] == code)
+ {
+ QMutexLocker l(&mtx);
+ values[i] = ev.value;
+ break;
+ }
}
}
}