Skip to content

New module: AltWindowCycle - #48281

Merged
Clint Rutkas (crutkas) merged 23 commits into
mainfrom
crutkas/alt-window-cycle
Jul 31, 2026
Merged

Clint Rutkas (crutkas) merged 23 commits into
mainfrom
crutkas/alt-window-cycle

Conversation

@crutkas

@crutkas Clint Rutkas (crutkas) commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Summary of the Pull Request

Introduces a new utility: AltWindowCycle to quickly switch between windows from the same process using Alt + `.

In release notes give Wenzhao Hu (@wzhudev) coauthor credits as he also had an earlier PR

It works like Alt + Tab, but scoped to the app you’re already in. Perfect for juggling multiple browser windows, terminals, or editor instances.

alt-tic.mp4
image

PR Checklist

Detailed Description of the Pull Request / Additional comments

This PR adds AltWindowCycle (in-proc module + Settings integration), then addresses follow-up check-spelling feedback without changing runtime behavior:

  • allow-list update for ROOTOWNER
  • comment text adjustment for forbidden-pattern compliance
  • local identifier rename (wpx → whitePx) for spelling compliance

Validation Steps Performed

  • Verified ROOTOWNER is present in .github/actions/spell-check/allow/code.txt
  • Verified wpx is removed and updated occurrences in src/modules/AltWindowCycle/AltWindowCycle.cpp
  • Ran targeted diff/verification for both updated files
  • Ran final validation (code review + CodeQL trivial-change path)
  • Ran secret scan for changed files
Adds AltWindowCycle, an in-proc module that cycles the top-level windows
of the currently-focused application, mimicking macOS Cmd+.

- Native C++ module DLL (modeled on FindMyMouse) loaded in-proc by the runner
- Two configurable hotkeys: Alt+` (next) and Shift+Alt+` (previous)
- C# Settings page under Windowing & Layouts, Dashboard entry, GPO support
- Settings persisted to AltWindowCycle/settings.json

Note: ships with placeholder icon/module images (copied from AlwaysOnTop)
that still need real assets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@crutkas

Copy link
Copy Markdown
Member Author

Copilot add ROOTOWNER to the spelling allow list

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Copilot add ROOTOWNER to the spelling allow list

Done in be4a5c2 — ROOTOWNER is now in .github/actions/spell-check/allow/code.txt.

@crutkas

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.
@niels9001 Niels Laute (niels9001) added Area-Localization issues regarding to Localization the application Idea-New PowerToy Suggestion for a PowerToy Product-Settings The standalone PowerToys Settings application and removed Product-Settings The standalone PowerToys Settings application Area-Localization issues regarding to Localization the application labels Jun 5, 2026
Port the Alt-Tab-style overlay into the native PowerToys module with a dedicated UI thread, acrylic backdrop, and same-surface preview snapshots for real alpha-masked rounded corners.

Keep the runner hotkey callback lightweight by posting to the module UI thread, and harden snapshot capture with timeout-bounded WM_PRINTCLIENT rendering.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

check-spelling found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-actions

This comment has been minimized.

Keep thumbnail previews compositor-owned for visual fidelity and remove the rejected app-callback snapshot path. The overlay still runs on the dedicated module UI thread and preserves the acrylic chrome.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Show the overlay immediately, avoid stale monitor-size frames, and use an inset live-thumbnail viewport so DWM previews remain fast without exposing bad card corners.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Clint Rutkas (crutkas) and others added 2 commits June 5, 2026 16:40
Extract pure overlay layout, crop, wrap, and first-hotkey selection logic into a shared helper and cover it with native MSTests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@crutkas Clint Rutkas (crutkas) added the Needs-Review This Pull Request awaits the review of a maintainer. label Jun 6, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Theme-aware card background (dark mode uses a darker, mostly-opaque tile), 1px CardStroke border, header height 48 with vertically centered 16px icon/title, corner radius 10, preview inset by the card stroke so the border stays visible, robust opaque-backing + rounded-bottom punch so the DWM thumbnail reads as rounded at the bottom, and focus-ring contrast shadow that is white in light mode / black in dark mode. Unit-test layout expectations updated accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 44 changed files in this pull request and generated 2 comments.

Niels Laute (niels9001) and others added 2 commits June 25, 2026 20:09
Replaces the undocumented `SetWindowCompositionAttribute` /
`ACCENT_POLICY` acrylic path with the public, documented
`DWMWA_SYSTEMBACKDROP_TYPE` (`DWMSBT_TRANSIENTWINDOW`) on Windows 11
22H2+.

On older builds (Windows 10, Windows 11 21H2) it falls back to an opaque
tinted fill painted by the thumb host window proc, so no private
composition API is used anywhere.

### Changes
- Remove `ACCENT_POLICY` / `WINDOWCOMPOSITIONATTRIBDATA` /
`SetWindowCompositionAttribute` usage.
- Add `SupportsSystemBackdrop()` OS-version gate (build >= 22621 via
`RtlGetVersion`).
- Add `ApplyBackdrop()` + `ThumbHostProc` for the public acrylic path
and the opaque fallback fill.
- Guard `DWMWA_SYSTEMBACKDROP_TYPE` / `DWMSBT_TRANSIENTWINDOW` for older
SDKs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Re-add VREDRAW to spell-check allowlist; the module uses CS_VREDRAW
  (and it is referenced across the repo), so removing it would reintroduce
  spell-check failures.
- enable(): set m_enabled from InitializeAltWindowCycle() result and only
  emit the enabled telemetry on success, so a failed init no longer reports
  the module as enabled-but-non-functional.
- EnabledModules: note that AltWindowCycle defaults to off, matching the
  convention used by the surrounding fields.
- ShellPage: use the module-specific AltWindowCycle icon in the nav item
  instead of the generic Windowing & Layouts group icon.
- ShowOverlayWindow(): guard the CreateRoundRectRgn/SetWindowRgn pair so a
  null region is skipped and the HRGN is freed if SetWindowRgn fails.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Orange-GT3

Copy link
Copy Markdown

What's wrong with Ctrl-Tab, which already does the job?

@sergey-pt

Copy link
Copy Markdown

What's wrong with Ctrl-Tab, which already does the job?

Orange-GT3 it does not, ctrl + tab in the browser for example is changing tabs. This PR adds possibility for switching windows of the same app, for example if there are 2 windows of Edge browser, one for personal profile, and another for work profile, with this PR Alt + backtick would allow to quickly switch between those 2 windows, it is very convinient for productivity.

@Orange-GT3

Copy link
Copy Markdown

What's wrong with Ctrl-Tab, which already does the job?

Orange-GT3 it does not, ctrl + tab in the browser for example is changing tabs. This PR adds possibility for switching windows of the same app, for example if there are 2 windows of Edge browser, one for personal profile, and another for work profile, with this PR Alt + backtick would allow to quickly switch between those 2 windows, it is very convinient for productivity.

Yes, OK. Ctrl-Tab works for changing windows in Word and Excel, for example, but I agree it wouldn't change browser windows.

@crutkas

Copy link
Copy Markdown
Member Author

Ctrl-Tab is 'window locked' for things typically like tabs too. So you have have 3 browser windows open but you cycle within only the in-focus one w/ ctrl-tab

Clint Rutkas (crutkas) and others added 2 commits July 2, 2026 23:39
…ogic

Move the Alt-Tab eligibility predicate and the same-process window
selection/ordering out of the inline EnumWindows glue in AltWindowCycle.cpp
into pure helpers in AltWindowCycleLogic.h (WindowEligibility /
IsAltTabEligible / CandidateWindow / SelectCycleWindows). The refactor is
behavior-preserving: the same Win32 queries run in the same short-circuit
order; only the boolean composition and process-key grouping moved to the
header so they can be unit-tested without a live desktop.

Add native unit tests covering same-process inclusion, exclusion of
invisible/cloaked/owned/tool windows, Z-order preservation, unknown-
foreground and 0/1-window cases, duplicate-process grouping, and
unresolved-process handling. Also extend the pure-logic coverage
(column clamping, max-columns, narrow work area, DPI 1.0/1.25/1.5/2.0
padding, tile row/column advance, wrap-index and begin-cycle edges,
modifier sanitization).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds C# MSTest coverage for the new AltWindowCycle module:
- AltWindowCycleSettingsTests: default hotkeys (Alt+\, Shift+Alt+\),
  JSON key contract (next_window_shortcut/previous_window_shortcut),
  ToJsonString round-trip for defaults + custom overrides, and
  SettingsSerializationContext registration (AOT).
- AltWindowCycle ViewModel: loads shortcuts from settings, enable path
  emits OutGoingGeneralSettings IPC, GPO not-configured stays user-managed,
  shortcut changes persist via SaveSettings, and null shortcut falls back
  to the module default.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@crutkas

Copy link
Copy Markdown
Member Author

Niels Laute (@niels9001). Let’s please be sure to give Wenzhao Hu (@wzhudev)
credit too

@crutkas

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@MuyuanMS Muyuan Li (MuyuanMS) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the module code (build + 29/29 tests pass locally). A few things worth addressing before merge:

🔴 HIGH — UI thread can outlive DLL unload → use-after-unload crash · AltWindowCycle.cpp ShutdownAltWindowCycle (~L1540) + init-timeout paths (~L1505-1525)
ShutdownAltWindowCycle returns on the 5s timeout without joining the worker, and the init-timeout path closes the handle even if the join timed out. destroy() unloads the DLL immediately after, so a surviving worker executes unmapped code. The worker only ever blocks on bounded SMTO_ABORTIFHUNG calls, so it's safe to loop re-posting WM_QUIT and join unconditionally before returning — one shared helper used by shutdown and both init-failure paths.

🔴 HIGH — EnumWindows runs inside the WH_KEYBOARD_LL hook proc → hook can be silently dropped · AltWindowCycle.cpp HandleAltWindowCycleHotkey "quick check" (GetAppWindows)
GetAppWindows does EnumWindows + per-window OpenProcess/DwmGetWindowAttribute (+EnumChildWindows for UWP) synchronously in the LL keyboard-hook callback (centralized_kb_hook.cpp invokes action() directly in KeyboardHookProc), then the UI thread repeats the scan. If it exceeds LowLevelHooksTimeout (300ms default), Windows removes our keyboard hook — a known PT failure mode. The module's own header says the callback "only posts a message," so the code diverges from its intended design. Suggest a cached same-app eligibility set maintained on the worker via SetWinEventHook, or a cheap PID/visibility-only count without OpenProcess/DWM per window.

🔴 HIGH — off-by-default in Settings but auto-starts · dllmain.cpp
EnabledModules defaults this off, but the module inherits is_enabled_by_default() == true, so start_enabled_powertoys() starts it and reserves Alt+` for users whose settings predate the key, while the UI shows it off. Override to return false:

