[PR #12799] [MERGED] Allow windows created by console apps to appear above the Terminal #29230

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12799
Author: @zadjii-msft
Created: 3/31/2022
Status: Merged
Merged: 4/19/2022
Merged by: @zadjii-msft

Base: mainHead: dev/migrie/b/2988-focus-foreground


📝 Commits (10+)

  • 9dd1649 Doesn't build. Want to merge in the ConGetSet change first, cause obviously that's gonna blow this diff up.
  • 1a1caf9 cherry-pick 479c6c9f08
  • 5be7f76 comments comments comments
  • 37adb94 remove a todo
  • 172acd2 you knew there'd be typos
  • 0d17cd7 Merge branch 'main' into dev/migrie/b/2988-focus-foreground
  • ac53c8a Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-focus-foreground
  • e6e5669 what? I always run the tests locally i dunno what you're talking about....
  • 440323d this should have always been in this branch
  • 3b4675c oh my god I've done it again

📊 Changes

11 files changed (+101 additions, -3 deletions)

View changed files

📝 src/cascadia/TerminalControl/ControlCore.cpp (+21 -0)
📝 src/cascadia/TerminalControl/ControlCore.h (+3 -0)
📝 src/cascadia/TerminalControl/ControlInteractivity.cpp (+4 -0)
📝 src/host/CursorBlinker.cpp (+3 -1)
📝 src/server/IoDispatchers.cpp (+16 -1)
📝 src/terminal/adapter/IInteractDispatch.hpp (+2 -0)
📝 src/terminal/adapter/InteractDispatch.cpp (+29 -0)
📝 src/terminal/adapter/InteractDispatch.hpp (+2 -0)
📝 src/terminal/parser/InputStateMachineEngine.cpp (+12 -1)
📝 src/terminal/parser/InputStateMachineEngine.hpp (+2 -0)
📝 src/terminal/parser/ut_parser/InputEngineTest.cpp (+7 -0)

📄 Description

Window shenanigans, part the third:

Hooks the Terminal's focus state up to the underlying ConPTY. This is LOAD BEARING for allowing windows created by console applications to bring themselves to the foreground.

We're using the FocusIn/FocusOut sequences to communicate to ConPTY when a control gains/loses focus. Theoretically, other terminals could do this as well.

References

#11682 tracks real support for this sequence in Console & conpty. When we do that, we should consider even if a client application disables this mode, the Terminal & conpty should always request this from the hosting terminal (and just ignore internally to ConPTY).

See also #12515, #12526, which are the other two parts of this effort. This was tested with all three merged together, and they worked beautifully for all our scenarios. They are kept separate for ease of review.

PR Checklist

  • This is prototype 3 for #2988
  • I work here
  • Tests added/passed
  • [n/a] Requires documentation to be updated

Detailed Description of the Pull Request / Additional comments

This allows windows spawned by console processes to bring themselves to the foreground when the console is focused. (Historically, this is also called in the WndProc, when focus changes).

Notably, before this, ConPTY was never focused, so windows could never bring themselves to the foreground when run from a ConPTY console. We're not blanket granting the SetForeground right to all console apps when run in ConPTY. It's the responsibility of the hosting terminal emulator to always tell ConPTY when a particular instance is focused.

Validation Steps Performed

(gif below)


🔄 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/12799 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 3/31/2022 **Status:** ✅ Merged **Merged:** 4/19/2022 **Merged by:** [@zadjii-msft](https://github.com/zadjii-msft) **Base:** `main` ← **Head:** `dev/migrie/b/2988-focus-foreground` --- ### 📝 Commits (10+) - [`9dd1649`](https://github.com/microsoft/terminal/commit/9dd16495251e393aa05387c955697ecc7efd64be) Doesn't build. Want to merge in the ConGetSet change first, cause _obviously_ that's gonna blow this diff up. - [`1a1caf9`](https://github.com/microsoft/terminal/commit/1a1caf94357e317ac0c5bc85fc8502e75f988644) cherry-pick 479c6c9f08cf273768e64f9f7fbc74a2c231b815 - [`5be7f76`](https://github.com/microsoft/terminal/commit/5be7f76586e2a9d7363145171383b00fe1a44f0f) comments comments comments - [`37adb94`](https://github.com/microsoft/terminal/commit/37adb94c90454d7b8f8c5ad6671b5edac34c8f39) remove a todo - [`172acd2`](https://github.com/microsoft/terminal/commit/172acd2f8b08ecca2d883de77dd2acdaf55bd48b) you knew there'd be typos - [`0d17cd7`](https://github.com/microsoft/terminal/commit/0d17cd722996bc291b0dc8ec41cd7fd335905a38) Merge branch 'main' into dev/migrie/b/2988-focus-foreground - [`ac53c8a`](https://github.com/microsoft/terminal/commit/ac53c8a910163233bd87c1abd13569efffadce48) Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-focus-foreground - [`e6e5669`](https://github.com/microsoft/terminal/commit/e6e566932cae99e78cc12ca0d122cdc3b422034d) what? I always run the tests locally i dunno what you're talking about.... - [`440323d`](https://github.com/microsoft/terminal/commit/440323d59c477181d49883468c8699e9b243e219) this should have always been in this branch - [`3b4675c`](https://github.com/microsoft/terminal/commit/3b4675c6842575167d5b1b8ddc2635b458e88c24) oh my god I've done it again ### 📊 Changes **11 files changed** (+101 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+21 -0) 📝 `src/cascadia/TerminalControl/ControlCore.h` (+3 -0) 📝 `src/cascadia/TerminalControl/ControlInteractivity.cpp` (+4 -0) 📝 `src/host/CursorBlinker.cpp` (+3 -1) 📝 `src/server/IoDispatchers.cpp` (+16 -1) 📝 `src/terminal/adapter/IInteractDispatch.hpp` (+2 -0) 📝 `src/terminal/adapter/InteractDispatch.cpp` (+29 -0) 📝 `src/terminal/adapter/InteractDispatch.hpp` (+2 -0) 📝 `src/terminal/parser/InputStateMachineEngine.cpp` (+12 -1) 📝 `src/terminal/parser/InputStateMachineEngine.hpp` (+2 -0) 📝 `src/terminal/parser/ut_parser/InputEngineTest.cpp` (+7 -0) </details> ### 📄 Description ## Window shenanigans, part the third: Hooks the Terminal's focus state up to the underlying ConPTY. This is LOAD BEARING for allowing windows created by console applications to bring themselves to the foreground. We're using the [FocusIn/FocusOut](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-FocusIn_FocusOut) sequences to communicate to ConPTY when a control gains/loses focus. Theoretically, other terminals could do this as well. ## References #11682 tracks _real_ support for this sequence in Console & conpty. When we do that, we should consider even if a client application disables this mode, the Terminal & conpty should always request this from the hosting terminal (and just ignore internally to ConPTY). See also #12515, #12526, which are the other two parts of this effort. This was tested with all three merged together, and they worked beautifully for all our scenarios. They are kept separate for ease of review. ## PR Checklist * [x] This is prototype 3 for #2988 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments This allows windows spawned by console processes to bring themselves to the foreground _when the console is focused_. (Historically, this is also called in the WndProc, when focus changes). Notably, before this, ConPTY was _never_ focused, so windows could never bring themselves to the foreground when run from a ConPTY console. We're not blanket granting the SetForeground right to all console apps when run in ConPTY. It's the responsibility of the hosting terminal emulator to always tell ConPTY when a particular instance is focused. ## Validation Steps Performed (gif below) --- <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:33:38 +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#29230