-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
How to configure a window (also for reload case)? (fixes #27192)
- Loading branch information
Showing
5 changed files
with
100 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean>; | ||
private _registered: boolean; | ||
private _isISOKeyboard: boolean; | ||
|
||
private constructor() { | ||
this._emitter = new Emitter<boolean>(); | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters