After getting a notification about this post just recently I thought I would add what my solution finally was when I came across the problem again.
I created my own event queue and polled that for events:
class event_queue{
public:
~event_queue(){
free(curr);
free(prev);
free(next);
}
xcb_generic_event_t *curr = nullptr, *prev = nullptr, *next = nullptr;
};
namespace {
event_queue internal_eventq;
}
xcb_generic_event_t *poll_event(xcb_connection_t *conn){
if(internal_eventq.curr){
free(internal_eventq.prev);
internal_eventq.prev = internal_eventq.curr;
}
internal_eventq.curr = internal_eventq.next;
internal_eventq.next = xcb_poll_event(conn);
return internal_eventq.curr;
}
So I can could check the previous and next events.
Next I changed my input function to use the new polling function and changed how I handle key presses:
// in same scope as 'poll_event'
void handle_events(xcb_connection_t *conn){
while(auto ev = poll_event(conn)){
switch(ev->response_type){
case /* xcb key press */:{
if(
(internal_eventq.next == /* xcb key release */) &&
(internal_eventq.next->keysym == ev->keysym) &&
(internal_eventq.next->time == ev->time)
){
free(internal_eventq.next);
internal_eventq.next = nullptr; // ignore release part of key repeat
return; // ignore key repeat
}
break;
}
default:
break;
}
}
}
Which was a bit of a hassle, but I imagine it is similar to how Xlib handles it's event queue behind the scenes.