virtual bool is_enabled_by_default() const override
{
    return false;
}

🟠 MEDIUM — Escape/cancel detected by polling but not consumed · AltWindowCycle.cpp OnTick (~L582-596)
GetAsyncKeyState(VK_ESCAPE) observes the key but can't swallow it (both overlays are WS_EX_NOACTIVATE), so Escape also reaches the foreground app (closing a dialog/menu), and short presses between 25ms ticks are missed. Route the cancel key through the centralized hook while the switcher is visible.

🟠 MEDIUM — overlay layout only caps columns; panel can exceed the work area · AltWindowCycleLogic.h ComputeOverlayLayout (~L127)
Many windows / high DPI (e.g. 13 windows 150% on 1080p) produce a panel taller than the screen; centering pushes panelY negative so the header/top tiles are unreachable. Clamp the origin on-screen (paging / a visible-tile cap can follow):

layout.panelX = work.left + (workW - layout.panelW) / 2;
layout.panelY = work.top + (workH - layout.panelH) / 2;
if (layout.panelX < work.left) { layout.panelX = work.left; }
if (layout.panelY < work.top)  { layout.panelY = work.top; }

🟠 MEDIUM — missing Fluent icon mapping → broken image · Settings.UI.Library/Helpers/ModuleHelper.cs GetModuleTypeFluentIconName (~L32)
The fallback resolves Assets/Settings/Icons/AltWindowCycle.png, which doesn't exist (the asset is WindowHopper.png) → broken tile in Dashboard / Quick Access / shortcut-conflict UI:

ModuleType.AltWindowCycle => "ms-appx:///Assets/Settings/Icons/WindowHopper.png",

🟡 LOW — release binary not in signing policy · .pipelines/ESRPSigning_core.json (+ installer WXS / signed YML)
PowerToys.AltWindowCycle.dll would ship unsigned — add it alongside the other module DLLs (maps to the unchecked "New binaries" checklist items).

Make UI-thread teardown join before unload, keep keyboard-hook work bounded, and consume Escape through the centralized hook. Align default enablement, clamp oversized overlays, and complete icon and signing integration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: dd5080ea-5001-4efb-87f8-1e7218e10a4e

@MuyuanMS Muyuan Li (MuyuanMS) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at HEAD 61a5f42 — thanks, this addresses the bulk of the earlier feedback: the worker thread is now joined unconditionally before unload, the window enumeration is off the LL keyboard-hook proc, is_enabled_by_default() returns false, Escape is routed through the centralized hook, the icon maps to the real WindowHopper.png, and the signing entry is in place. Module builds and 29/29 tests pass locally. Two mediums still worth addressing before merge, plus one trivial nicety:

🟠 MEDIUM — overlay can still overflow the work-area bottom · AltWindowCycleLogic.h ComputeOverlayLayout (~L127)
Thanks for the origin clamp — that fixes the negative-panelY case. One residual: the layout still doesn't bound panelH to the work-area height, so with many same-app windows (or high DPI) the panel extends past the bottom edge and the lower tiles + the selection indicator render off-screen. Could we clamp the row count to what fits (and paginate or shrink tiles beyond that) so the selected item is always visible? The new oversized-panel test currently codifies the origin-only behavior.

