aboutsummaryrefslogtreecommitdiff
path: root/src/safe_x11/safex11.c
blob: e4f87d8df03258ffb0b59adc67d496dd20f17cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "safex11.h"
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xutil.h>

int select_next_event(Display *display, int x11_fd, XEvent *retval)
{
    fd_set in_fds;
    struct timeval tv;
    XEvent ev;
    /* check if there're some events on the queue first of all. */
    if(XPending(display) > 0)
        goto EVENT_QUEUED;

    FD_ZERO(&in_fds);
    FD_SET(x11_fd, &in_fds);

    /* one second */
    tv.tv_usec = 0;
    tv.tv_sec = 1;

    /* Wait for X Event or a Timer */
    if(select(x11_fd+1, &in_fds, 0, 0, &tv))
        goto EVENT_QUEUED;

    return 0;

EVENT_QUEUED:
        XNextEvent(display, &ev);
        *retval = ev;
        return 1;
}