2

I want to catch hotkeys via XNextEvent. Unfortuantely this is blocking. Hence I want to call XPending before, which should be triggered by a select(). The problem is that I cant catch general keypresses from the Xserver. What is wrong here? If I do this with a window (like here) everything works well.

Window _root =  DefaultRootWindow(_display);

XSelectInput(_display, _root,
             ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
             ButtonPressMask | ButtonReleaseMask  | StructureNotifyMask
             );

XMapWindow(_display, _root);
XFlush(_display);

int     x11_fd = ConnectionNumber(_display);
fd_set in_fds;
int counter =0;
int timer =0;
XEvent ev;
int ret;
struct timeval tv;
while(1) {

    FD_ZERO(&in_fds);
    FD_SET(x11_fd, &in_fds);
    assert(FD_ISSET(x11_fd, &in_fds));
    tv.tv_sec = 1;
    tv.tv_usec = 0;

    // Wait for X Event or a Timer
    if (ret = select(x11_fd+1, &in_fds, 0, 0, &tv))
    {
        printf("%d Events Received!(%d)\n",ret,  counter++);
        // Handle XEvents and flush the input
        while(XPending(_display))
            XNextEvent(_display, &ev);
    }
    else
    {
        // Handle timer here
        printf("%d Timer Fired! (%d)\n", timer++, ret);
    }
}
Community
  • 1
  • 1
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103

0 Answers0