Skip to content

Commit dcb066e

Browse files
authored
aux window - fix broken focus tracking (fix microsoft#199266) (microsoft#199267)
1 parent a3d5787 commit dcb066e

File tree

7 files changed

+46
-47
lines changed

7 files changed

+46
-47
lines changed

src/vs/workbench/browser/layout.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b
4848
import { AuxiliaryBarPart } from 'vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart';
4949
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
5050
import { IAuxiliaryWindowService } from 'vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService';
51-
import { $window, mainWindow } from 'vs/base/browser/window';
51+
import { mainWindow } from 'vs/base/browser/window';
5252

5353
//#region Layout Implementation
5454

@@ -57,7 +57,7 @@ interface ILayoutRuntimeState {
5757
fullscreen: boolean;
5858
maximized: Set<number>;
5959
hasFocus: boolean;
60-
windowBorder: boolean;
60+
mainWindowBorder: boolean;
6161
readonly menuBar: {
6262
toggled: boolean;
6363
};
@@ -368,10 +368,10 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
368368
}
369369

370370
// Theme changes
371-
this._register(this.themeService.onDidColorThemeChange(() => this.updateWindowBorder($window.vscodeWindowId)));
371+
this._register(this.themeService.onDidColorThemeChange(() => this.updateWindowsBorder()));
372372

373373
// Window active / focus changes
374-
this._register(this.hostService.onDidChangeFocus(focused => this.onWindowFocusChanged($window.vscodeWindowId, focused)));
374+
this._register(this.hostService.onDidChangeFocus(focused => this.onWindowFocusChanged(focused)));
375375
this._register(this.hostService.onDidChangeActiveWindow(() => this.onActiveWindowChanged()));
376376

377377
// WCO changes
@@ -449,7 +449,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
449449
// Propagate to grid
450450
this.workbenchGrid.setViewVisible(this.titleBarPartView, this.shouldShowTitleBar());
451451

452-
this.updateWindowBorder($window.vscodeWindowId, true);
452+
this.updateWindowsBorder(true);
453453
}
454454

455455
this._onDidChangeFullscreen.fire(this.state.runtime.fullscreen);
@@ -459,14 +459,18 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
459459
const activeContainerId = this.getActiveContainerId();
460460
if (this.state.runtime.activeContainerId !== activeContainerId) {
461461
this.state.runtime.activeContainerId = activeContainerId;
462+
463+
// Indicate active window border
464+
this.updateWindowsBorder();
465+
462466
this._onDidChangeActiveContainer.fire();
463467
}
464468
}
465469

466-
private onWindowFocusChanged(targetWindowId: number, hasFocus: boolean): void {
470+
private onWindowFocusChanged(hasFocus: boolean): void {
467471
if (this.state.runtime.hasFocus !== hasFocus) {
468472
this.state.runtime.hasFocus = hasFocus;
469-
this.updateWindowBorder(targetWindowId);
473+
this.updateWindowsBorder();
470474
}
471475
}
472476

@@ -520,7 +524,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
520524
this.adjustPartPositions(position, panelAlignment, panelPosition);
521525
}
522526

