From a8fb36fc284749ef7b9d8e366eaac4bbc791e52d Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 25 May 2017 09:44:01 +0200 Subject: [PATCH] How to configure a window (also for reload case)? (fixes #27192) --- src/vs/code/electron-main/menus.ts | 20 +++++- src/vs/code/electron-main/window.ts | 10 +-- src/vs/code/electron-main/windows.ts | 84 +---------------------- src/vs/code/node/keyboard.ts | 70 +++++++++++++++++++ src/vs/workbench/electron-browser/main.ts | 10 ++- 5 files changed, 100 insertions(+), 94 deletions(-) create mode 100644 src/vs/code/node/keyboard.ts diff --git a/src/vs/code/electron-main/menus.ts b/src/vs/code/electron-main/menus.ts index 91ccab243c9..249722e754c 100644 --- a/src/vs/code/electron-main/menus.ts +++ b/src/vs/code/electron-main/menus.ts @@ -9,7 +9,7 @@ import * as nls from 'vs/nls'; import { isMacintosh, isLinux, isWindows, language } from 'vs/base/common/platform'; import * as arrays from 'vs/base/common/arrays'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem } from 'electron'; +import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem, BrowserWindow } from 'electron'; import { OpenContext } from 'vs/code/common/windows'; import { IWindowsMainService } from 'vs/code/electron-main/windows'; import { VSCodeWindow } from 'vs/code/electron-main/window'; @@ -908,7 +908,7 @@ export class VSCodeMenu { label: this.mnemonicLabel(nls.localize({ key: 'miAccessibilityOptions', comment: ['&& denotes a mnemonic'] }, "Accessibility &&Options")), accelerator: null, click: () => { - this.windowsService.openAccessibilityOptions(); + this.openAccessibilityOptions(); } }, false)); @@ -974,6 +974,22 @@ export class VSCodeMenu { } } + private openAccessibilityOptions(): void { + let win = new BrowserWindow({ + alwaysOnTop: true, + skipTaskbar: true, + resizable: false, + width: 450, + height: 300, + show: true, + title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options") + }); + + win.setMenuBarVisibility(false); + + win.loadURL('chrome://accessibility'); + } + private getUpdateMenuItems(): Electron.MenuItem[] { switch (this.updateService.state) { case UpdateState.Uninitialized: diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 7cd1f647083..4b1840c8642 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -22,7 +22,7 @@ import product from 'vs/platform/node/product'; import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http'; import { IWindowSettings, MenuBarVisibility } from 'vs/platform/windows/common/windows'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; - +import { KeyboardLayoutMonitor } from "vs/code/node/keyboard"; export interface IWindowState { width?: number; @@ -82,10 +82,7 @@ export interface IWindowConfiguration extends ParsedArgs { * The physical keyboard is of ISO type (on OSX). */ isISOKeyboard?: boolean; - /** - * Accessibility support is enabled. - */ - accessibilitySupportEnabled?: boolean; + zoomLevel?: number; fullscreen?: boolean; highContrast?: boolean; @@ -558,6 +555,9 @@ export class VSCodeWindow { windowConfiguration.highContrast = platform.isWindows && systemPreferences.isInvertedColorScheme() && (!windowConfig || windowConfig.autoDetectHighContrast); windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled(); + // Set Keyboard Config + windowConfiguration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard(); + // Theme windowConfiguration.baseTheme = this.getBaseTheme(); windowConfiguration.backgroundColor = this.getBackgroundColor(); diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 72d1091e196..b4324486c62 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -31,8 +31,7 @@ import product from 'vs/platform/node/product'; import { OpenContext } from 'vs/code/common/windows'; import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; import { isParent, isEqual, isEqualOrParent } from 'vs/platform/files/common/files'; -import * as nativeKeymap from 'native-keymap'; -import { IDisposable } from 'vs/base/common/lifecycle'; +import { KeyboardLayoutMonitor } from "vs/code/node/keyboard"; enum WindowError { UNRESPONSIVE, @@ -107,7 +106,6 @@ export interface IWindowsMainService { openFileFolderPicker(forceNewWindow?: boolean, data?: ITelemetryData): void; openFilePicker(forceNewWindow?: boolean, path?: string, window?: VSCodeWindow, data?: ITelemetryData): void; openFolderPicker(forceNewWindow?: boolean, window?: VSCodeWindow, data?: ITelemetryData): void; - openAccessibilityOptions(): void; focusLastActive(cli: ParsedArgs, context: OpenContext): VSCodeWindow; getLastActiveWindow(): VSCodeWindow; findWindow(workspacePath: string, filePath?: string, extensionDevelopmentPath?: string): VSCodeWindow; @@ -343,6 +341,7 @@ export class WindowsManager implements IWindowsMainService { } private onBroadcast(event: string, payload: any): void { + // Theme changes if (event === 'vscode:changeColorTheme' && typeof payload === 'string') { @@ -737,8 +736,6 @@ export class WindowsManager implements IWindowsMainService { configuration.filesToCreate = filesToCreate; configuration.filesToDiff = filesToDiff; configuration.nodeCachedDataDir = this.environmentService.nodeCachedDataDir; - configuration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard(); - configuration.accessibilitySupportEnabled = app.isAccessibilitySupportEnabled(); return configuration; } @@ -1028,22 +1025,6 @@ export class WindowsManager implements IWindowsMainService { this.doPickAndOpen({ pickFolders: true, forceNewWindow, window }, 'openFolder', data); } - public openAccessibilityOptions(): void { - let win = new BrowserWindow({ - alwaysOnTop: true, - skipTaskbar: true, - resizable: false, - width: 450, - height: 300, - show: true, - title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options") - }); - - win.setMenuBarVisibility(false); - - win.loadURL('chrome://accessibility'); - } - private doPickAndOpen(options: INativeOpenDialogOptions, eventName: string, data?: ITelemetryData): void { this.getFileOrFolderPaths(options, (paths: string[]) => { const nOfPaths = paths ? paths.length : 0; @@ -1338,63 +1319,4 @@ export class WindowsManager implements IWindowsMainService { }, 10 /* delay to unwind callback stack (IPC) */); } } -} - -class KeyboardLayoutMonitor { - - public static INSTANCE = new KeyboardLayoutMonitor(); - - private _emitter: Emitter; - private _registered: boolean; - private _isISOKeyboard: boolean; - - private constructor() { - this._emitter = new Emitter(); - this._registered = false; - this._isISOKeyboard = this._readIsISOKeyboard(); - } - - public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable { - if (!this._registered) { - this._registered = true; - - nativeKeymap.onDidChangeKeyboardLayout(() => { - this._emitter.fire(this._isISOKeyboard); - }); - - if (platform.isMacintosh) { - // See https://github.com/Microsoft/vscode/issues/24153 - // On OSX, on ISO keyboards, Chromium swaps the scan codes - // of IntlBackslash and Backquote. - // - // The C++ methods can give the current keyboard type (ISO or not) - // only after a NSEvent was handled. - // - // We therefore poll. - setInterval(() => { - let newValue = this._readIsISOKeyboard(); - if (this._isISOKeyboard === newValue) { - // no change - return; - } - - this._isISOKeyboard = newValue; - this._emitter.fire(this._isISOKeyboard); - - }, 3000); - } - } - return this._emitter.event(callback); - } - - private _readIsISOKeyboard(): boolean { - if (platform.isMacintosh) { - return nativeKeymap.isISOKeyboard(); - } - return false; - } - - public isISOKeyboard(): boolean { - return this._isISOKeyboard; - } -} +} \ No newline at end of file diff --git a/src/vs/code/node/keyboard.ts b/src/vs/code/node/keyboard.ts new file mode 100644 index 00000000000..d2f968371ef --- /dev/null +++ b/src/vs/code/node/keyboard.ts @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import * as nativeKeymap from 'native-keymap'; +import { IDisposable } from 'vs/base/common/lifecycle'; +import { isMacintosh } from "vs/base/common/platform"; +import { Emitter } from "vs/base/common/event"; + +export class KeyboardLayoutMonitor { + + public static readonly INSTANCE = new KeyboardLayoutMonitor(); + + private _emitter: Emitter; + private _registered: boolean; + private _isISOKeyboard: boolean; + + private constructor() { + this._emitter = new Emitter(); + this._registered = false; + this._isISOKeyboard = this._readIsISOKeyboard(); + } + + public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable { + if (!this._registered) { + this._registered = true; + + nativeKeymap.onDidChangeKeyboardLayout(() => { + this._emitter.fire(this._isISOKeyboard); + }); + + if (isMacintosh) { + // See https://github.com/Microsoft/vscode/issues/24153 + // On OSX, on ISO keyboards, Chromium swaps the scan codes + // of IntlBackslash and Backquote. + // + // The C++ methods can give the current keyboard type (ISO or not) + // only after a NSEvent was handled. + // + // We therefore poll. + setInterval(() => { + let newValue = this._readIsISOKeyboard(); + if (this._isISOKeyboard === newValue) { + // no change + return; + } + + this._isISOKeyboard = newValue; + this._emitter.fire(this._isISOKeyboard); + + }, 3000); + } + } + return this._emitter.event(callback); + } + + private _readIsISOKeyboard(): boolean { + if (isMacintosh) { + return nativeKeymap.isISOKeyboard(); + } + return false; + } + + public isISOKeyboard(): boolean { + return this._isISOKeyboard; + } +} diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index fb179f3196c..b20a6fd422a 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -42,10 +42,7 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest { */ isISOKeyboard?: boolean; - /** - * Accessibility support is enabled. - */ - accessibilitySupportEnabled?: boolean; + accessibilitySupport?: boolean; appRoot: string; execPath: string; @@ -62,15 +59,16 @@ export function startup(configuration: IWindowConfiguration): TPromise { // Ensure others can listen to zoom level changes browser.setZoomFactor(webFrame.getZoomFactor()); + // See https://github.com/Microsoft/vscode/issues/26151 // Can be trusted because we are not setting it ourselves. - browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/true); + browser.setZoomLevel(webFrame.getZoomLevel(), true /* isTrusted */); browser.setFullscreen(!!configuration.fullscreen); KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged(configuration.isISOKeyboard); - browser.setAccessibilitySupport(configuration.accessibilitySupportEnabled ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled); + browser.setAccessibilitySupport(configuration.accessibilitySupport ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled); // Setup Intl comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));