🟠 MEDIUM — dashboard NRE on a null shortcut in settings.json · AltWindowCycleProperties + DashboardViewModel.GetModuleItemsAltWindowCycle()
GetModuleItemsAltWindowCycle() calls settings.Properties.NextWindowShortcut.GetKeysList() directly. Because the setters accept null, a "next_window_shortcut": null in settings.json deserializes to a null shortcut and this crashes dashboard construction with an NRE. Recommend null-normalizing backing properties (same pattern as PowerDisplayProperties.ActivationShortcut) so a deserialized null falls back to the default.

🟡 LOW — honor WS_EX_APPWINDOW in Alt-Tab eligibility · AltWindowCycleLogic.h IsAltTabEligible (~L215)
Currently all WS_EX_TOOLWINDOW windows are rejected even when WS_EX_APPWINDOW overrides it. Matching Window Walker's (!isToolWindow || isAppWindow) would include app windows that opt in. Trivial and low-risk.

Non-blocking follow-ups (fine as later work): the no-activate overlay exposes no UIA provider, so it's not screen-reader accessible; and the ViewModel unit tests share a process-wide SettingsRepository singleton, making them order-dependent.

Clint Rutkas (crutkas) and others added 2 commits July 29, 2026 08:00
Paginate overlay rows to the monitor work area, normalize null shortcut settings, and honor WS_EX_APPWINDOW when evaluating tool windows.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: dd5080ea-5001-4efb-87f8-1e7218e10a4e
…ner thread

Escape was registered as real global hotkeys (Alt+Esc, Shift+Alt+Esc) with
conflict-manager IDs 2 and 3, but AltWindowCycleSettings.GetAllHotkeyAccessors()
returns only 2 accessors, so the conflict dialog indexed past the array and
silently dropped the Window Hopper row. It also meant PowerToys permanently
claimed Alt+Escape, a documented Windows shell shortcut, even while idle.

Escape is now handled by a WH_KEYBOARD_LL hook installed on the module UI thread
only while the overlay is visible. The callback stays bounded: it posts
WM_AWC_CANCEL to the UI thread and swallows the key only when the post succeeds,
so teardown runs on the message loop instead of inline.

