-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImGuiIO modifier key states incorrect under Linux/X11 (glfw) #99
Comments
Hi, thanks for the detailed report 👍 So, if I understand correctly, this behavior is specific to GLFW, right? If you would be using the SDL application instead (if it's possible for you to test that), it wouldn't happen? I'm thinking adding an extra bit of code that fills in also the modifier state if on a key down event for a modifier key could fix this, and make the behavior consistent between OSes and toolkits. @pezcode, since you did all of the ImGui event work and are familiar with the code, is this something you'd be able to look into? Thank you :) |
I just tried it and this behaviour is indeed only present when using Filling the modifier state also with the (modifier) key being pressed sounds good. Handling the key release probably becomes a bit trickier. For example, someone could be holding down both Shift keys. After releasing only one of them, the shift modifier should remain set. After also releasing the other shift key the shift modifier should explicitly not be set. Not to mention the concerns raised in the glfw issue (glfw/glfw#1630) regarding such workarounds:
That being said, it would already be a great improvement and at least make modifiers with mouse events usable in this setup. |
Useful reference for how ImGui handles this issue: ocornut/imgui#6034 (comment) They've been inferring the modifiers from the key state since 2015 onwards. Basically ignoring the modifiers provided by GLFW altogether and deriving it themselves from which modifier keys are in the pressed state. January last year they accidentally removed this workaround (ocornut/imgui@0755767) and later applied a fix that updated the modifiers based on the (current) key being pressed (ocornut/imgui@1ad8ad6). So if, for example, the left control key was pressed, it would include CTRL in the modifiers. With this approach they still faced the issue linked above, and are now back to deriving the modifiers manually from which keys are pressed. Interestingly they apply this workaround on all platforms, despite it only being necessary under Linux/X11. Applying the same workaround here in the ImGui integration becomes a tricky as querying the key state with |
When using the ImGui Integration under Linux/X11 the
ImGuiIO.KeyCtrl/Shift/Alt/Super
states aren't always correct. The modifiers in the key events contain the modifier state just before the event. When pressing the Shift key, for example, this results in the following behaviour:ImGuiIO.KeyShift = false
ImGuiIO.KeyShift = true
For common shortcuts, like
Ctrl+C
this doesn't cause too much trouble as the key events for the non-modifier key contain the right modifier state and will result in theImGuiIO.KeyCtrl
state being correct. But when combined with mouse events, the incorrect modifier state causes unexpected behaviour. Holding down a modifier key having no effect and the modifier state 'sticking around' after letting go of a modifier key.This is likely a regression introduced by switching to ImGui's event based input model. See glfw/glfw#1630 for more details and some possible workarounds (though, sadly, none of the workarounds seem ideal).
The text was updated successfully, but these errors were encountered: