Skip to content

CmdPal: Add hidden window as owner for tool windows#42902

Merged
michaeljolley merged 1 commit intomicrosoft:mainfrom
jiripolasek:hotfix/42395-cmdpal-add-hidden-owners-to-tool-windows
Oct 28, 2025
Merged

CmdPal: Add hidden window as owner for tool windows#42902
michaeljolley merged 1 commit intomicrosoft:mainfrom
jiripolasek:hotfix/42395-cmdpal-add-hidden-owners-to-tool-windows

Conversation

@jiripolasek
Copy link
Copy Markdown
Collaborator

@jiripolasek jiripolasek commented Oct 24, 2025

Summary of the Pull Request

This PR changes the method used to hide tool windows from the taskbar and Alt+Tab to a more reliable approach.
Previously, this was achieved by adding WS_EX_TOOLWINDOW to an unowned top-level window, which proved unreliable in several scenarios.

The new implementation assigns a hidden window as the owner of each tool window.
This ensures that the window does not appear on the taskbar even when the Windows setting
Settings → System → Multitasking → On the taskbar, show all opened windows is set to On all desktops.

Change log one-liner

Fixes Command Palette windows occasionally appearing on the taskbar under certain system settings.

PR Checklist

  • Closes: Command Palette permanently opened on taskbar #42395
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: none
  • Documentation updated: no need

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Tested alongside the stable CmdPal on a system with

Switches to a more reliable method for hiding tool windows from the taskbar and Alt+Tab. Previously, this was done by adding WS_EX_TOOLWINDOW to an unowned top-level window, which proved unreliable in multiple scenarios. This change uses a hidden owner window instead.
@jiripolasek jiripolasek marked this pull request as draft October 24, 2025 20:03
@jiripolasek jiripolasek added the Product-Command Palette Refers to the Command Palette utility label Oct 24, 2025
@jiripolasek jiripolasek self-assigned this Oct 24, 2025
@jiripolasek jiripolasek marked this pull request as ready for review October 27, 2025 12:12
Copy link
Copy Markdown
Contributor

@michaeljolley michaeljolley left a comment

Choose a reason for hiding this comment

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

Image

@michaeljolley michaeljolley merged commit 103429b into microsoft:main Oct 28, 2025
10 checks passed
@yeelam-gordon yeelam-gordon requested a review from Copilot November 7, 2025 01:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the window taskbar and Alt+Tab visibility management into a new reusable HiddenOwnerWindowBehavior class. The refactoring consolidates duplicated logic from MainWindow and ToastWindow that previously used extended window styles directly.

  • Introduces HiddenOwnerWindowBehavior to centralize taskbar/Alt+Tab visibility logic using a hidden owner window pattern
  • Removes ApplyWindowStyle() from MainWindow and simplifies initialization
  • Updates ToastWindow to use the new behavior class instead of direct style manipulation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/modules/cmdpal/Microsoft.CmdPal.UI/HiddenOwnerWindowBehavior.cs New class that encapsulates taskbar visibility logic using hidden owner window pattern and extended window styles
src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs Replaced ApplyWindowStyle() method with HiddenOwnerWindowBehavior instance; added early HideWindow() call
src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs Removed direct window style manipulation and replaced with HiddenOwnerWindowBehavior
src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs Changed GetWindowHwnd() visibility from private to public to support the new behavior class
src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt Added P/Invoke entries for new window creation APIs

Comment on lines +69 to 71
HideWindow();

_hwnd = new HWND(WinRT.Interop.WindowNative.GetWindowHandle(this).ToInt32());
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

HideWindow() is called before _hwnd is initialized on line 71. The HideWindow() method calls Cloak(), which uses _hwnd (lines 385, 398). This will cause _hwnd to have its default uninitialized value when used, potentially leading to incorrect behavior or a crash. Move this call to after line 71 where _hwnd is initialized, or move the _hwnd initialization before this call.

Suggested change
HideWindow();
_hwnd = new HWND(WinRT.Interop.WindowNative.GetWindowHandle(this).ToInt32());
_hwnd = new HWND(WinRT.Interop.WindowNative.GetWindowHandle(this).ToInt32());
HideWindow();

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +88
private HWND EnsureHiddenOwner()
{
if (_hiddenOwnerHwnd.IsNull)
{
_hiddenWindow = new Window();
_hiddenOwnerHwnd = _hiddenWindow.GetWindowHwnd();
}

return _hiddenOwnerHwnd;
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The hidden owner window (_hiddenWindow) is created in EnsureHiddenOwner() but is never disposed. This can lead to a resource leak. Consider implementing IDisposable on this class and disposing of _hiddenWindow (e.g., by calling _hiddenWindow?.Close()) in the Dispose method. The owning classes (MainWindow and ToastWindow) should then call Dispose on their HiddenOwnerWindowBehavior instances when they are disposed or closed.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +66
GetStockObject
GetModuleHandle No newline at end of file
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

GetModuleHandle is listed twice in this file (lines 58 and 66). Remove the duplicate entry on line 66.

Suggested change
GetStockObject
GetModuleHandle
GetStockObject

Copilot uses AI. Check for mistakes.
@yeelam-gordon yeelam-gordon added this to the PowerToys 0.96 milestone Nov 11, 2025
@jiripolasek jiripolasek deleted the hotfix/42395-cmdpal-add-hidden-owners-to-tool-windows branch November 11, 2025 23:15
vanzue pushed a commit that referenced this pull request Nov 12, 2025
## Summary of the Pull Request

This PR changes the method used to hide tool windows from the taskbar
and Alt+Tab to a more reliable approach.
Previously, this was achieved by adding `WS_EX_TOOLWINDOW` to an unowned
top-level window, which proved unreliable in several scenarios.

The new implementation assigns a hidden window as the owner of each tool
window.
This ensures that the window does not appear on the taskbar even when
the Windows setting
**Settings → System → Multitasking → On the taskbar, show all opened
windows** is set to **On all desktops**.

## Change log one-liner

Fixes Command Palette windows occasionally appearing on the taskbar
under certain system settings.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #42395
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [x] **Dev docs:** Added/updated
- [x] **New binaries:** none
- [x] **Documentation updated:** no need

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

Tested alongside the stable CmdPal on a system with
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command Palette permanently opened on taskbar

4 participants