523-
private updateWindowBorder(targetWindowId: number, skipLayout: boolean = false) {
527+
private updateWindowsBorder(skipLayout = false) {
524528
if (
525529
isWeb ||
526530
isWindows || // not working well with zooming and window control overlays
@@ -534,22 +538,26 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
534538
const activeBorder = theme.getColor(WINDOW_ACTIVE_BORDER);
535539
const inactiveBorder = theme.getColor(WINDOW_INACTIVE_BORDER);
536540

537-
let windowBorder = false;
538-
if (!this.state.runtime.fullscreen && !this.state.runtime.maximized.has(targetWindowId) && (activeBorder || inactiveBorder)) {
539-
windowBorder = true;
541+
for (const container of this.containers) {
542+
const isMainContainer = container === this.mainContainer;
543+
const isActiveContainer = this.activeContainer === container;
544+
const containerWindowId = getWindowId(getWindow(container));
540545

541-
// If the inactive color is missing, fallback to the active one
542-
const borderColor = this.state.runtime.hasFocus ? activeBorder : inactiveBorder ?? activeBorder;
543-
this.mainContainer.style.setProperty('--window-border-color', borderColor?.toString() ?? 'transparent');
544-
}
546+
let windowBorder = false;
547+
if (!this.state.runtime.fullscreen && !this.state.runtime.maximized.has(containerWindowId) && (activeBorder || inactiveBorder)) {
548+
windowBorder = true;
545549

546-
if (windowBorder === this.state.runtime.windowBorder) {
547-
return;
548-
}
550+
// If the inactive color is missing, fallback to the active one
551+
const borderColor = isActiveContainer && this.state.runtime.hasFocus ? activeBorder : inactiveBorder ?? activeBorder;
552+
container.style.setProperty('--window-border-color', borderColor?.toString() ?? 'transparent');
553+
}
549554

550-
this.state.runtime.windowBorder = windowBorder;
555+
if (isMainContainer) {
556+
this.state.runtime.mainWindowBorder = windowBorder;
557+
}
551558

552-
this.mainContainer.classList.toggle(LayoutClasses.WINDOW_BORDER, windowBorder);
559+
container.classList.toggle(LayoutClasses.WINDOW_BORDER, windowBorder);
560+
}
553561

554562
if (!skipLayout) {
555563
this.layout();
@@ -614,7 +622,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
614622
fullscreen: isFullscreen(),
615623
hasFocus: this.hostService.hasFocus,
616624
maximized: new Set<number>(),
617-
windowBorder: false,
625+
mainWindowBorder: false,
618626
menuBar: {
619627
toggled: false,
620628
},
@@ -676,7 +684,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
676684
}
677685

678686
// Window border
679-
this.updateWindowBorder(mainWindow.vscodeWindowId, true);
687+
this.updateWindowsBorder(true);
680688
}
681689

682690
private getDefaultLayoutViews(environmentService: IBrowserWorkbenchEnvironmentService, storageService: IStorageService): string[] | undefined {
@@ -1995,16 +2003,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
19952003
}
19962004
}
19972005

1998-
hasWindowBorder(): boolean {
1999-
return this.state.runtime.windowBorder;
2000-
}
2001-
2002-
getWindowBorderWidth(): number {
2003-
return this.state.runtime.windowBorder ? 2 : 0;
2006+
hasMainWindowBorder(): boolean {
2007+
return this.state.runtime.mainWindowBorder;
20042008
}
20052009

2006-
getWindowBorderRadius(): string | undefined {
2007-
return this.state.runtime.windowBorder && isMacintosh ? '5px' : undefined;
2010+
getMainWindowBorderRadius(): string | undefined {
2011+
return this.state.runtime.mainWindowBorder && isMacintosh ? '5px' : undefined;
20082012
}
20092013

20102014
isPanelMaximized(): boolean {
@@ -2139,7 +2143,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
21392143
this.state.runtime.maximized.delete(targetWindowId);
21402144
}
21412145

2142-
this.updateWindowBorder(targetWindowId);
2146+
this.updateWindowsBorder();
21432147
this._onDidChangeWindowMaximized.fire({ windowId: targetWindowId, maximized });
21442148
}
21452149

src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export class AuxiliaryEditorPart {
114114
}
115115
}));
116116

117-
118117
updateStatusbarVisibility(false);
119118

120119
// Lifecycle

