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

Fixed #521 - AltGr combinations not working #1436

Merged
merged 1 commit into from
Jun 27, 2019
Merged

Fixed #521 - AltGr combinations not working #1436

merged 1 commit into from
Jun 27, 2019

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jun 22, 2019

Summary of the Pull Request

Let's start fixing #521 and the currently broken state of AltGr combinations, as it heavily affects many non-US users of this project.

PR Checklist

Detailed Description of the Pull Request / Additional comments

I'm about 100% sure that this PR is not going to fix #521 by itself, but it's a start. 🙂
If others wan't to contribute to this PR, please feel free to do so. I'll gladly grant push permissions to my fork.

If you want to view the diff here on GitHub I recommend enabling "Hide whitespace changes" in the diff viewer.

Validation Steps Performed

This PR fixes all immediate/obvious issues in regards to AltGr for me in all types of shells I know.
I think it's fairly easy to see why it works, since I simply delegate the handling to WM_CHAR instead.

@lhecker lhecker changed the title [WIP] Fixed #521 - AltGr combinations not working Fixed #521 - AltGr combinations not working Jun 23, 2019
@lhecker
Copy link
Member Author

lhecker commented Jun 23, 2019

Alright... I've spent 5 hours on this thing today. Dammit. I hope it was worth it. 😄

This PR should now be far more robust than my basic solution in #521.
I've changed the Terminal class to actually propagate the left/right states of Alt/Ctrl separately down into the TerminalInput class. That way we can continue (or... technically start...) using keyEvent.IsAltGrPressed() in the HandleKey method.

This also has the nice side effect of this PR allowing others to continue pressing Ctrl+Alt without it being confused for an AltGr key press.
For instance if I press AltGr+Q on my german keyboard it will now insert a @ character, BUT if I press Alt+Ctrl+Q it will properly send an escape sequence instead, just like it used to.

I've also fixed the input tests I believe, which now...

  • Reflect the changes to AltGr being handled by WM_CHAR instead
  • Added the missing Ctrl+/ sequence check - without it the tests are failing on systems with non-US keyboards

@DHowett-MSFT
Copy link
Contributor

This is exciting. Thanks so much for looking at it! We’ll probably get to reviewing this after the weekend. 😄

src/terminal/adapter/ut_adapter/inputTest.cpp Outdated Show resolved Hide resolved
src/terminal/adapter/ut_adapter/inputTest.cpp Outdated Show resolved Hide resolved
// - a KeyModifiers value with flags set for each key that's pressed.
Settings::KeyModifiers TermControl::_GetPressedModifierKeys() const
// - The combined ControlKeyState flags as a bitfield.
DWORD TermControl::_GetPressedModifierKeys() const
Copy link
Member

Choose a reason for hiding this comment

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

I think @zadjii-msft was actively avoiding using a loose number of flags for representing this.

Even though Settings::KeyModifiers is no longer appropriate (given it treats left/right alt/ctrl the same), maybe it's appropriate to either expand it to have a preference (if folks want it and set both alts or both ctrls if the regular alt/ctrl is chosen) or appropriate to make a different more strongly typed flag structure for this.

Copy link
Member

Choose a reason for hiding this comment

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

To be fair, I don't mind it this way.

src/cascadia/TerminalControl/TermControl.cpp Show resolved Hide resolved
src/terminal/input/terminalInput.cpp Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Jun 25, 2019
@lhecker
Copy link
Member Author

lhecker commented Jun 25, 2019

@miniksa Thank you for your kind review! I've reverted most parts of the changeset and tried to be as minimalistic as possible this time. You'll find that the diff should be easier to read now.

I could optimize the code structure here and there to use e.g. switches (like I did originally), but I feel like I might not be following any plans you guys might already have in mind for this project. For now I'd like make this PR simple and leave any larger refactorings to you. 🙂

Except of course... Regarding the modifiers bitfield... I also don't think my current approach is acceptable either.
I'm slightly unsure what you mean with "expand it [the Settings::KeyModifiers structure] to have a preference" though.
What I'd like to suggest is to write a class that abstracts over the exact same bitfield used by the TerminalInput module, but provides a simplified API to query for Alt/Ctrl/AltGr states, similar to how KeyEvent does it already. That way this class would stay compatible with the DWORD based APIs. 🙂
Since the diff is relatively minimalistic such changes can be done at any point in time though IMO.
Either way is fine for me (i.e. me writing this class or not as part of this PR).

