diff --git a/app.c b/app.c index ad4d44e..8edf68e 100644 --- a/app.c +++ b/app.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -202,21 +203,19 @@ int appRun(App *app) { LOGDBG("app: run: event loop"); int buttonDown = 0; unsigned int buttonDownMs = 0; - fd_set fds = {}; - int maxFd = fd; - if (maxFd < app->stopFd) maxFd = app->stopFd; - if (app->touch.app && maxFd < app->touch.fd) maxFd = app->touch.fd; + + struct pollfd fds[3] = {}; + fds[0].fd = fd; + fds[1].fd = app->stopFd; + fds[2].fd = app->touch.fd; + fds[0].events = fds[1].events = fds[2].events = POLLIN; + int fdcnt = app->touch.app ? 3 : 2; XFlush(app->dpy); while(1) { int hasEvent = 0; XEvent event = {}; - FD_ZERO(&fds); - FD_SET(fd, &fds); - FD_SET(app->stopFd, &fds); - if (app->touch.app) FD_SET(app->touch.fd, &fds); - // wait for next event if (XPending(app->dpy)) { XNextEvent(app->dpy, &event); @@ -224,20 +223,18 @@ int appRun(App *app) { } else if (buttonDown != 1) { // just wait for fds - select(maxFd + 1, &fds, NULL, NULL, NULL); + if (poll(fds, fdcnt, 0) < 0) + { LOGERR("app: run: poll error"); appStop(app, 1); } } else { // manually call select for the X-socket to use timeout - unsigned int dt = monotonicMs() - buttonDownMs; + int dt = monotonicMs() - buttonDownMs; if (dt < LONGPRESS_MS) { dt = LONGPRESS_MS - dt; - struct timeval t = {}; - t.tv_sec = dt/1000; - t.tv_usec = dt%1000*1000; - - LOGDBG("app: run: use select fd=%d, timeout=%ums, sec=%ld, usec=%ld", fd, dt, t.tv_sec, t.tv_usec); + LOGDBG("app: run: use poll with timeout %d ms", dt); XFlush(app->dpy); - select(maxFd + 1, &fds, NULL, NULL, &t); + if (poll(fds, fdcnt, dt) < 0) + { LOGERR("app: run: timed poll error"); appStop(app, 1); } } } diff --git a/main.c b/main.c index 2e96be3..f7f379e 100644 --- a/main.c +++ b/main.c @@ -14,7 +14,7 @@ #include "layout.am.inc.c" #include "layout.ru.inc.c" -#include +#include Layout layouts[] = { diff --git a/touch.c b/touch.c index fb28bba..a98600f 100644 --- a/touch.c +++ b/touch.c @@ -27,12 +27,7 @@ static int touch_field_codes[TOUCH_FIELDS] = int touchInit(Touch *touch, App *app, const char *dev) { if (!app || !dev) return 0; - LOGDBG("touch: init"); - touch->app = app; - touch->slot = 0; - touch->id = -1; - touch->pressed = 0; touch->fd = open(dev, O_RDONLY | O_NONBLOCK); if (touch->fd < 0) @@ -59,6 +54,10 @@ int touchInit(Touch *touch, App *app, const char *dev) { if (f[2] < f[0]) f[2] = f[0]; } + touch->app = app; + touch->slot = 0; + touch->id = -1; + touch->pressed = 0; return 1; }