src/vs/workbench/contrib/splash/browser/partsSplash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class PartsSplash {
8484
activityBarWidth: this._layoutService.isVisible(Parts.ACTIVITYBAR_PART) ? dom.getTotalWidth(assertIsDefined(this._layoutService.getContainer(mainWindow, Parts.ACTIVITYBAR_PART))) : 0,
8585
sideBarWidth: this._layoutService.isVisible(Parts.SIDEBAR_PART) ? dom.getTotalWidth(assertIsDefined(this._layoutService.getContainer(mainWindow, Parts.SIDEBAR_PART))) : 0,
8686
statusBarHeight: this._layoutService.isVisible(Parts.STATUSBAR_PART, mainWindow) ? dom.getTotalHeight(assertIsDefined(this._layoutService.getContainer(mainWindow, Parts.STATUSBAR_PART))) : 0,
87-
windowBorder: this._layoutService.hasWindowBorder(),
88-
windowBorderRadius: this._layoutService.getWindowBorderRadius()
87+
windowBorder: this._layoutService.hasMainWindowBorder(),
88+
windowBorderRadius: this._layoutService.getMainWindowBorderRadius()
8989
}
9090
});
9191
}

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export class BrowserHostService extends Disposable implements IHostService {
151151
Event.map(focusTracker.onDidFocus, () => this.hasFocus, disposables),
152152
Event.map(focusTracker.onDidBlur, () => this.hasFocus, disposables),
153153
Event.map(visibilityTracker.event, () => this.hasFocus, disposables),
154+
Event.map(this.onDidChangeActiveWindow, () => this.hasFocus, disposables),
154155
), undefined, disposables)(focus => emitter.fire(focus));
155156
}, { window: mainWindow, disposables: this._store }));
156157

src/vs/workbench/services/host/electron-sandbox/nativeHostService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class WorkbenchHostService extends Disposable implements IHostService {
4545
readonly onDidChangeFocus = Event.latch(
4646
Event.any(
4747
Event.map(Event.filter(this.nativeHostService.onDidFocusMainOrAuxiliaryWindow, id => hasWindow(id), this._store), () => this.hasFocus, this._store),
48-
Event.map(Event.filter(this.nativeHostService.onDidBlurMainOrAuxiliaryWindow, id => hasWindow(id), this._store), () => this.hasFocus, this._store)
48+
Event.map(Event.filter(this.nativeHostService.onDidBlurMainOrAuxiliaryWindow, id => hasWindow(id), this._store), () => this.hasFocus, this._store),
49+
Event.map(this.onDidChangeActiveWindow, () => this.hasFocus, this._store)
4950
), undefined, this._store
5051
);
5152

src/vs/workbench/services/layout/browser/layoutService.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,14 @@ export interface IWorkbenchLayoutService extends ILayoutService {
200200
toggleMaximizedPanel(): void;
201201

202202
/**
203-
* Returns true if the window has a border.
203+
* Returns true if the main window has a border.
204204
*/
205-
hasWindowBorder(): boolean;
205+
hasMainWindowBorder(): boolean;
206206

207207
/**
208-
* Returns the window border width.
208+
* Returns the main window border radius if any.
209209
*/
210-
getWindowBorderWidth(): number;
211-
212-
/**
213-
* Returns the window border radius if any.
214-
*/
215-
getWindowBorderRadius(): string | undefined;
210+
getMainWindowBorderRadius(): string | undefined;
216211

217212
/**
218213
* Returns true if the panel is maximized.

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,8 @@ export class TestLayoutService implements IWorkbenchLayoutService {
618618
whenRestored: Promise<void> = Promise.resolve(undefined);
619619
hasFocus(_part: Parts): boolean { return false; }
620620
focusPart(_part: Parts): void { }
621-
hasWindowBorder(): boolean { return false; }
622-
getWindowBorderWidth(): number { return 0; }
623-
getWindowBorderRadius(): string | undefined { return undefined; }
621+
hasMainWindowBorder(): boolean { return false; }
622+
getMainWindowBorderRadius(): string | undefined { return undefined; }
624623
isVisible(_part: Parts): boolean { return true; }
625624
getContainer(): HTMLElement { return null!; }
626625
isTitleBarHidden(): boolean { return false; }

0 commit comments

Comments
 (0)