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

Active terminal does not get focus when window gets focus #522

Closed
patriksvensson opened this issue May 7, 2019 · 13 comments · Fixed by #3540
Closed

Active terminal does not get focus when window gets focus #522

patriksvensson opened this issue May 7, 2019 · 13 comments · Fixed by #3540
Labels
Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@patriksvensson
Copy link

patriksvensson commented May 7, 2019

Your Windows build number:
10.0.18362.86

What you're doing and what's happening:

  1. Open Windows Terminal
  2. Start PowerShell console.
  3. Make sure that the window have lost focus
  4. Click on the window to focus the application
  5. Start writing
  6. Input is not sent to the active console

What's wrong / what should be happening instead:
Input should be sent to the active console.

@zadjii-msft
Copy link
Member

Where specifically are you clicking to focus the window?

I'm seeing that clicking in the main part of the terminal window (with the text) works to send focus, but clicking anywhere in the tab row does not focus the terminal control

@zadjii-msft zadjii-msft added the Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. label May 7, 2019
@patriksvensson
Copy link
Author

@zadjii-msft Yes. I realized it only occurs when clicking the tab row. However, is this by design?

Btw, before I forget; I really love what you're doing with this project! The Windows Terminal is super fast!

@zadjii-msft
Copy link
Member

That's good to know! Makes fixing it a lot easier. It's definitely not by design, I just need to know what UI element we need to eat the focus from :P

Thanks for the kind words! We're really happy to be able to make this for the community (and ourselves :P)

@carlos-zamora
Copy link
Member

Found a few scenarios to lose focus (I suspect these to be basically the same problem):

  1. Clicking tabs:
    • Repro:
      • Open a tab w/ CTRL+T (focus should be ok for now)
      • Click on the tab you're using (focus should be lost)
    • Interestingly, if you then press the left arrow key, you switch to the tab on the left. BUT, if you press the left arrow key again, you are now moving around in the terminal control for the tab you just focused on.
  2. Clicking the drop-down menu:
    • Repro:
      • Click drop-down menu (focus is now on menu. Arrow keys let you explore that. Typing does not go to term control [bug?])
      • Click drop-down menu again to close it (focus is now stuck in tab control again. Same as extra bullet point in scenario 1)

@miniksa miniksa added Issue-Bug It either shouldn't be doing this or needs an investigation. Mass-Chaos and removed Needs-Repro We can't figure out how to make this happen. Please help find a simplified repro. labels May 14, 2019
@ghost ghost added the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@miniksa miniksa added Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Product-Terminal The new Windows Terminal. and removed Mass-Chaos labels May 17, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label May 17, 2019
@danielniccoli
Copy link

This also happens with

Windows build number: 10.0.19018.0
Windows Terminal version (if applicable): 0.6.2951.0

When the Terminal regains focus by either clicking the title bar, any tab or the app icon in the task bar, then only the window is focused, not the active terminal, preventing you to type text into it.

@zadjii-msft zadjii-msft added this to the Terminal v1.0 milestone Nov 11, 2019
@zadjii-msft
Copy link
Member

Hey wadda ya know, this might just be related to #1205, which I just started on this morning. I'll make sure to include these scenarios in my investigations.

zadjii-msft added a commit that referenced this issue Nov 11, 2019
  If I want to double up and also fix #522 (which I do), then I need to also
  * when a tab GetsFocus, send the focus instead to the Pane
  * When the border is clicked on, focus that pane's control

  And like a lot of cleanup, because this is horrifying
@ghost ghost added the In-PR This issue has a related PR label Nov 12, 2019
@khowling
Copy link

Moved to Windows terminal this week, loving it, but this is my biggest user-experience issue. I need to retrain my brain. Windows has trained me the safe way to focus any command window is by clicking the title-bar then the cursor will be in the correct place so i can type. I've typed so many characters into the ether this week

