diff --git a/app.c b/app.c index 8edf68e..8e5b514 100644 --- a/app.c +++ b/app.c @@ -215,6 +215,7 @@ int appRun(App *app) { while(1) { int hasEvent = 0; XEvent event = {}; + fds[0].revents = fds[1].revents = fds[2].revents = 0; // wait for next event if (XPending(app->dpy)) { @@ -223,47 +224,23 @@ int appRun(App *app) { } else if (buttonDown != 1) { // just wait for fds - if (poll(fds, fdcnt, 0) < 0) - { LOGERR("app: run: poll error"); appStop(app, 1); } + poll(fds, fdcnt, -1); } else { // manually call select for the X-socket to use timeout int dt = monotonicMs() - buttonDownMs; if (dt < LONGPRESS_MS) { dt = LONGPRESS_MS - dt; LOGDBG("app: run: use poll with timeout %d ms", dt); - XFlush(app->dpy); - if (poll(fds, fdcnt, dt) < 0) - { LOGERR("app: run: timed poll error"); appStop(app, 1); } + poll(fds, fdcnt, dt); } } - if (!hasEvent && XPending(app->dpy)) { + if (!hasEvent && fds[0].revents && XPending(app->dpy)) { XNextEvent(app->dpy, &event); hasEvent = 1; } - if (app->touch.app) { - // handle direct touch events - int x, y, p; - while(touchGet(&app->touch, &x, &y, &p)) { - if (p && !buttonDown) { - LOGDBG("app: touch pressed: x=%d, y=%d", x, y); - buttonDown = 1; buttonDownMs = monotonicMs(); - keyboardMouseDown(&app->keyboard, x, y); - } else - if (!p && buttonDown) { - LOGDBG("app: touch released"); - buttonDown = 0; - keyboardMouseUp(&app->keyboard); - } else - if (p) { - LOGDBG("app: touch motion: x=%d, y=%d", x, y); - keyboardMouseMotion(&app->keyboard, x, y); - } - } - } - if (hasEvent) { // handle X11 events switch(event.type) { @@ -347,13 +324,39 @@ int appRun(App *app) { } } + if (app->touch.app && fds[2].revents) { + // handle direct touch events + int x, y, p; + while(touchGet(&app->touch, &x, &y, &p)) { + if (p && !buttonDown) { + LOGDBG("app: touch pressed: x=%d, y=%d", x, y); + buttonDown = 1; buttonDownMs = monotonicMs(); + keyboardMouseDown(&app->keyboard, x, y); + hasEvent = 1; + } else + if (!p && buttonDown) { + LOGDBG("app: touch released"); + buttonDown = 0; + keyboardMouseUp(&app->keyboard); + hasEvent = 1; + } else + if (p) { + LOGDBG("app: touch motion: x=%d, y=%d", x, y); + keyboardMouseMotion(&app->keyboard, x, y); + hasEvent = 1; + } + } + } + if (buttonDown == 1 && monotonicMs() - buttonDownMs >= LONGPRESS_MS) { LOGDBG("app: long press"); buttonDown = 2; keyboardMouseLongDown(&app->keyboard); + hasEvent = 1; } if (app->run != 1) break; + if (!hasEvent) continue; inputUpdateModifiers(&app->input); keyboardResize(&app->keyboard);