Skip to content

Fixed #521 - AltGr combinations not working - #1436

Merged
Dustin L. Howett (MSFT) (DHowett-MSFT) merged 1 commit into
microsoft:masterfrom
lhecker:fix-altgr-handling
Jun 27, 2019
Merged

Dustin L. Howett (MSFT) (DHowett-MSFT) merged 1 commit into
microsoft:masterfrom
lhecker:fix-altgr-handling

Conversation

@lhecker

@lhecker Leonard Hecker (lhecker) commented Jun 22, 2019 •

Copy link
Copy Markdown
Member

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 Leonard Hecker (lhecker) changed the title [WIP] Fixed #521 - AltGr combinations not working Fixed #521 - AltGr combinations not working Jun 23, 2019
@lhecker

Leonard Hecker (lhecker) commented Jun 23, 2019 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

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

// - 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think Mike Griese (@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
Copy Markdown
Contributor

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.

Comment thread src/terminal/input/terminalInput.cpp 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

Leonard Hecker (lhecker) commented Jun 25, 2019 •

Copy link
Copy Markdown
Member Author

Michael Niksa (@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
Copy Markdown

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

Matthieu S. (utybo) commented Jun 27, 2019 •

Copy link
Copy Markdown

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
Copy Markdown

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

@miniksa

Copy link
Copy Markdown
Contributor

Michael Niksa (@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 Mike Griese (@zadjii-msft) finds disagreeable later when he gets back.

@lhecker

Copy link
Copy Markdown
Member Author

Michael Niksa (@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
Copy Markdown
Contributor

Leonard Hecker (@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
Copy Markdown
Contributor

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.

@patriksvensson

Copy link
Copy Markdown

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

Dustin L. Howett (MSFT) (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)
Dustin L. Howett (MSFT) (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)
Wojciech Litewka (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.
Wojciech Litewka (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
Leonard Hecker (lhecker) restored the fix-altgr-handling branch September 19, 2019 16:54
@lhecker
Leonard Hecker (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