Skip to content

Commit 651391e

Browse files
authored
Aux window: fullscreen windows show custom title bar (fix microsoft#201297) (microsoft#201332)
1 parent 86d1a94 commit 651391e

File tree

16 files changed

+100
-18
lines changed

16 files changed

+100
-18
lines changed

src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IAuxiliaryWindowsMainService {
1717

1818
readonly onDidMaximizeWindow: Event<IAuxiliaryWindow>;
1919
readonly onDidUnmaximizeWindow: Event<IAuxiliaryWindow>;
20+
readonly onDidChangeFullScreen: Event<IAuxiliaryWindow>;
2021
readonly onDidTriggerSystemContextMenu: Event<{ readonly window: IAuxiliaryWindow; readonly x: number; readonly y: number }>;
2122

2223
createWindow(): BrowserWindowConstructorOptions;

src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindowsMainService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class AuxiliaryWindowsMainService extends Disposable implements IAuxiliar
2424
private readonly _onDidUnmaximizeWindow = this._register(new Emitter<IAuxiliaryWindow>());
2525
readonly onDidUnmaximizeWindow = this._onDidUnmaximizeWindow.event;
2626

27+
private readonly _onDidChangeFullScreen = this._register(new Emitter<IAuxiliaryWindow>());
28+
readonly onDidChangeFullScreen = this._onDidChangeFullScreen.event;
29+
2730
private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ window: IAuxiliaryWindow; x: number; y: number }>());
2831
readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event;
2932

@@ -85,6 +88,8 @@ export class AuxiliaryWindowsMainService extends Disposable implements IAuxiliar
8588

8689
disposables.add(auxiliaryWindow.onDidMaximize(() => this._onDidMaximizeWindow.fire(auxiliaryWindow)));
8790
disposables.add(auxiliaryWindow.onDidUnmaximize(() => this._onDidUnmaximizeWindow.fire(auxiliaryWindow)));
91+
disposables.add(auxiliaryWindow.onDidEnterFullScreen(() => this._onDidChangeFullScreen.fire(auxiliaryWindow)));
92+
disposables.add(auxiliaryWindow.onDidLeaveFullScreen(() => this._onDidChangeFullScreen.fire(auxiliaryWindow)));
8893
disposables.add(auxiliaryWindow.onDidTriggerSystemContextMenu(({ x, y }) => this._onDidTriggerSystemContextMenu.fire({ window: auxiliaryWindow, x, y })));
8994

9095
Event.once(auxiliaryWindow.onDidClose)(() => disposables.dispose());

src/vs/platform/native/common/native.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export interface ICommonNativeHostService {
5353
readonly onDidFocusMainWindow: Event<number>;
5454
readonly onDidBlurMainWindow: Event<number>;
5555

56+
readonly onDidChangeWindowFullScreen: Event<number>;
57+
5658
readonly onDidFocusMainOrAuxiliaryWindow: Event<number>;
5759
readonly onDidBlurMainOrAuxiliaryWindow: Event<number>;
5860

src/vs/platform/native/electron-main/nativeHostMainService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
9292
Event.filter(Event.map(this.auxiliaryWindowsMainService.onDidUnmaximizeWindow, window => window.id), windowId => !!this.auxiliaryWindowsMainService.getWindowById(windowId))
9393
);
9494

95+
readonly onDidChangeWindowFullScreen = Event.any(
96+
Event.map(this.windowsMainService.onDidChangeFullScreen, window => window.id),
97+
Event.map(this.auxiliaryWindowsMainService.onDidChangeFullScreen, window => window.id)
98+
);
99+
95100
readonly onDidBlurMainWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-blur', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
96101
readonly onDidFocusMainWindow = Event.any(
97102
Event.map(Event.filter(Event.map(this.windowsMainService.onDidChangeWindowsCount, () => this.windowsMainService.getLastActiveWindow()), window => !!window), window => window!.id),

src/vs/platform/window/electron-main/window.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface IBaseWindow extends IDisposable {
1818
readonly onDidMaximize: Event<void>;
1919
readonly onDidUnmaximize: Event<void>;
2020
readonly onDidTriggerSystemContextMenu: Event<{ readonly x: number; readonly y: number }>;
21+
readonly onDidEnterFullScreen: Event<void>;
22+
readonly onDidLeaveFullScreen: Event<void>;
2123
readonly onDidClose: Event<void>;
2224

2325
readonly id: number;

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
9898
private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ x: number; y: number }>());
9999
readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event;
100100

