Skip to content

Fix Acrylic flicker and window focus fallback - #20949

Open
alkali210 wants to merge 1 commit into
microsoft:mainfrom
alkali210:fix/acrylic-focus-flicker
Open

alkali210 wants to merge 1 commit into
microsoft:mainfrom
alkali210:fix/acrylic-focus-flicker

Conversation

@alkali210

Copy link
Copy Markdown

Summary of the Pull Request

Replaces reliance on AcrylicBackgroundSource::HostBackdrop for unfocused acrylic fallback with explicit top-level window activation tracking, keeping the tab row, terminal panes, and Settings preview controls on AcrylicBackgroundSource::Backdrop.

References and Relevant Issues

#20944

Detailed Description of the Pull Request / Additional comments

In XAML Islands, AcrylicBackgroundSource::HostBackdrop can misreport window activation state, leading to inverted acrylic states when switching focus between multiple Terminal windows and full-window flickering when hovering over the tab row with EnableUnfocusedAcrylic disabled.

This change switches acrylic fallback to be driven directly by top-level window activation:

  • TermControl.idl, TermControl.h, TermControl.cpp:
    • Adds WindowActivationChanged(Boolean activated) and tracks host-provided activation state in std::optional<bool> _windowActivated.
    • Uses AcrylicBackgroundSource::Backdrop whenever _windowActivated.has_value() or EnableUnfocusedAcrylic() is enabled, while preserving the existing HostBackdrop behavior for external hosts that do not call WindowActivationChanged.
    • Drives unfocused fallback explicitly via AcrylicBrush::AlwaysUseFallback(_ShouldUseAcrylicFallback()) and recreates the AcrylicBrush if its BackgroundSource changes.
  • TerminalPage.cpp:
    • Forwards _activated to controls in _SetupControl (covering both newly created and attached/moved panes) and propagates changes across all terminal panes in WindowActivated.
    • Keeps the tab row AcrylicBrush in _updateThemeColors on Backdrop, since _updateThemeColors already swaps to a solid/theme brush when the window is inactive and EnableUnfocusedAcrylic is disabled.
  • TerminalSettings.cpp:
    • Sets _EnableUnfocusedAcrylic = true in CreateForPreview and delegates CreateForPreviewUnfocused to CreateForPreview so preview controls—which are not driven by WindowActivationChanged—stay on Backdrop instead of mixing in HostBackdrop.

AI-use: used AI (Codex + 6.2-Astra) for investigating this bug fix and translation. Tested myself.

Validation Steps Performed

  • Enabled profile acrylic with "Allow acrylic material in unfocused windows" disabled, hovered across the tab row, and verified no full-window flicker occurs.
VID_20261121154557.mp4
  • Opened multiple Terminal windows, switched focus between them, and verified only the active window renders acrylic while inactive windows fall back to solid color.
#20944  Fix
PixPin_2026-11-21_15-29-01 PixPin_2026-11-21_15-29-36
  • Opened "Appearance" previews and verified unfocused acrylic fallback does not cause flicker.
  • Toggled "Allow acrylic material in unfocused windows" at runtime and verified active and inactive windows update cleanly.

PR Checklist

Use top-level window activation to control Acrylic fallback and keep the tab row, terminal panes, and settings previews on the same backdrop source.

Refs microsoft#20944
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@alkali210

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@zadjii-msft

Copy link
Copy Markdown
Member

What differentiates this PR from #20881?

What makes this the right solution to this problem? Would other approaches work too? Why this change and not some other approach?

@alkali210

Copy link
Copy Markdown
Author

What differentiates this PR from #20881?

What makes this the right solution to this problem? Would other approaches work too? Why this change and not some other approach?

Thanks for review!

What differentiates this PR from #20881

#20881 fixed mixed-source flicker for enableUnfocusedAcrylic: true by moving the tab row to Backdrop, while keeping both TermControl and the tab row on HostBackdrop when enableUnfocusedAcrylic: false.

#20944 reproduces on Preview 1.26.3133.0 (already includes #20881) with enableUnfocusedAcrylic: false, even with useAcrylicInTabRow: false:

  • In a cold-start two-window check (default theme, without opening Settings), active/inactive acrylic states invert when switching focus.
  • After opening/changing Settings, hovering over the tab row triggers a full-window flicker.

So this PR moves Terminal's own controls off HostBackdrop entirely and drives unfocused fallback explicitly from window activation (tested on Windows 11 29708.1003 and 29712.1013).

Why this approach

  • Aligning remaining controls onto HostBackdrop (extending Fix the useAcrylicInTabRow flicker #20881): The cold-start repro only involves TermControl's own HostBackdrop brush(es), suggesting HostBackdrop's activation tracking itself is unreliable in XAML Islands—so staying on HostBackdrop is unlikely to fix it.
  • Swapping TermControl to a SolidColorBrush on deactivate: TermControl intentionally reuses its AcrylicBrush to avoid flicker, and BackgroundBrush can be shared directly as TitlebarBrush (when tabRow uses terminalBackground). Toggling AlwaysUseFallback updates it in place and keeps shared references in sync.
  • Tracking activation inside TermControl instead of adding WindowActivationChanged: GotFocus/LostFocus tracks pane focus rather than window activation, and hooking the top-level HWND inside TermControl is fragile when tabs move across windows. WM_ACTIVATE already reaches TerminalPage, so WindowActivationChanged mirrors WindowVisibilityChanged, while std::optional<bool> preserves existing HostBackdrop fallback for external hosts.

note: I drafted this reply in Chinese, and used llm to translate, tighten the English wording and markdown formatting.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full-window flicker when hovering over the tab bar with unfocused acrylic disabled

2 participants