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

During Alt+Numpad composition, stash keys in case we bail out #17774

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Aug 22, 2024

We were erroneously eating Alt followed by VK_ADD. This change makes sure we cache key presses and releases that happen once a numpad composition is active so that we can send them when you release Alt.

Right now, we only send them when you release Alt after composing Alt and VK_ADD (entering hex mode) and only if you haven't inserted an actual hex numpad code. This does mean that Alt VK_ADD 0 0 H I will result in an input of "+hi". That... seems like a small price to pay for Alt VK_ADD working again.

Closes #17762

We were erroneously eating Alt followed by VK_ADD. This change makes
sure we cache key presses and releases that happen once a numpad
composition is active so that we can send them when you release Alt.

Right now, we only send them when you release Alt after composing Alt
and VK_ADD (entering hex mode) and only if you haven't inserted an
actual hex numpad code. This does mean that `Alt VK_ADD 0 0 H I` will
result in an input of "+hi". That... seems like a small price to pay for
Alt VK_ADD working again.

Closes #17762
@DHowett DHowett requested a review from lhecker August 22, 2024 19:36
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Input Related to input processing (key presses, mouse, etc.) Product-Terminal The new Windows Terminal. labels Aug 22, 2024
s.encoding = AltNumpadEncoding::Unicode;
s.accumulator = 0;
s.active = true;
if (keyDown)
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to move keyDown into these places so we could stash the keyUp event in case composition was active.

This makes ALTdown KP+down KP+up ALTup work.

Copy link
Member

Choose a reason for hiding this comment

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

This may be easier to read if the if (keyDown) was outside the if/else chain instead of inside it.

}
// Send the alt keyup we are currently processing
h = h && _TrySendKeyEvent(vkey, scanCode, modifiers, keyDown);
// do not accumulate into the buffer
Copy link
Member Author

Choose a reason for hiding this comment

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

oh we should probably return h somewhere...

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I don't have time to read this, but I think this is fine with one sign-off

@@ -262,6 +262,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// The state can be active, while the accumulator is 0, if the user pressed Alt+Numpad0 which enabled
// the OEM encoding mode (= active), and then pressed Numpad0 again (= accumulator is still 0).
bool active = false;
til::small_vector<std::tuple<WORD, WORD, ::Microsoft::Terminal::Core::ControlKeyStates, bool>, 4> cachedKeyEvents;
Copy link
Member

Choose a reason for hiding this comment

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

I'd introduce a struct for this to make it more descriptive.

src/cascadia/TerminalControl/TermControl.cpp Show resolved Hide resolved
s.encoding = AltNumpadEncoding::Unicode;
s.accumulator = 0;
s.active = true;
if (keyDown)
Copy link
Member

Choose a reason for hiding this comment

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

This may be easier to read if the if (keyDown) was outside the if/else chain instead of inside it.

@DHowett DHowett enabled auto-merge (squash) August 23, 2024 01:25
@DHowett DHowett disabled auto-merge August 23, 2024 15:13
@DHowett DHowett merged commit e006f75 into main Aug 23, 2024
20 checks passed
@DHowett DHowett deleted the dev/duhowett/alt-numpad-kp-plus branch August 23, 2024 15:13
DHowett added a commit that referenced this pull request Aug 23, 2024
We were erroneously eating Alt followed by VK_ADD. This change makes
sure we cache key presses and releases that happen once a numpad
composition is active so that we can send them when you release Alt.

Right now, we only send them when you release Alt after composing Alt
and VK_ADD (entering hex mode) and only if you haven't inserted an
actual hex numpad code. This does mean that `Alt VK_ADD 0 0 H I` will
result in an input of "+hi". That... seems like a small price to pay for
Alt VK_ADD working again.

Closes #17762

(cherry picked from commit e006f75)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgSF50M
Service-Version: 1.21
DHowett pushed a commit that referenced this pull request Sep 24, 2024
This just adds a quick registry check for `EnableHexNumpad`.

Depends on #17774
Closes #17762 (again)

## Validation Steps Performed
* Alt + NumpadAdd + 221E doesn't do anything ✅
* Set the `EnableHexNumpad` registry key
* Restart
* Alt + NumpadAdd + 221E inserts ∞ ✅
DHowett pushed a commit that referenced this pull request Sep 24, 2024
This just adds a quick registry check for `EnableHexNumpad`.

Depends on #17774
Closes #17762 (again)

## Validation Steps Performed
* Alt + NumpadAdd + 221E doesn't do anything ✅
* Set the `EnableHexNumpad` registry key
* Restart
* Alt + NumpadAdd + 221E inserts ∞ ✅

(cherry picked from commit b520da2)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgTQsd8
Service-Version: 1.21
DHowett pushed a commit that referenced this pull request Sep 24, 2024
This just adds a quick registry check for `EnableHexNumpad`.

Depends on #17774
Closes #17762 (again)

## Validation Steps Performed
* Alt + NumpadAdd + 221E doesn't do anything ✅
* Set the `EnableHexNumpad` registry key
* Restart
* Alt + NumpadAdd + 221E inserts ∞ ✅

(cherry picked from commit b520da2)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgTQseA
Service-Version: 1.22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CANARY: ALT+NUMPAD ADD is Broken
3 participants