@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Nov 18, 2019
zadjii-msft added a commit that referenced this issue Nov 18, 2019
## Summary of the Pull Request

Unties the concept of "focused control" from "active control".

Previously, we were exclusively using the "Focused" state of `TermControl`s to determine which one was active. This was fraught with gotchas - if anything else became focused, then suddenly there was _no_ pane focused in the Tab. This happened especially frequently if the user clicked on a tab to focus the window. Furthermore, in experimental branches with more UI added to the Terminal (such as [dev/migrie/f/2046-command-palette](https://github.com/microsoft/terminal/tree/dev/migrie/f/2046-command-palette)), when these UIs were added to the Terminal, they'd take focus, which again meant that there was no focused pane.

This fixes these issue by having each Tab manually track which Pane is active in that tab. The Tab is now the arbiter of who in the tree is "active". Panes still track this state, for them to be able to MoveFocus appropriately. 

It also contains a related fix to prevent the tab separator from stealing focus from the TermControl. This required us to set the color of the un-focused Pane border to some color other that Transparent, so I went with the TabViewBackground. Panes now look like the following:

![image](https://user-images.githubusercontent.com/18356694/68697343-41ea2380-0544-11ea-8218-601b57fdd835.png)


## References

See also: #2046

## PR Checklist
* [x] Closes #1205
* [x] Closes #522
* [x] Closes #999
* [x] I work here
* [😢] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed

Tested manually opening panes, closing panes, clicking around panes, the whole dance.

---------------------------------------------------

* this is janky but is close for some reason?

* This is _almost_ right to solve #1205

  If I want to double up and also fix #522 (which I do), then I need to also
  * when a tab GetsFocus, send the focus instead to the Pane
  * When the border is clicked on, focus that pane's control

  And like a lot of cleanup, because this is horrifying

* hey this autorevoker is really nice

* Encapsulate Pane::pfnGotFocus

* Propogate the events back up on close

* Encapsulate Tab::pfnFocusChanged, and clean up TerminalPage a bit

* Mostly just code cleanup, commenting

* This works to hittest on the borders

  If the border is `Transparent`, then it can't hittest for Tapped events, and it'll fall through (to someone)

  THis at least works, but looks garish

* Match the pane border to the TabViewHeader

* Fix a bit of dead code and a bad copy-pasta

* This _works_ to use a winrt event, but it's dirty

* Clean up everything from the winrt::event debacle.

* This is dead code that shouldn't have been there

* Turn Tab's callback into a winrt::event as well
@ghost
Copy link

ghost commented Nov 26, 2019

🎉This issue was addressed in #3540, which has now been successfully released as Windows Terminal Preview v0.7.3291.0.:tada:

Handy links:

@nickcano
Copy link

nickcano commented Jan 5, 2020

I'm still experiencing this issue. Exactly as described here and in #3609. Just switched to terminal hoping to make it my main, but this is really messing with me. My version:

Windows Terminal (Preview)
Version: 0.7.3451.0

I'm on 1903 (Build 18362.535)

@DJackman123
Copy link
Contributor

Confirming that it's still happening for me as well. Looks like issue #3609 is still open and addressing this problem.

@KuroshM
Copy link

KuroshM commented Oct 17, 2022

I have version 1.15.2712.0 and opening a new tab (Ctrl+Shift+T ) does not gain focus until clicked on the window area.

@charliefortner
Copy link

Problem persists in version 1.15.2874.0
I launch Terminal from Start Menu and then must click the window for it to gain focus. I've tried Alt+Tab to switch away and then back to the Terminal window, but it still won't get focus so I can type.

@zadjii-msft
Copy link
Member

If you're seeing this on 1.15+, you're probably seeing #13388, not this thread. I'm gonna lock this thread as out-of-date. The root cause here was addressed a couple years ago. Let's track the new regression in the new thread. Thanks!

@microsoft microsoft locked as resolved and limited conversation to collaborators Nov 2, 2022
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Nov 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants