Skip to content

Commit

Permalink
fixup! remove macOS workaround for devtools with custom titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Nov 23, 2020
1 parent 0151976 commit c21f001
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
options.tabbingIdentifier = product.nameShort; // this opts in to sierra tabs
}

const useCustomTitleStyle = getTitleBarStyle(this.configurationService, this.environmentService, !!config.extensionDevelopmentPath) === 'custom';
const useCustomTitleStyle = getTitleBarStyle(this.configurationService) === 'custom';
if (useCustomTitleStyle) {
options.titleBarStyle = 'hidden';
this.hiddenTitleBarStyle = true;
Expand Down Expand Up @@ -1145,7 +1145,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
}

private getMenuBarVisibility(): MenuBarVisibility {
let menuBarVisibility = getMenuBarVisibility(this.configurationService, this.environmentService, !!this.currentConfig?.extensionDevelopmentPath);
let menuBarVisibility = getMenuBarVisibility(this.configurationService);
if (['visible', 'toggle', 'hidden'].indexOf(menuBarVisibility) < 0) {
menuBarVisibility = 'default';
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/menubar/electron-main/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Menubar {
this.menubarMenus = Object.create(null);
this.keybindings = Object.create(null);

if (isMacintosh || getTitleBarStyle(this.configurationService, this.environmentService) === 'native') {
if (isMacintosh || getTitleBarStyle(this.configurationService) === 'native') {
this.restoreCachedMenubarData();
}

Expand Down Expand Up @@ -416,7 +416,7 @@ export class Menubar {

private shouldDrawMenu(menuId: string): boolean {
// We need to draw an empty menu to override the electron default
if (!isMacintosh && getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if (!isMacintosh && getTitleBarStyle(this.configurationService) === 'custom') {
return false;
}

Expand Down
12 changes: 3 additions & 9 deletions src/vs/platform/windows/common/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import { isMacintosh, isLinux, isWeb, IProcessEnvironment } from 'vs/base/common/platform';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
Expand Down Expand Up @@ -85,8 +84,8 @@ export function isFileToOpen(uriToOpen: IWindowOpenable): uriToOpen is IFileToOp

export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden' | 'compact';

export function getMenuBarVisibility(configurationService: IConfigurationService, environment: IEnvironmentService, isExtensionDevelopment = environment.isExtensionDevelopment): MenuBarVisibility {
const titleBarStyle = getTitleBarStyle(configurationService, environment, isExtensionDevelopment);
export function getMenuBarVisibility(configurationService: IConfigurationService): MenuBarVisibility {
const titleBarStyle = getTitleBarStyle(configurationService);
const menuBarVisibility = configurationService.getValue<MenuBarVisibility>('window.menuBarVisibility');

if (titleBarStyle === 'native' && menuBarVisibility === 'compact') {
Expand Down Expand Up @@ -119,18 +118,13 @@ export interface IWindowSettings {
enableExperimentalProxyLoginDialog: boolean;
}

export function getTitleBarStyle(configurationService: IConfigurationService, environment: IEnvironmentService, isExtensionDevelopment = environment.isExtensionDevelopment): 'native' | 'custom' {
export function getTitleBarStyle(configurationService: IConfigurationService): 'native' | 'custom' {
if (isWeb) {
return 'custom';
}

const configuration = configurationService.getValue<IWindowSettings | undefined>('window');

const isDev = !environment.isBuilt || isExtensionDevelopment;
if (isMacintosh && isDev) {
return 'native'; // not enabled when developing due to https://github.com/electron/electron/issues/3647
}

if (configuration) {
const useNativeTabs = isMacintosh && configuration.nativeTabs === true;
if (useNativeTabs) {
Expand Down
6 changes: 2 additions & 4 deletions src/vs/workbench/browser/actions/layoutActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/co
import { InEditorZenModeContext, IsCenteredLayoutContext, EditorAreaVisibleContext } from 'vs/workbench/common/editor';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { SideBarVisibleContext } from 'vs/workbench/common/viewlet';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IViewDescriptorService, IViewsService, FocusedViewContext, ViewContainerLocation, IViewDescriptor } from 'vs/workbench/common/views';
import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { INotificationService } from 'vs/platform/notification/common/notification';
Expand Down Expand Up @@ -419,14 +418,13 @@ export class ToggleMenuBarAction extends Action {
constructor(
id: string,
label: string,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IEnvironmentService private readonly environmentService: IEnvironmentService
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super(id, label);
}

run(): Promise<void> {
let currentVisibilityValue = getMenuBarVisibility(this.configurationService, this.environmentService);
let currentVisibilityValue = getMenuBarVisibility(this.configurationService);
if (typeof currentVisibilityValue !== 'string') {
currentVisibilityValue = 'default';
}
Expand Down
12 changes: 6 additions & 6 deletions src/vs/workbench/browser/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this._register(addDisposableListener(this.container, EventType.SCROLL, () => this.container.scrollTop = 0));

// Menubar visibility changes
if ((isWindows || isLinux || isWeb) && getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if ((isWindows || isLinux || isWeb) && getTitleBarStyle(this.configurationService) === 'custom') {
this._register(this.titleService.onMenubarVisibilityChange(visible => this.onMenubarToggled(visible)));
}

Expand Down Expand Up @@ -345,7 +345,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this.workbenchGrid.edgeSnapping = this.state.fullscreen;

// Changing fullscreen state of the window has an impact on custom title bar visibility, so we need to update
if (getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if (getTitleBarStyle(this.configurationService) === 'custom') {
// Propagate to grid
this.workbenchGrid.setViewVisible(this.titleBarPartView, this.isVisible(Parts.TITLEBAR_PART));

Expand Down Expand Up @@ -394,7 +394,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}

// Menubar visibility
const newMenubarVisibility = getMenuBarVisibility(this.configurationService, this.environmentService);
const newMenubarVisibility = getMenuBarVisibility(this.configurationService);
this.setMenubarVisibility(newMenubarVisibility, !!skipLayout);

// Centered Layout
Expand Down Expand Up @@ -438,7 +438,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
}

private updateWindowBorder(skipLayout: boolean = false) {
if (isWeb || getTitleBarStyle(this.configurationService, this.environmentService) !== 'custom') {
if (isWeb || getTitleBarStyle(this.configurationService) !== 'custom') {
return;
}

Expand Down Expand Up @@ -482,7 +482,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
this.state.fullscreen = isFullscreen();

// Menubar visibility
this.state.menuBar.visibility = getMenuBarVisibility(this.configurationService, this.environmentService);
this.state.menuBar.visibility = getMenuBarVisibility(this.configurationService);

// Activity bar visibility
this.state.activityBar.hidden = !this.configurationService.getValue<string>(Settings.ACTIVITYBAR_VISIBLE);
Expand Down Expand Up @@ -878,7 +878,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
isVisible(part: Parts): boolean {
switch (part) {
case Parts.TITLEBAR_PART:
if (getTitleBarStyle(this.configurationService, this.environmentService) === 'native') {
if (getTitleBarStyle(this.configurationService) === 'native') {
return false;
} else if (!this.state.fullscreen && !isWeb) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class MenuActivityActionViewItem extends ActivityActionViewItem {
const menu = disposables.add(this.menuService.createMenu(this.menuId, this.contextKeyService));
const actions = await this.resolveActions(menu, disposables);

const isUsingCustomMenu = isWeb || (getTitleBarStyle(this.configurationService, this.environmentService) !== 'native' && !isMacintosh); // see #40262
const isUsingCustomMenu = isWeb || (getTitleBarStyle(this.configurationService) !== 'native' && !isMacintosh); // see #40262
const position = this.configurationService.getValue('workbench.sideBar.location');

this.contextMenuService.showContextMenu({
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/activitybar/activitybarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}

// Menu
const menuBarVisibility = getMenuBarVisibility(this.configurationService, this.environmentService);
const menuBarVisibility = getMenuBarVisibility(this.configurationService);
if (menuBarVisibility === 'compact' || (menuBarVisibility === 'hidden' && isWeb)) {
actions.push(this.instantiationService.createInstance(ToggleMenuBarAction, ToggleMenuBarAction.ID, menuBarVisibility === 'compact' ? nls.localize('hideMenu', "Hide Menu") : nls.localize('showMenu', "Show Menu")));
}
Expand Down Expand Up @@ -265,7 +265,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
// Register for configuration changes
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('window.menuBarVisibility')) {
if (getMenuBarVisibility(this.configurationService, this.environmentService) === 'compact') {
if (getMenuBarVisibility(this.configurationService) === 'compact') {
this.installMenubar();
} else {
this.uninstallMenubar();
Expand Down Expand Up @@ -463,7 +463,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}

// Install menubar if compact
if (getMenuBarVisibility(this.configurationService, this.environmentService) === 'compact') {
if (getMenuBarVisibility(this.configurationService) === 'compact') {
this.installMenubar();
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/titlebar/menubarControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export abstract class MenubarControl extends Disposable {
}

const hasBeenNotified = this.storageService.getBoolean('menubar/accessibleMenubarNotified', StorageScope.GLOBAL, false);
const usingCustomMenubar = getTitleBarStyle(this.configurationService, this.environmentService) === 'custom';
const usingCustomMenubar = getTitleBarStyle(this.configurationService) === 'custom';

if (hasBeenNotified || usingCustomMenubar || !this.accessibilityService.isScreenReaderOptimized()) {
return;
Expand Down Expand Up @@ -484,7 +484,7 @@ export class CustomMenubarControl extends MenubarControl {
}

private get currentMenubarVisibility(): MenuBarVisibility {
return getMenuBarVisibility(this.configurationService, this.environmentService);
return getMenuBarVisibility(this.configurationService);
}

private get currentDisableMenuBarAltFocus(): boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class TitlebarPart extends Part implements ITitleService {

this.contextMenu = this._register(menuService.createMenu(MenuId.TitleBarContext, contextKeyService));

this.titleBarStyle = getTitleBarStyle(this.configurationService, this.environmentService);
this.titleBarStyle = getTitleBarStyle(this.configurationService);

this.registerListeners();
}
Expand Down Expand Up @@ -461,13 +461,13 @@ export class TitlebarPart extends Part implements ITitleService {
}

protected get currentMenubarVisibility(): MenuBarVisibility {
return getMenuBarVisibility(this.configurationService, this.environmentService);
return getMenuBarVisibility(this.configurationService);
}

updateLayout(dimension: Dimension): void {
this.lastLayoutDimensions = dimension;

if (getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if (getTitleBarStyle(this.configurationService) === 'custom') {
// Only prevent zooming behavior on macOS or when the menubar is not visible
if ((!isWeb && isMacintosh) || this.currentMenubarVisibility === 'hidden') {
this.title.style.zoom = `${1 / getZoomFactor()}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class TitlebarPart extends BrowserTitleBarPart {
updateLayout(dimension: DOM.Dimension): void {
this.lastLayoutDimensions = dimension;

if (getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if (getTitleBarStyle(this.configurationService) === 'custom') {
// Only prevent zooming behavior on macOS or when the menubar is not visible
if (isMacintosh || this.currentMenubarVisibility === 'hidden') {
this.title.style.zoom = `${1 / getZoomFactor()}`;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/electron-sandbox/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class NativeWindow extends Disposable {
}

// Maximize/Restore on doubleclick (for macOS custom title)
if (isMacintosh && getTitleBarStyle(this.configurationService, this.environmentService) === 'custom') {
if (isMacintosh && getTitleBarStyle(this.configurationService) === 'custom') {
const titlePart = assertIsDefined(this.layoutService.getContainer(Parts.TITLEBAR_PART));

this._register(DOM.addDisposableListener(titlePart, DOM.EventType.DBLCLICK, e => {
Expand Down Expand Up @@ -416,7 +416,7 @@ export class NativeWindow extends Disposable {
this.customTitleContextMenuDisposable.clear();

// Provide new menu if a file is opened and we are on a custom title
if (!filePath || getTitleBarStyle(this.configurationService, this.environmentService) !== 'custom') {
if (!filePath || getTitleBarStyle(this.configurationService) !== 'custom') {
return;
}

Expand Down Expand Up @@ -448,7 +448,7 @@ export class NativeWindow extends Disposable {
private create(): void {

// Native menu controller
if (isMacintosh || getTitleBarStyle(this.configurationService, this.environmentService) === 'native') {
if (isMacintosh || getTitleBarStyle(this.configurationService) === 'native') {
this._register(this.instantiationService.createInstance(NativeMenubarControl));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ContextMenuService extends Disposable implements IContextMenuServic
super();

// Custom context menu: Linux/Windows if custom title is enabled
if (!isMacintosh && getTitleBarStyle(configurationService, environmentService) === 'custom') {
if (!isMacintosh && getTitleBarStyle(configurationService) === 'custom') {
this.impl = new HTMLContextMenuService(telemetryService, notificationService, contextViewService, keybindingService, themeService);
}

Expand Down

0 comments on commit c21f001

Please sign in to comment.