Skip to content
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

Fix: Handle AltGr on Windows #2944

Merged
merged 1 commit into from Jun 21, 2023
Merged

Fix: Handle AltGr on Windows #2944

merged 1 commit into from Jun 21, 2023

Conversation

hunger
Copy link
Member

@hunger hunger commented Jun 20, 2023

AltGr on windos sends a left control pressed followed by AltGr pressed on both winit and Qt. On AltGr release it sends left control released followed by AltGr released.

So unset left control on windows once AltGr is pressed to avoid treating special characters entered via AltGr key combos to be treated as control sequences -- leading to the input being ignored!

Fixes: #2933

@ogoffart
Copy link
Member

I searched a bit on the internet why this would happen.
Is it true that on windows (in other apps than slint) doing Ctrl+alt+something is the same as Altgr+something? And Altgr just maps to ctrl+alt. If that's the case, we also should support the ctrl+alt =Altgr

@hunger
Copy link
Member Author

hunger commented Jun 21, 2023

Yes, I originally read that, too, but the information seems outdated by now.

In Window::dispatch_event(...) I get the following values on Windows 11, both with winit and Qt:

Key value comment
Ctrl (left) \u{11}
Win \u{17}
Alt \u{12}
AltGr \u{11} + \u{13} That's via two separate key press/release events.
Ctrl (right) \u{16}

Ignoring that "stray" \u{11} seems like an acceptable solution, even thought that theoretically breaks Ctrl-AltGr-X key combos.

@ogoffart
Copy link
Member

So in a native Windows application, if you press "Ctrl + (left) Alt + Q", you don't get a "@" on your German keyboard ?

@hunger
Copy link
Member Author

hunger commented Jun 21, 2023

Oh! Ctrl-Alt-q indeed prints @, just as AltGr-q does. What a strange OS this is! No wonder Ctrl-Alt shortcuts are rarely used ;-)

@hunger
Copy link
Member Author

hunger commented Jun 21, 2023

New and improved! Now treats Alt-Ctrl as AltGr (by disabling the relevant flags in the modifier state).

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming you tested that it works as expected with all combination

internal/core/input.rs Outdated Show resolved Hide resolved
@hunger
Copy link
Member Author

hunger commented Jun 21, 2023

I did test Alt-CtrlL and AltGr. I did not test Alt-CtrlR :-( What kind of platform would even start to treat all those key combos the same?!

I am now wondering whether there are keyboards with a right Alt key.

@ogoffart
Copy link
Member

I am now wondering whether there are keyboards with a right Alt key.

I think there are, but its probably usually mapped to altgr

AltGr on windos sends a left control pressed followed by AltGr pressed
on both winit and Qt. On AltGr release it sends left control released
followed by AltGr released.

So unset left control on windows once AltGr is pressed to avoid treating
special characters entered via AltGr key combos to be treated as control
sequences -- leading to the input being ignored!

Also treat `Alt-Ctlr-X` as `AltGr-X` on windows.

Fixes: slint-ui#2933
@hunger
Copy link
Member Author

hunger commented Jun 21, 2023

OK, this is what I tested this time round (using a german keyboard layout):

key combo windows terminal Slint Gallery Text Edit
CtrlL-q ^Q
CtrlR-q ^Q
AltR-q q q
AltR-Shift-q Q Q
AltGr-q @ @
CtrlL-AltL-q @ @
CtrlL-AltL-Shift-q ^Q
CtrlR-AltL-q @ @
CtrlL-CtrlR-AltL-q @ @
CtrlL-CtrlR-AltL-AltGr-q @ @
CtrlR-AltGr @ @
CtrlL-AltGr @ @

I think that should cover the option space... AltGr is AltR according to Wikipedia, so we should not need to cover that in Windows -- and we do anyway by using alt().

@hunger hunger merged commit 501024a into slint-ui:master Jun 21, 2023
26 checks passed
@hunger hunger deleted the fix-2933 branch June 21, 2023 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot input characters that depend on Alt Gr key on Windows
2 participants