Skip to content

Fix title bar color inaccuracy on window restore #247773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
private titleBarStyle: TitlebarStyle;

private isInactive: boolean = false;
private initialFocusChecked: boolean = false;

private readonly isAuxiliary: boolean;
private isCompact = false;
Expand Down Expand Up @@ -345,15 +346,19 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
}

private onBlur(): void {
this.isInactive = true;

this.updateStyles();
// Only update if initial focus check is complete
if (this.initialFocusChecked) {
this.isInactive = true;
this.updateStyles();
}
}

private onFocus(): void {
this.isInactive = false;

this.updateStyles();
// Only update if initial focus check is complete
if (this.initialFocusChecked) {
this.isInactive = false;
this.updateStyles();
}
}

private onEditorPartConfigurationChange({ oldPartOptions, newPartOptions }: IEditorPartOptionsChangeEvent): void {
Expand Down Expand Up @@ -498,6 +503,38 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
this.createActionToolBarMenus();
}

// During startup, assume all windows are inactive until focus is properly determined
if (!this.initialFocusChecked) {
this.isInactive = true;

// Create a disposable store for initial focus detection
const initialFocusDisposables = new DisposableStore();

// Function to handle initial focus determination
const determineInitialFocus = () => {
if (!this.initialFocusChecked) {
this.initialFocusChecked = true;
this.isInactive = !getActiveDocument().hasFocus();
this.updateStyles();
initialFocusDisposables.dispose(); // Clean up event listeners
}
};

// Listen for focus events on the window
initialFocusDisposables.add(addDisposableListener(getWindow(this.element), 'focus', determineInitialFocus, true));
initialFocusDisposables.add(addDisposableListener(getWindow(this.element), 'blur', determineInitialFocus, true));

// Also listen for mouse clicks which might indicate user interaction with a window
initialFocusDisposables.add(addDisposableListener(getWindow(this.element).document, 'mousedown', determineInitialFocus, true));

// Fallback timeout as a safety net (longer duration to ensure we catch slower systems)
const fallbackTimer = setTimeout(() => determineInitialFocus(), 2000);
initialFocusDisposables.add({ dispose: () => clearTimeout(fallbackTimer) });

// Add to our disposables so it gets cleaned up properly
this._register(initialFocusDisposables);
}

// Window Controls Container
if (!hasNativeTitlebar(this.configurationService, this.titleBarStyle)) {
let primaryWindowControlsLocation = isMacintosh ? 'left' : 'right';
Expand Down