Edit: Ah you're already done reviewing. 😅

@yveslange
Copy link

Please, can you review this issue ? For most people in Sweden, Germany and Switzerland the terminal with WSL is unusable at the moment without this patch.

@utybo
Copy link

utybo commented Jun 27, 2019

Also relatively unusable for French users, given that the issue this PR fixes prevents using all sorts of keys. #{[|\^@]} all require pressing AltGr for French AZERTY keyboards.

@pekkah
Copy link

pekkah commented Jun 27, 2019

Same for Finnish users. Cannot navigate paths as cannot type path separators.

@miniksa
Copy link
Member

miniksa commented Jun 27, 2019

@miniksa Michael Niksa FTE Thank you for your kind review! I've reverted most parts of the changeset and tried to be as minimalistic as possible this time. You'll find that the diff should be easier to read now.

I could optimize the code structure here and there to use e.g. switches (like I did originally), but I feel like I might not be following any plans you guys might already have in mind for this project. For now I'd like make this PR simple and leave any larger refactorings to you. 🙂

Except of course... Regarding the modifiers bitfield... I also don't think my current approach is acceptable either.
I'm slightly unsure what you mean with "expand it [the Settings::KeyModifiers structure] to have a preference" though.
What I'd like to suggest is to write a class that abstracts over the exact same bitfield used by the TerminalInput module, but provides a simplified API to query for Alt/Ctrl/AltGr states, similar to how KeyEvent does it already. That way this class would stay compatible with the DWORD based APIs. 🙂
Since the diff is relatively minimalistic such changes can be done at any point in time though IMO.
Either way is fine for me (i.e. me writing this class or not as part of this PR).

Edit: Ah you're already done reviewing. 😅

If you could write a follow on issue or PR to make it into a nice class that does what you say... that would be ideal.

For everyone else, I'll try to get someone else to 2nd this and we can correct anything that @zadjii-msft finds disagreeable later when he gets back.

@lhecker
Copy link
Member Author

lhecker commented Jun 27, 2019

@miniksa Do you believe it might be possible to get this PR through until the weekend? Coincidentally I'm going to have some free time then and could work on that. But don't worry if it's not possible. We'll find the necessary time/solution either way, right? 🙂

@miniksa
Copy link
Member

miniksa commented Jun 27, 2019

@lhecker, I think we could merge it today if I can find someone with 15 minutes to read it. Let me keep trying. We have had meetings this afternoon.

Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

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

Thanks so much. This is great.

@DHowett-MSFT DHowett-MSFT merged commit 6775325 into microsoft:master Jun 27, 2019
@lhecker lhecker deleted the fix-altgr-handling branch June 28, 2019 16:56
@patriksvensson
Copy link

@lhecker Just noticed this was merged. Thank you so much for submitting a PR and fixing this issue!

DHowett-MSFT pushed a commit that referenced this pull request Jul 2, 2019
This commit changes how TerminalControl/TerminalCore handle key events to give it better knowledge about modifier states at the lower levels.

(cherry picked from commit 6775325)
DHowett-MSFT pushed a commit that referenced this pull request Jul 2, 2019
This commit changes how TerminalControl/TerminalCore handle key events to give it better knowledge about modifier states at the lower levels.

(cherry picked from commit 6775325)
mcpiroman pushed a commit to mcpiroman/terminal that referenced this pull request Jul 2, 2019
This commit changes how TerminalControl/TerminalCore handle key events to give it better knowledge about modifier states at the lower levels.
mcpiroman pushed a commit to mcpiroman/terminal that referenced this pull request Jul 23, 2019
This commit changes how TerminalControl/TerminalCore handle key events to give it better knowledge about modifier states at the lower levels.
@lhecker lhecker restored the fix-altgr-handling branch September 19, 2019 16:54
@lhecker lhecker deleted the fix-altgr-handling branch September 19, 2019 16:54
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.

AltGR SEQUENCES DO NOT WORK -- Can't type any AltGr combinations in Windows Terminal
7 participants