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

Adding/fixing Alt+Space handling #10799

Merged
5 commits merged into from
Aug 10, 2021
Merged

Adding/fixing Alt+Space handling #10799

5 commits merged into from
Aug 10, 2021

Conversation

FWest98
Copy link
Contributor

@FWest98 FWest98 commented Jul 26, 2021

Summary of the Pull Request

This PR implements/solves #7125. Concretely: two requests regarding alt+space were posted there:

  1. Disabling the alt+space menu when the keychord explicitly unbound - and forwarding the keystroke to the terminal
  2. Disabling the alt+space menu when the keychord is bound to an action

References

Not that I know

PR Checklist

  • Closes Add an option to disable the Windows menu on alt+space in Terminal #7125
  • CLA signed.
  • Tests added/passed
  • Documentation updated. N/A
  • Schema updated.
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan.
    The issue was marked Help-Wanted. I am happy to change the implementation to better fit your (planned) architecture.

Detailed Description of the Pull Request / Additional comments

While researching the solution, I noticed that the XAML system was always opening the system menu after Alt+Space, even when explicitly setting the event to be handled according to the documentation. The only solution I could find was to hook into the "XAML bypass" already in place for F7 KeyDown, and Alt KeyUp keystrokes. This bypass sends the keystroke to the AppHost immediately. This bypass method will "fall back" to the normal XAML routing when the keystroke is not handled.

The implemented behaviour is as follows:

  • Default: same as normal; system menu is working since the bypass does not handle the keystroke
  • Alt+Space explicitly unbound: bypass passes the keystroke to the terminal and marks it as handled
  • Alt+Space bound to command: bypass invokes the command and marks it as handled

Concretely, added a method to the KeyBindings and ActionMap interfaces to check whether a keychord is explicitly unbound. The implementation for _GetActionByKeyChordInternal already distinguishes between explicitly unbound and lack of binding, however this distinction is not carried over to the public methods. I decided not to change this existing method, to avoid breaking other stuff and to make the API more explicit.

Furthermore, there were some checks against Alt+Space further down in the code, preventing this keystroke from being entered in the terminal. Since the check for this keystroke is now done at a "higher" level, I thought I could safely remove these checks as otherwise the keystroke could never be sent to the terminal itself. Please correct me if I'm wrong.

Note that when alt+space is bound to an action that opens the command pallette (such as tab search), then a second press of the key combination does still open the system menu. This is because at that point, the "bypass" is cancelled (called "not a good implementation" in #4031). I don't think this can easily be solved for now, but this is a very minor bug/inconvenience.

Validation Steps Performed

Added tests for the new method. Performed manual checking:

  • Default configuration still opens system menu like normal
  • Binding alt+space to an action performs the action and does not show the system menu
  • Explicitly unbinding alt+space no longer shows the system menu and sends the keystroke to the terminal. I was unable to run the debug tap (it crashed my instance - same thing happening on preview and release builds) to check for sure, but behaviour was identical to native linux terminals.

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Area-User Interface Issues pertaining to the user interface of the Console or Terminal Issue-Task It's a feature request, but it doesn't really need a major design. Priority-3 A description (P3) Product-Terminal The new Windows Terminal. labels Jul 26, 2021
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks!

I assume it works fine, but mind testing this with PowerToys Run as well? I imagine they intercept it and handle it before we even get the chance to see it.

src/cascadia/TerminalControl/TermControl.cpp Outdated Show resolved Hide resolved
@FWest98
Copy link
Contributor Author

FWest98 commented Aug 1, 2021

@carlos-zamora Thanks for the feedback! I tested, and as suspected, PT Run makes use of some global event handler so the keystroke never arrives at the terminal.

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.

Code looks good to me - thanks for doing this!

@carlos-zamora
Copy link
Member

@msftbot merge this in 5 minutes

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Aug 10, 2021
@ghost
Copy link

ghost commented Aug 10, 2021

Hello @carlos-zamora!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Tue, 10 Aug 2021 19:52:44 GMT, which is in 5 minutes

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost ghost merged commit ebf41dd into microsoft:main Aug 10, 2021
@ghost
Copy link

ghost commented Aug 31, 2021

🎉Windows Terminal Preview v1.11.2421.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Area-User Interface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Priority-3 A description (P3) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to disable the Windows menu on alt+space in Terminal
3 participants