[PR #3540] [MERGED] Decouple "Active Terminal" and "Focused Control" #25421

Open
opened 2026-01-31 09:09:24 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/3540
Author: @zadjii-msft
Created: 11/12/2019
Status: Merged
Merged: 11/18/2019
Merged by: @zadjii-msft

Base: masterHead: dev/migrie/f/1205-active-vs-focused-ready-FIGHT


📝 Commits (10+)

📊 Changes

8 files changed (+313 additions, -183 deletions)

View changed files

📝 src/cascadia/TerminalApp/AppActionHandlers.cpp (+1 -1)
📝 src/cascadia/TerminalApp/Pane.cpp (+161 -89)
📝 src/cascadia/TerminalApp/Pane.h (+26 -8)
📝 src/cascadia/TerminalApp/Tab.cpp (+81 -25)
📝 src/cascadia/TerminalApp/Tab.h (+7 -3)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+29 -49)
📝 src/cascadia/TerminalApp/TerminalPage.h (+1 -1)
📝 src/cascadia/inc/cppwinrt_utils.h (+7 -7)

📄 Description

Summary of the Pull Request

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

Previously, we were exclusively using the "Focused" state of TermControls 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), 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

References

See also: #2046

PR Checklist

Validation Steps Performed

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/3540 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 11/12/2019 **Status:** ✅ Merged **Merged:** 11/18/2019 **Merged by:** [@zadjii-msft](https://github.com/zadjii-msft) **Base:** `master` ← **Head:** `dev/migrie/f/1205-active-vs-focused-ready-FIGHT` --- ### 📝 Commits (10+) - [`250e3d4`](https://github.com/microsoft/terminal/commit/250e3d4059100c4dbde01e495a332c72c7ef134c) this is janky but is close for some reason? - [`3125f62`](https://github.com/microsoft/terminal/commit/3125f624f77d39ec6ea9a3093dd675a9efeb2242) This is _almost_ right to solve #1205 - [`5929484`](https://github.com/microsoft/terminal/commit/59294845475e2e8e6c79b348fa1fdaef1584eb06) hey this autorevoker is really nice - [`aa70156`](https://github.com/microsoft/terminal/commit/aa701568d37cf65434665dc986ab73fc14736576) Encapsulate Pane::pfnGotFocus - [`30fc881`](https://github.com/microsoft/terminal/commit/30fc8811e6019a974f8021d31b6ddf5f7fa5ff61) Propogate the events back up on close - [`9cfebf1`](https://github.com/microsoft/terminal/commit/9cfebf1686c6b914e65abd7aefece2345b50339a) Encapsulate Tab::pfnFocusChanged, and clean up TerminalPage a bit - [`b61e6fe`](https://github.com/microsoft/terminal/commit/b61e6fe38dbced9ee41408943d425c0a3d42e92b) Mostly just code cleanup, commenting - [`e358e0d`](https://github.com/microsoft/terminal/commit/e358e0dcba13509b4b60ffb4638b92b4d720f57b) This works to hittest on the borders - [`b40e190`](https://github.com/microsoft/terminal/commit/b40e1905bff93f37ae0c3e36a68252be170e40ce) Match the pane border to the TabViewHeader - [`b585950`](https://github.com/microsoft/terminal/commit/b585950312830c19dbcb2d638c8d1ee31bc0afe4) Fix a bit of dead code and a bad copy-pasta ### 📊 Changes **8 files changed** (+313 additions, -183 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/AppActionHandlers.cpp` (+1 -1) 📝 `src/cascadia/TerminalApp/Pane.cpp` (+161 -89) 📝 `src/cascadia/TerminalApp/Pane.h` (+26 -8) 📝 `src/cascadia/TerminalApp/Tab.cpp` (+81 -25) 📝 `src/cascadia/TerminalApp/Tab.h` (+7 -3) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+29 -49) 📝 `src/cascadia/TerminalApp/TerminalPage.h` (+1 -1) 📝 `src/cascadia/inc/cppwinrt_utils.h` (+7 -7) </details> ### 📄 Description ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:09:24 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25421