Skip to content
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

Add window.nonNativeFullscreen option for macOS #55267

Merged
merged 14 commits into from Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 57 additions & 8 deletions src/vs/code/electron-main/window.ts
Expand Up @@ -143,6 +143,10 @@ export class CodeWindow implements ICodeWindow {

const windowConfig = this.configurationService.getValue<IWindowSettings>('window');

if (isMacintosh && !this.useNativeFullScreen()) {
options.fullscreenable = false; // enables simple fullscreen mode
}

if (isMacintosh) {
options.acceptFirstMouse = true; // enabled by default

Expand Down Expand Up @@ -197,7 +201,7 @@ export class CodeWindow implements ICodeWindow {
this._win.maximize();

if (this.windowState.mode === WindowMode.Fullscreen) {
this._win.setFullScreen(true);
this.setFullScreen(true);
}

if (!this._win.isVisible()) {
Expand Down Expand Up @@ -372,6 +376,14 @@ export class CodeWindow implements ICodeWindow {
this._lastFocusTime = Date.now();
});

// Simple fullscreen doesn't resize automatically when the resolution changes
screen.on('display-metrics-changed', () => {
if (isMacintosh && this.isFullScreen() && !this.useNativeFullScreen()) {
this.setFullScreen(false);
this.setFullScreen(true);
}
});

// Window (Un)Maximize
this._win.on('maximize', (e) => {
if (this.currentConfig) {
Expand Down Expand Up @@ -558,7 +570,7 @@ export class CodeWindow implements ICodeWindow {
}

// Set fullscreen state
windowConfiguration.fullscreen = this._win.isFullScreen();
windowConfiguration.fullscreen = this.isFullScreen();

// Set Accessibility Config
let autoDetectHighContrast = true;
Expand Down Expand Up @@ -612,7 +624,7 @@ export class CodeWindow implements ICodeWindow {
}

// fullscreen gets special treatment
if (this._win.isFullScreen()) {
if (this.isFullScreen()) {
const display = screen.getDisplayMatching(this.getBounds());

const defaultState = defaultWindowState();
Expand Down Expand Up @@ -778,15 +790,52 @@ export class CodeWindow implements ICodeWindow {
}

toggleFullScreen(): void {
const willBeFullScreen = !this._win.isFullScreen();
this.setFullScreen(!this.isFullScreen());
}

// set fullscreen flag on window
this._win.setFullScreen(willBeFullScreen);
private setFullScreen(fullscreen: boolean): void {

// respect configured menu bar visibility or default to toggle if not set
// Set fullscreen state
if (this.useNativeFullScreen()) {
this.setNativeFullScreen(fullscreen);
} else {
this.setSimpleFullScreen(fullscreen);
}

// Events
this.sendWhenReady(fullscreen ? 'vscode:enterFullScreen' : 'vscode:leaveFullScreen');

// Respect configured menu bar visibility or default to toggle if not set
this.setMenuBarVisibility(this.currentMenuBarVisibility, false);
}

isFullScreen(): boolean {
return this._win.isFullScreen() || this._win.isSimpleFullScreen();
}

private setNativeFullScreen(fullscreen: boolean): void {
if (this._win.isSimpleFullScreen()) {
this._win.setSimpleFullScreen(false);
}

this._win.setFullScreen(fullscreen);
}

private setSimpleFullScreen(fullscreen: boolean): void {
if (this._win.isFullScreen()) {
this._win.setFullScreen(false);
}

this._win.setSimpleFullScreen(fullscreen);
this._win.webContents.focus(); // workaround issue where focus is not going into window
}

private useNativeFullScreen(): boolean {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');

return windowConfig && windowConfig.nativeFullscreen !== false;
}

private getMenuBarVisibility(): MenuBarVisibility {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
if (!windowConfig || !windowConfig.menuBarVisibility) {
Expand Down Expand Up @@ -827,7 +876,7 @@ export class CodeWindow implements ICodeWindow {
}

private doSetMenuBarVisibility(visibility: MenuBarVisibility): void {
const isFullscreen = this._win.isFullScreen();
const isFullscreen = this.isFullScreen();

switch (visibility) {
case ('default'):
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/windows/common/windows.ts
Expand Up @@ -236,6 +236,7 @@ export interface IWindowSettings {
menuBarVisibility: MenuBarVisibility;
newWindowDimensions: 'default' | 'inherit' | 'maximized' | 'fullscreen';
nativeTabs: boolean;
nativeFullscreen: boolean;
enableMenuBarMnemonics: boolean;
closeWhenEmpty: boolean;
clickThroughInactive: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/windows/electron-main/windows.ts
Expand Up @@ -60,6 +60,7 @@ export interface ICodeWindow {
sendWhenReady(channel: string, ...args: any[]): void;

toggleFullScreen(): void;
isFullScreen(): boolean;
hasHiddenTitleBarStyle(): boolean;
setRepresentedFilename(name: string): void;
getRepresentedFilename(): string;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/windows/electron-main/windowsService.ts
Expand Up @@ -136,7 +136,7 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable

if (codeWindow) {
const contents = codeWindow.win.webContents;
if (isMacintosh && codeWindow.hasHiddenTitleBarStyle() && !codeWindow.win.isFullScreen() && !contents.isDevToolsOpened()) {
if (isMacintosh && codeWindow.hasHiddenTitleBarStyle() && !codeWindow.isFullScreen() && !contents.isDevToolsOpened()) {
contents.openDevTools({ mode: 'undocked' }); // due to https://github.com/electron/electron/issues/3647
} else {
contents.toggleDevTools();
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Expand Up @@ -818,6 +818,12 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('window.nativeTabs', "Enables macOS Sierra window tabs. Note that changes require a full restart to apply and that native tabs will disable a custom title bar style if configured."),
'included': isMacintosh && parseFloat(os.release()) >= 16 // Minimum: macOS Sierra (10.12.x = darwin 16.x)
},
'window.nativeFullscreen': {
'type': 'boolean',
'default': true,
'description': nls.localize('window.nativeFullscreen', "Prefer native full-screen. Disable this option to prevent macOS from creating a new space when going full-screen."),
'included': isMacintosh
},
'window.clickThroughInactive': {
'type': 'boolean',
'default': true,
Expand Down
24 changes: 18 additions & 6 deletions src/vs/workbench/electron-browser/shell.ts
Expand Up @@ -87,7 +87,7 @@ import { NotificationService } from 'vs/workbench/services/notification/common/n
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { DialogService } from 'vs/workbench/services/dialogs/electron-browser/dialogService';
import { DialogChannel } from 'vs/platform/dialogs/node/dialogIpc';
import { EventType, addDisposableListener, addClass } from 'vs/base/browser/dom';
import { EventType, addDisposableListener, addClass, scheduleAtNextAnimationFrame } from 'vs/base/browser/dom';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { OpenerService } from 'vs/editor/browser/services/openerService';
import { SearchHistoryService } from 'vs/workbench/services/search/node/searchHistoryService';
Expand Down Expand Up @@ -517,13 +517,25 @@ export class WorkbenchShell extends Disposable {
}

private registerListeners(): void {
this._register(addDisposableListener(window, EventType.RESIZE, e => this.onWindowResize(e, true)));
}

// Resize
this._register(addDisposableListener(window, EventType.RESIZE, e => {
if (e.target === window) {
this.layout();
private onWindowResize(e: any, retry: boolean): void {
if (e.target === window) {
if (window.document && window.document.body && window.document.body.clientWidth === 0) {
// TODO@Ben this is an electron issue on macOS when simple fullscreen is enabled
// where for some reason the window clientWidth is reported as 0 when switching
// between simple fullscreen and normal screen. In that case we schedule the layout
// call at the next animation frame once, in the hope that the dimensions are
// proper then.
if (retry) {
scheduleAtNextAnimationFrame(() => this.onWindowResize(e, false));
}
return;
}
}));

this.layout();
}
}

onUnexpectedError(error: any): void {
Expand Down
Expand Up @@ -32,6 +32,7 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo

private titleBarStyle: 'native' | 'custom';
private nativeTabs: boolean;
private nativeFullscreen: boolean;
private clickThroughInactive: boolean;
private updateChannel: string;
private enableCrashReporter: boolean;
Expand Down Expand Up @@ -86,6 +87,12 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo
changed = true;
}

// macOS: Native fullscreen
if (isMacintosh && config.window && typeof config.window.nativeFullscreen === 'boolean' && config.window.nativeFullscreen !== this.nativeFullscreen) {
this.nativeFullscreen = config.window.nativeFullscreen;
changed = true;
}

// macOS: Click through (accept first mouse)
if (isMacintosh && config.window && typeof config.window.clickThroughInactive === 'boolean' && config.window.clickThroughInactive !== this.clickThroughInactive) {
this.clickThroughInactive = config.window.clickThroughInactive;
Expand Down