Skip to content

Commit a8fb36f

Browse files
Benjamin Paserodbaeumer
authored andcommitted
How to configure a window (also for reload case)? (fixes microsoft#27192)
1 parent 27625c2 commit a8fb36f

5 files changed

Lines changed: 100 additions & 94 deletions

File tree

src/vs/code/electron-main/menus.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as nls from 'vs/nls';
99
import { isMacintosh, isLinux, isWindows, language } from 'vs/base/common/platform';
1010
import * as arrays from 'vs/base/common/arrays';
1111
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
12-
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem } from 'electron';
12+
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem, BrowserWindow } from 'electron';
1313
import { OpenContext } from 'vs/code/common/windows';
1414
import { IWindowsMainService } from 'vs/code/electron-main/windows';
1515
import { VSCodeWindow } from 'vs/code/electron-main/window';
@@ -908,7 +908,7 @@ export class VSCodeMenu {
908908
label: this.mnemonicLabel(nls.localize({ key: 'miAccessibilityOptions', comment: ['&& denotes a mnemonic'] }, "Accessibility &&Options")),
909909
accelerator: null,
910910
click: () => {
911-
this.windowsService.openAccessibilityOptions();
911+
this.openAccessibilityOptions();
912912
}
913913
}, false));
914914

@@ -974,6 +974,22 @@ export class VSCodeMenu {
974974
}
975975
}
976976

