-
Notifications
You must be signed in to change notification settings - Fork 29
Description
xcffib v1.7.1
I'm trying to reimplement the event loop that https://github.com/xkbmon/xkbmon does, but can't replicate the behaviour, specifically -- the filtering of events. I'm only interested in those that signal about the keyboard layout change, and xkbmon does it like this (the comments are added by me):
xcb_generic_event_t *event;
while ((event = xcb_wait_for_event(connection))) {
// filter 1: it selects the `pad0` field of `event`
// xcffib's event doesn't have that field
switch (event->pad0) {
// and thus can't be identified as a StateNotify type
// all events have type NewKeyboardNotifyEvent
case XCB_XKB_STATE_NOTIFY: {
xcb_xkb_state_notify_event_t *ne = (void *)event;
// filter 2: it bitwise-compares `changed` field to a constant
// good news: the constant is present under xcffib.xkb.StatePart.GroupState
// bad news: the `changed` field doesn't hold any value except 0, thus events can't be filtered by it
if (ne->changed & XCB_XKB_STATE_PART_GROUP_STATE) {
print_layout(connection);
}
break;
}
default:
break;
}
free(event);
}At the moment, the only reliable way to check if the layout has changed is to check the value of event.oldMaxKeyCode, which gets the same index as the result of xkb.GetState(xcffib.xkb.ID.UseCoreKbd).reply().lockedGroup (where xkb = conn(xcffib.xkb.key)). On one hand, it might be somewhat cheaper to use that value myself to get the layout by index than to rerun GetState(), on the other -- it still differs from the C implementation.
Btw, the code I come up with (with some help from, Lord forgive me, ChatGPT (except from the event filter, I found it out myself)) is such: https://pastebin.com/F2QQiUL0