rust_minifb
rust_minifb copied to clipboard
Support key modifiers on X11
I'm unfortunately not sure how this feature would work on other platforms since on this level I've only ever worked with X11 (and that through xcb not XLib).
My problem is that, for example, when the user holds Shift
then switches focus to the minifb window and then presses another key, like a
, only the a
press is registered and window.is_key_down(Key::LeftShift)
returns false, even though X11 reports the KeyPress event as having the Shift
modifier (for example the xev utility).
Do you think it would be possible to incorporate modifiers as Key::ModShift
or something similar without breaking other X11 code and other platforms? I'm not familiar with XLib so I can't immediately tell if it would. I'd be happy to spend the time on that myself if you think it would be possible to implement and include in minifb.
Edit: might be related to issue #203
So this code
window.get_keys().map(|keys| {
for t in keys {
match t {
Key::LeftShift => println!("holding left shift!"),
Key::RightShift => println!("holding right!"),
Key::W => println!("holding w!"),
_ => (),
}
}
});
Will not work for you?
I think this version is ok for most cases, and I've written my program that way. However I have a small testing utility (using minifb) for debugging a window manager and I kept running into "bugs" with focusing windows which turned out to be this particular edge case when the modifier key is already pressed before the minifb window gets focused. It may sound contrived, a somewhat realistic example would be: user is closing multiple windows in quick succession with a key chord like Ctrl+D where the user just holds the Ctrl key and presses repeatedly the D key, terminal emulators handle this fine because they detect modifiers directly from the X events, but with minifb user has to press the Ctrl key after the window has been focused.
I understand if the change is not worth it to you for this edge case, I was only hoping that the implementation in minifb would be easier than writing a new testing program. Thanks for the quick response!
I see. I will take a look at if it's easy to fix it, but as you say it's a bit of an edge case that in general doesn't cause that much issues so I think this is low priority right now.
Closing this as I don't think I will come around to do this. If I do I will reopen at that point.