977+
private openAccessibilityOptions(): void {
978+
let win = new BrowserWindow({
979+
alwaysOnTop: true,
980+
skipTaskbar: true,
981+
resizable: false,
982+
width: 450,
983+
height: 300,
984+
show: true,
985+
title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options")
986+
});
987+
988+
win.setMenuBarVisibility(false);
989+
990+
win.loadURL('chrome://accessibility');
991+
}
992+
977993
private getUpdateMenuItems(): Electron.MenuItem[] {
978994
switch (this.updateService.state) {
979995
case UpdateState.Uninitialized:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import product from 'vs/platform/node/product';
2222
import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http';
2323
import { IWindowSettings, MenuBarVisibility } from 'vs/platform/windows/common/windows';
2424
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
25-
25+
import { KeyboardLayoutMonitor } from "vs/code/node/keyboard";
2626

2727
export interface IWindowState {
2828
width?: number;
@@ -82,10 +82,7 @@ export interface IWindowConfiguration extends ParsedArgs {
8282
* The physical keyboard is of ISO type (on OSX).
8383
*/
8484
isISOKeyboard?: boolean;
85-
/**
86-
* Accessibility support is enabled.
87-
*/
88-
accessibilitySupportEnabled?: boolean;
85+
8986
zoomLevel?: number;
9087
fullscreen?: boolean;
9188
highContrast?: boolean;
@@ -558,6 +555,9 @@ export class VSCodeWindow {
558555
windowConfiguration.highContrast = platform.isWindows && systemPreferences.isInvertedColorScheme() && (!windowConfig || windowConfig.autoDetectHighContrast);
559556
windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled();
560557

558+
// Set Keyboard Config
559+
windowConfiguration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard();
560+
561561
// Theme
562562
windowConfiguration.baseTheme = this.getBaseTheme();
563563
windowConfiguration.backgroundColor = this.getBackgroundColor();

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

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import product from 'vs/platform/node/product';
3131
import { OpenContext } from 'vs/code/common/windows';
3232
import { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
3333
import { isParent, isEqual, isEqualOrParent } from 'vs/platform/files/common/files';
34-
import * as nativeKeymap from 'native-keymap';
35-
import { IDisposable } from 'vs/base/common/lifecycle';
34+
import { KeyboardLayoutMonitor } from "vs/code/node/keyboard";
3635

3736
enum WindowError {
3837
UNRESPONSIVE,
@@ -107,7 +106,6 @@ export interface IWindowsMainService {
107106
openFileFolderPicker(forceNewWindow?: boolean, data?: ITelemetryData): void;
108107
openFilePicker(forceNewWindow?: boolean, path?: string, window?: VSCodeWindow, data?: ITelemetryData): void;
109108
openFolderPicker(forceNewWindow?: boolean, window?: VSCodeWindow, data?: ITelemetryData): void;
110-
openAccessibilityOptions(): void;
111109
focusLastActive(cli: ParsedArgs, context: OpenContext): VSCodeWindow;
112110
getLastActiveWindow(): VSCodeWindow;
113111
findWindow(workspacePath: string, filePath?: string, extensionDevelopmentPath?: string): VSCodeWindow;
@@ -343,6 +341,7 @@ export class WindowsManager implements IWindowsMainService {
343341
}
344342

345343
private onBroadcast(event: string, payload: any): void {
344+
346345
// Theme changes
347346
if (event === 'vscode:changeColorTheme' && typeof payload === 'string') {
348347

@@ -737,8 +736,6 @@ export class WindowsManager implements IWindowsMainService {
737736
configuration.filesToCreate = filesToCreate;
738737
configuration.filesToDiff = filesToDiff;
739738
configuration.nodeCachedDataDir = this.environmentService.nodeCachedDataDir;
740-
configuration.isISOKeyboard = KeyboardLayoutMonitor.INSTANCE.isISOKeyboard();
741-
configuration.accessibilitySupportEnabled = app.isAccessibilitySupportEnabled();
742739

743740
return configuration;
744741
}
@@ -1028,22 +1025,6 @@ export class WindowsManager implements IWindowsMainService {
10281025
this.doPickAndOpen({ pickFolders: true, forceNewWindow, window }, 'openFolder', data);
10291026
}
10301027

1031-
public openAccessibilityOptions(): void {
1032-
let win = new BrowserWindow({
1033-
alwaysOnTop: true,
1034-
skipTaskbar: true,
1035-
resizable: false,
1036-
width: 450,
1037-
height: 300,
1038-
show: true,
1039-
title: nls.localize('accessibilityOptionsWindowTitle', "Accessibility Options")
1040-
});
1041-
1042-
win.setMenuBarVisibility(false);
1043-
1044-
win.loadURL('chrome://accessibility');
1045-
}
1046-
10471028
private doPickAndOpen(options: INativeOpenDialogOptions, eventName: string, data?: ITelemetryData): void {
10481029
this.getFileOrFolderPaths(options, (paths: string[]) => {
10491030
const nOfPaths = paths ? paths.length : 0;
@@ -1338,63 +1319,4 @@ export class WindowsManager implements IWindowsMainService {
13381319
}, 10 /* delay to unwind callback stack (IPC) */);
13391320
}
13401321
}
1341-
}
1342-
1343-
class KeyboardLayoutMonitor {
1344-
1345-
public static INSTANCE = new KeyboardLayoutMonitor();
1346-
1347-
private _emitter: Emitter<boolean>;
1348-
private _registered: boolean;
1349-
private _isISOKeyboard: boolean;
1350-
1351-
private constructor() {
1352-
this._emitter = new Emitter<boolean>();
1353-
this._registered = false;
1354-
this._isISOKeyboard = this._readIsISOKeyboard();
1355-
}
1356-
1357-
public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable {
1358-
if (!this._registered) {
1359-
this._registered = true;
1360-
1361-
nativeKeymap.onDidChangeKeyboardLayout(() => {
1362-
this._emitter.fire(this._isISOKeyboard);
1363-
});
1364-
1365-
if (platform.isMacintosh) {
1366-
// See https://github.com/Microsoft/vscode/issues/24153
1367-
// On OSX, on ISO keyboards, Chromium swaps the scan codes
1368-
// of IntlBackslash and Backquote.
1369-
//
1370-
// The C++ methods can give the current keyboard type (ISO or not)
1371-
// only after a NSEvent was handled.
1372-
//
1373-
// We therefore poll.
1374-
setInterval(() => {
1375-
let newValue = this._readIsISOKeyboard();
1376-
if (this._isISOKeyboard === newValue) {
1377-
// no change
1378-
return;
1379-
}
1380-
1381-
this._isISOKeyboard = newValue;
1382-
this._emitter.fire(this._isISOKeyboard);
1383-
1384-
}, 3000);
1385-
}
1386-
}
1387-
return this._emitter.event(callback);
1388-
}
1389-
1390-
private _readIsISOKeyboard(): boolean {
1391-
if (platform.isMacintosh) {
1392-
return nativeKeymap.isISOKeyboard();
1393-
}
1394-
return false;
1395-
}
1396-
1397-
public isISOKeyboard(): boolean {
1398-
return this._isISOKeyboard;
1399-
}
1400-
}
1322+
}

src/vs/code/node/keyboard.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as nativeKeymap from 'native-keymap';
9+
import { IDisposable } from 'vs/base/common/lifecycle';
10+
import { isMacintosh } from "vs/base/common/platform";
11+
import { Emitter } from "vs/base/common/event";
12+
13+
export class KeyboardLayoutMonitor {
14+
15+
public static readonly INSTANCE = new KeyboardLayoutMonitor();
16+
17+
private _emitter: Emitter<boolean>;
18+
private _registered: boolean;
19+
private _isISOKeyboard: boolean;
20+
21+
private constructor() {
22+
this._emitter = new Emitter<boolean>();
23+
this._registered = false;
24+
this._isISOKeyboard = this._readIsISOKeyboard();
25+
}
26+
27+
public onDidChangeKeyboardLayout(callback: (isISOKeyboard: boolean) => void): IDisposable {
28+
if (!this._registered) {
29+
this._registered = true;
30+
31+
nativeKeymap.onDidChangeKeyboardLayout(() => {
32+
this._emitter.fire(this._isISOKeyboard);
33+
});
34+
35+
if (isMacintosh) {
36+
// See https://github.com/Microsoft/vscode/issues/24153
37+
// On OSX, on ISO keyboards, Chromium swaps the scan codes
38+
// of IntlBackslash and Backquote.
39+
//
40+
// The C++ methods can give the current keyboard type (ISO or not)
41+
// only after a NSEvent was handled.
42+
//
43+
// We therefore poll.
44+
setInterval(() => {
45+
let newValue = this._readIsISOKeyboard();
46+
if (this._isISOKeyboard === newValue) {
47+
// no change
48+
return;
49+
}
50+
51+
this._isISOKeyboard = newValue;
52+
this._emitter.fire(this._isISOKeyboard);
53+
54+
}, 3000);
55+
}
56+
}
57+
return this._emitter.event(callback);
58+
}
59+
60+
private _readIsISOKeyboard(): boolean {
61+
if (isMacintosh) {
62+
return nativeKeymap.isISOKeyboard();
63+
}
64+
return false;
65+
}
66+
67+
public isISOKeyboard(): boolean {
68+
return this._isISOKeyboard;
69+
}
70+
}

src/vs/workbench/electron-browser/main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
4242
*/
4343
isISOKeyboard?: boolean;
4444

45-
/**
46-
* Accessibility support is enabled.
47-
*/
48-
accessibilitySupportEnabled?: boolean;
45+
accessibilitySupport?: boolean;
4946

5047
appRoot: string;
5148
execPath: string;
@@ -62,15 +59,16 @@ export function startup(configuration: IWindowConfiguration): TPromise<void> {
6259

6360
// Ensure others can listen to zoom level changes
6461
browser.setZoomFactor(webFrame.getZoomFactor());
62+
6563
// See https://github.com/Microsoft/vscode/issues/26151
6664
// Can be trusted because we are not setting it ourselves.
67-
browser.setZoomLevel(webFrame.getZoomLevel(), /*isTrusted*/true);
65+
browser.setZoomLevel(webFrame.getZoomLevel(), true /* isTrusted */);
6866

6967
browser.setFullscreen(!!configuration.fullscreen);
7068

7169
KeyboardMapperFactory.INSTANCE._onKeyboardLayoutChanged(configuration.isISOKeyboard);
7270

73-
browser.setAccessibilitySupport(configuration.accessibilitySupportEnabled ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled);
71+
browser.setAccessibilitySupport(configuration.accessibilitySupport ? platform.AccessibilitySupport.Enabled : platform.AccessibilitySupport.Disabled);
7472

7573
// Setup Intl
7674
comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));

0 commit comments

Comments
 (0)