I am trying to set up a global hotkey on Linux.
I had initially used x11 (libX11.so
) however I had to do this from a thread. I tried it but the XPendingEvent
and XNextEvent
would eventually crash the app.
So I switched to xcb (libxcb.so.1
). There is no errors, I even check with xcb_request_check
however the event loop is not picking anything up. As soon as I start the loop, I get only one event which looks like this:
{
response_type: 0,
pad0: 10,
sequence: 2,
pad: [620, 2162688, 0, 0, 0, 0, 0],
full_sequence: 2
}
Here is my code, I actually do this in js-ctypes, but I cut down all the stuff to just show simple agnostic as possible code:
conn = xcb_connect(null, null);
keysyms = xcb_key_symbols_alloc(conn);
keycodesPtr = xcb_key_symbols_get_keycode(keysyms, XK_Space);
setup = xcb_get_setup(conn);
screens = xcb_setup_roots_iterator(setup);
screensCnt = screens.rem;
for (var i=0; i<screensCnt; i++) {
rez_grab = xcb_grab_key(conn, 1, screens.data.root, XCB_MOD_MASK_ANY, keycodesPtr[0], XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
rez_err = xcb_request_check(conn, rez_grab);
// rez_err is null
xcb_screen_next(&screens);
}
xcb_flush(conn);
// start event loop
while (true) {
ev = xcb_poll_for_event(conn);
console.log(ev);
if (ev != null) {
free(ev);
}
Sleep(50);
}
console.log(ev)
gives me what I posted above earlier, response_type
of 0
and then forever after that ev
is just null
.
Does anyone know what's up? rez_grab as a raw string is xcb_void_cookie_t(2)
Thanks much
Figured it out at long last!! Ah figured this one out! I was using
XCB_MOD_MASK_ANY
and this constant works on Debian but not on Ubuntu, which is what I was using to test. I switched that up to use num lock, caps lock etc and now it works! :)that was very very crazy i had no idea the
XCB_MOD_MASK_ANY
constant didnt work on Ubuntu -I also tried @n.m's code. On ubuntu it didnt work, but worked on debian -