Navigation Menu

Skip to content

Commit

Permalink
Reworked XNextEventWithTimeout.
Browse files Browse the repository at this point in the history
New way of signaling autorepeats by the X11 servers broke Superkb.
Before we had a lot of KeyPresses and a single KeyRelease. Now we
have a lot of KeyPress/KeyRelease combinations. We must peek into
the next X event to see if it matches a KeyPress. If so, we must
ignore both.

We had to invert the logic for QLength() == 0 management and enclose
everything in a loop to continue if the events were swallowed.

This is to only emulate the old way before the rest of the codebase.

See: https://stackoverflow.com/questions/2100654

Signed-off-by: Octavio Alvarez <alvarezp@alvarezp.ods.org>
  • Loading branch information
alvarezp committed Sep 25, 2015
1 parent 4634700 commit 578ec0f
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions superkb.c
Expand Up @@ -99,29 +99,46 @@ XNextEventWithTimeout(Display * display, XEvent * event_return,

XFlush(display);

if (QLength(display) > 0) {
XNextEvent(display, event_return);
return 1;
}
while (1) {
if (QLength(display) <= 0) {

FD_ZERO(&fd);
FD_SET(XConnectionNumber(display), &fd);
FD_ZERO(&fd);
FD_SET(XConnectionNumber(display), &fd);

do {
r = select(FD_SETSIZE, &fd, NULL, NULL, to);
} while(r == -1 && errno == EINTR);
do {
r = select(FD_SETSIZE, &fd, NULL, NULL, to);
} while(r == -1 && errno == EINTR);

if (r == -1) {
/* Some error other than EINTR. */
return -errno;
}
if (r == -1) {
/* Some error other than EINTR. */
return -errno;
}

if (r == 0) {
/* Timeout */
return r;
}
if (r == 0) {
/* Timeout */
return r;
}

XNextEvent(display, event_return);
}

XNextEvent(display, event_return);

/* Swallow next event if this is a key-repeating event */
if (event_return->type == KeyRelease && XEventsQueued(display, QueuedAfterReading))
{
XEvent nev;
XPeekEvent(display, &nev);

if (nev.type == KeyPress && nev.xkey.time == event_return->xkey.time &&
nev.xkey.keycode == event_return->xkey.keycode)
{
/* Key wasn’t actually released. Swallow this event and the next one. */
XNextEvent(display, event_return);
continue;
}
}
break;
}
return 1;
}

Expand Down

0 comments on commit 578ec0f

Please sign in to comment.