The runner drives enable()/disable()/on_hotkey() on the same thread that services
the centralized keyboard hook, where Windows drops hooks that exceed
LowLevelHooksTimeout (300 ms). enable() waited up to 5 s for UI-thread init and
disable() joined without any bound. Both are now capped at 200 ms; the unbounded
join is kept only in destroy(), which is followed by FreeLibrary. A timed-out
disable() lets the thread finish asynchronously, and a subsequent enable()
re-joins before starting a second UI thread.

Also:
- Draw an "n / m" page indicator when the cycle set spans multiple pages.
- Fall back to defaults for a hand-edited shortcut with no modifier, which would
  otherwise flash the overlay and commit immediately on the first tick.
- Remove dead code: CycleForegroundAppWindows, an unreachable state check in
  OnHotkey, the cancel-hotkey machinery, and the now write-only g_switcherActive.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: dd5080ea-5001-4efb-87f8-1e7218e10a4e

@MuyuanMS Muyuan Li (MuyuanMS) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — re-reviewed the latest revision (the threading refactor plus the follow-up layout/null-shortcut/APPWINDOW fixes): every earlier finding is resolved with accompanying tests, the module builds, the native unit tests pass, and Copilot review came back clean. I also e2e-verified locally — overlay rendering, Alt+` / Shift+Alt+` cycling, Escape scoped to the overlay only, and a clean disable/exit with no hang.

The two inline comments are nits only and entirely at your discretion to take or leave before check-in — neither blocks this PR. Thanks for the thorough iterations!

layout.rows = (std::min)(totalRows, rowsFromWork);
layout.pageSize = (std::min)(safeWindowCount, layout.cols * layout.rows);
layout.panelW = 2 * layout.pad + layout.cols * layout.tileW + (layout.cols - 1) * layout.gap;
layout.panelH = 2 * layout.pad + layout.rows * layout.tileH + (std::max)(0, layout.rows - 1) * layout.gap;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit, optional] When a single tile plus padding exceeds the work area (tiny display at extreme scaling), the computed panelW/panelH can exceed it while the panelX < work.left / panelY < work.top guards only pin the top-left corner, so the panel overflows the opposite edge. Clamping the final dimensions to the work area keeps it fully on-screen (tiles clip in this degenerate case). Not blocking.

Suggested change
layout.panelH = 2 * layout.pad + layout.rows * layout.tileH + (std::max)(0, layout.rows - 1) * layout.gap;
layout.panelH = 2 * layout.pad + layout.rows * layout.tileH + (std::max)(0, layout.rows - 1) * layout.gap;
layout.panelW = (std::min)(layout.panelW, workW);
layout.panelH = (std::min)(layout.panelH, workH);
// arrives once its message queue exists.
const DWORD waitResult = WaitForSingleObject(readyEvent, UIThreadInitWaitMs);
CloseHandle(readyEvent);
if (waitResult == WAIT_OBJECT_0 && !g_initOk.load())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit, optional] The optimistic-enable on init timeout is intentional, but a genuinely stuck UI thread would be indistinguishable from a healthy slow start in field logs. A single trace on the timeout path makes it diagnosable (behavior unchanged). Not blocking.

Suggested change
if (waitResult == WAIT_OBJECT_0 && !g_initOk.load())
if (waitResult == WAIT_TIMEOUT)
{
Logger::info("AltWindowCycle UI thread init did not signal within the wait budget; enabling optimistically");
}
if (waitResult == WAIT_OBJECT_0 && !g_initOk.load())
@crutkas
Clint Rutkas (crutkas) merged commit bb99c30 into main Jul 31, 2026
8 checks passed
@crutkas
Clint Rutkas (crutkas) deleted the crutkas/alt-window-cycle branch July 31, 2026 05:42
@robmonte

Copy link
Copy Markdown

Oh my goodness thank you so much for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.101 Idea-New PowerToy Suggestion for a PowerToy Needs-Review This Pull Request awaits the review of a maintainer. Product-Always On Top Refers to the idea of a Always on Top Powertoy Product-Settings The standalone PowerToys Settings application

10 participants