101+
private readonly _onDidEnterFullScreen = this._register(new Emitter<void>());
102+
readonly onDidEnterFullScreen = this._onDidEnterFullScreen.event;
103+
104+
private readonly _onDidLeaveFullScreen = this._register(new Emitter<void>());
105+
readonly onDidLeaveFullScreen = this._onDidLeaveFullScreen.event;
106+
101107
//#endregion
102108

103109
abstract readonly id: number;
@@ -121,6 +127,8 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
121127
this._register(Event.fromNodeEventEmitter(win, 'focus')(() => {
122128
this._lastFocusTime = Date.now();
123129
}));
130+
this._register(Event.fromNodeEventEmitter(this._win, 'enter-full-screen')(() => this._onDidEnterFullScreen.fire()));
131+
this._register(Event.fromNodeEventEmitter(this._win, 'leave-full-screen')(() => this._onDidLeaveFullScreen.fire()));
124132

125133
// Sheet Offsets
126134
const useCustomTitleStyle = getTitleBarStyle(this.configurationService) === 'custom';
@@ -670,14 +678,14 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
670678
}));
671679

672680
// Window Fullscreen
673-
this._register(Event.fromNodeEventEmitter(this._win, 'enter-full-screen')(() => {
681+
this._register(this.onDidEnterFullScreen(() => {
674682
this.sendWhenReady('vscode:enterFullScreen', CancellationToken.None);
675683

676684
this.joinNativeFullScreenTransition?.complete();
677685
this.joinNativeFullScreenTransition = undefined;
678686
}));
679687

680-
this._register(Event.fromNodeEventEmitter(this._win, 'leave-full-screen')(() => {
688+
this._register(this.onDidLeaveFullScreen(() => {
681689
this.sendWhenReady('vscode:leaveFullScreen', CancellationToken.None);
682690

683691
this.joinNativeFullScreenTransition?.complete();

src/vs/platform/windows/electron-main/windows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface IWindowsMainService {
3232
readonly onDidSignalReadyWindow: Event<ICodeWindow>;
3333
readonly onDidMaximizeWindow: Event<ICodeWindow>;
3434
readonly onDidUnmaximizeWindow: Event<ICodeWindow>;
35+
readonly onDidChangeFullScreen: Event<ICodeWindow>;
3536
readonly onDidTriggerSystemContextMenu: Event<{ readonly window: ICodeWindow; readonly x: number; readonly y: number }>;
3637
readonly onDidDestroyWindow: Event<ICodeWindow>;
3738

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
198198
private readonly _onDidUnmaximizeWindow = this._register(new Emitter<ICodeWindow>());
199199
readonly onDidUnmaximizeWindow = this._onDidUnmaximizeWindow.event;
200200

201+
private readonly _onDidChangeFullScreen = this._register(new Emitter<ICodeWindow>());
202+
readonly onDidChangeFullScreen = this._onDidChangeFullScreen.event;
203+
201204
private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ window: ICodeWindow; x: number; y: number }>());
202205
readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event;
203206

@@ -1498,6 +1501,8 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
14981501
disposables.add(Event.once(createdWindow.onDidDestroy)(() => this.onWindowDestroyed(createdWindow)));
14991502
disposables.add(createdWindow.onDidMaximize(() => this._onDidMaximizeWindow.fire(createdWindow)));
15001503
disposables.add(createdWindow.onDidUnmaximize(() => this._onDidUnmaximizeWindow.fire(createdWindow)));
1504+
disposables.add(createdWindow.onDidEnterFullScreen(() => this._onDidChangeFullScreen.fire(createdWindow)));
1505+
disposables.add(createdWindow.onDidLeaveFullScreen(() => this._onDidChangeFullScreen.fire(createdWindow)));
15011506
disposables.add(createdWindow.onDidTriggerSystemContextMenu(({ x, y }) => this._onDidTriggerSystemContextMenu.fire({ window: createdWindow, x, y })));
15021507

15031508
const webContents = assertIsDefined(createdWindow.win?.webContents);

src/vs/platform/windows/test/electron-main/windowsFinder.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ suite('WindowsFinder', () => {
4040
onDidSignalReady: Event<void> = Event.None;
4141
onDidClose: Event<void> = Event.None;
4242
onDidDestroy: Event<void> = Event.None;
43+
onDidEnterFullScreen: Event<void> = Event.None;
44+
onDidLeaveFullScreen: Event<void> = Event.None;
4345
whenClosedOrLoaded: Promise<void> = Promise.resolve();
4446
id: number = -1;
4547
win: Electron.BrowserWindow = null!;

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { hide, show } from 'vs/base/browser/dom';
6+
import { detectFullscreen, hide, show } from 'vs/base/browser/dom';
77
import { Emitter, Event } from 'vs/base/common/event';
88
import { DisposableStore } from 'vs/base/common/lifecycle';
99
import { isNative } from 'vs/base/common/platform';
@@ -39,7 +39,8 @@ export class AuxiliaryEditorPart {
3939
@IConfigurationService private readonly configurationService: IConfigurationService,
4040
@IStatusbarService private readonly statusbarService: IStatusbarService,
4141
@ITitleService private readonly titleService: ITitleService,
42-
@IEditorService private readonly editorService: IEditorService
42+
@IEditorService private readonly editorService: IEditorService,
43+
@IHostService private readonly hostService: IHostService
4344
) {
4445
}
4546

@@ -52,7 +53,7 @@ export class AuxiliaryEditorPart {
5253
editorPartHeightOffset += statusbarPart.height;
5354
}
5455

55-
if (titlebarPart) {
56+
if (titlebarPart && titlebarPartVisible) {
5657
editorPartHeightOffset += titlebarPart.height;
5758
}
5859

@@ -95,10 +96,31 @@ export class AuxiliaryEditorPart {
9596

9697
// Titlebar
9798
let titlebarPart: IAuxiliaryTitlebarPart | undefined = undefined;
99+
let titlebarPartVisible = false;
98100
const useCustomTitle = isNative && getTitleBarStyle(this.configurationService) === 'custom'; // custom title in aux windows only enabled in native
99101
if (useCustomTitle) {
100102
titlebarPart = disposables.add(this.titleService.createAuxiliaryTitlebarPart(auxiliaryWindow.container, editorPart));
103+
titlebarPartVisible = true;
104+
101105
disposables.add(titlebarPart.onDidChange(() => updateEditorPartHeight(true)));
106+
107+
disposables.add(this.hostService.onDidChangeFullScreen(windowId => {
108+
if (windowId !== auxiliaryWindow.window.vscodeWindowId) {
109+
return; // ignore all but our window
110+
}
111+
112+
// Make sure to hide the custom title when we enter
113+
// fullscren mode and show it when we lave it.
114+
115+
const fullscreen = detectFullscreen(auxiliaryWindow.window);
116+
const oldTitlebarPartVisible = titlebarPartVisible;
117+
titlebarPartVisible = !fullscreen;
118+
if (titlebarPart && oldTitlebarPartVisible !== titlebarPartVisible) {
119+
titlebarPart.container.style.display = titlebarPartVisible ? '' : 'none';
120+
121+
updateEditorPartHeight(true);
122+
}
123+
}));
102124
} else {
103125
disposables.add(this.instantiationService.createInstance(WindowTitle, auxiliaryWindow.window, editorPart));
104126
}
@@ -132,9 +154,7 @@ export class AuxiliaryEditorPart {
132154
// Layout
133155
disposables.add(auxiliaryWindow.onDidLayout(dimension => {
134156
const titlebarPartHeight = titlebarPart?.height ?? 0;
135-
if (titlebarPart) {
136-
titlebarPart.layout(dimension.width, titlebarPartHeight, 0, 0);
137-
}
157+
titlebarPart?.layout(dimension.width, titlebarPartHeight, 0, 0);
138158

139159
const editorPartHeight = dimension.height - computeEditorPartHeightOffset();
140160
editorPart.layout(dimension.width, editorPartHeight, titlebarPartHeight, 0);

0 commit comments

Comments
 (0)