1

hopefully, this is not a bug and just my misunderstanding of how Xinput is supposed to work.

I have been writing a game, and I am using Xlib to get input from the keyboard. The bizarre thing is that some KeyRelease events seem to get stuck in the XServer indefinitely until another event happens and pushes the event to the queue.

I can get this to occur if I mash 3 buttons at once, (Left, Up, and Right arrows) repeatedly. Ironically I have only ever been able to get it to happen with the Left arrow key. But I have reproduced it on different machines.

I have used XPending() to check the event queue, as well as XCheckMaskEvent() and both of them, seem to think the queue is empty. But sure enough, when I press another key such as right the KeyRelease event for left happens at the exact same time.

Is this a bug? Or expected functionality?

  • Side note, it might be useful to know that I am grabbing the keyboard on the root window

Here is the actual code

loop do
  Fiber.yield
  next if (event = display.check_mask_event(KeyPressMask | KeyReleaseMask)).nil?
  case event
  when KeyEvent
    kcode = event.lookup_keysym event.state & ShiftMask ? 1 : 0
    return {event.type, kcode}
  else
    next
  end
end
Jeff Davenport
  • 2,624
  • 2
  • 13
  • 19
  • Are threads involved in your game? Do you use X11 (possibly through e.g. OpenGL) from multiple threads? If so, you might be seeing https://gitlab.freedesktop.org/xorg/lib/libx11/issues/79 – Uli Schlachter Sep 26 '18 at 07:45
  • My game is only using a single thread. I am using X11 but I am not using OpenGL or any 3D library. I have tried compiling that fix here: https://gitlab.freedesktop.org/xorg/lib/libx11/merge_requests/1 and I am still having the same problem – Jeff Davenport Sep 26 '18 at 20:51
  • Okay, then I do not know and would guess that you call some other Xlib functions afterwards that read in some events. Got any code to look at? – Uli Schlachter Sep 27 '18 at 06:50
  • I added the code that is running into this problem, But it's written in Crystal using C bindings to Xlib. So you think it is my code that is the problem? What's odd to me is that display.pending is showing 0 no matter how many times it's called. But as soon as I push another button to add in another event, then the KeyRelease event fires off as well – Jeff Davenport Sep 27 '18 at 15:07
  • Hm, no idea. Sorry. – Uli Schlachter Sep 28 '18 at 07:31
  • google "Xlib keyrelease lost" may be useful – rogerdpack Oct 08 '18 at 20:16
  • @rogerdpack The thing is that the KeyRelease event is not lost. It shows up if another KeyPress event happens, it then finally gets pushed through. Didn't see anything useful by searching that though – Jeff Davenport Oct 09 '18 at 21:07

0 Answers0