From f566d06a414012c901df6ea004abc8728feea718 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 21 Dec 2015 10:25:03 +0100 Subject: [PATCH] workaround win10 focus issue --- src/typings/atom-browser.d.ts | 2 ++ src/vs/workbench/electron-main/window.ts | 18 ++++++++++++------ src/vs/workbench/electron-main/windows.ts | 10 +++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/typings/atom-browser.d.ts b/src/typings/atom-browser.d.ts index f0a9d928d98..d3b36734e13 100644 --- a/src/typings/atom-browser.d.ts +++ b/src/typings/atom-browser.d.ts @@ -182,6 +182,8 @@ declare class BrowserWindow extends EventEmitter { setFullScreen(fullscreen: boolean): void; isFullScreen(): boolean; isMaximized(): boolean; + minimize(): void; + isFocused(): boolean; isMinimized(): boolean; isVisible(): boolean; restore(): boolean; diff --git a/src/vs/workbench/electron-main/window.ts b/src/vs/workbench/electron-main/window.ts index 272ba55d680..3d6b01c92e4 100644 --- a/src/vs/workbench/electron-main/window.ts +++ b/src/vs/workbench/electron-main/window.ts @@ -6,6 +6,7 @@ 'use strict'; import path = require('path'); +import os = require('os'); import Shell = require('shell'); import screen = require('screen'); @@ -218,18 +219,23 @@ export class VSCodeWindow { return this._win; } - public restore(): void { + public focus(): void { if (!this._win) { return; } - if (this._win.isMinimized()) { - this._win.restore(); + // Windows 10: https://github.com/Microsoft/vscode/issues/929 + if (platform.isWindows && os.release() && os.release().indexOf('10.') === 0 && !this._win.isFocused()) { + this._win.minimize(); + this._win.focus(); } - if (platform.isWindows || platform.isLinux) { - this._win.show(); // Windows & Linux sometimes cannot bring the window to the front when it is in the background - } else { + // Mac / Linux / Windows 7 & 8 + else { + if (this._win.isMinimized()) { + this._win.restore(); + } + this._win.focus(); } } diff --git a/src/vs/workbench/electron-main/windows.ts b/src/vs/workbench/electron-main/windows.ts index cc268f68236..7f8a654b06f 100644 --- a/src/vs/workbench/electron-main/windows.ts +++ b/src/vs/workbench/electron-main/windows.ts @@ -421,7 +421,7 @@ export class WindowsManager { // Open Files in last instance if any and flag tells us so let lastActiveWindow = this.getLastActiveWindow(); if (!openFilesInNewWindow && lastActiveWindow) { - lastActiveWindow.restore(); + lastActiveWindow.focus(); lastActiveWindow.ready().then((readyWindow) => { readyWindow.send('vscode:openFiles', { filesToOpen: filesToOpen, @@ -449,7 +449,7 @@ export class WindowsManager { // Check for existing instances let windowsOnWorkspacePath = arrays.coalesce(foldersToOpen.map((iPath) => this.findWindow(iPath.workspacePath))); if (windowsOnWorkspacePath.length > 0) { - windowsOnWorkspacePath[0].restore(); // just focus one of them + windowsOnWorkspacePath[0].focus(); // just focus one of them windowsOnWorkspacePath[0].ready().then((readyWindow) => { readyWindow.send('vscode:openFiles', { filesToOpen: filesToOpen, @@ -518,7 +518,7 @@ export class WindowsManager { let res = WindowsManager.WINDOWS.filter((w) => w.config && this.isPathEqual(w.config.pluginDevelopmentPath, openConfig.cli.pluginDevelopmentPath)); if (res && res.length === 1) { this.reload(res[0], openConfig.cli); - res[0].restore(); // make sure it gets focus and is restored + res[0].focus(); // make sure it gets focus and is restored return; } @@ -685,7 +685,7 @@ export class WindowsManager { vscodeWindow = windowToUse || this.getLastActiveWindow(); if (vscodeWindow) { - vscodeWindow.restore(); + vscodeWindow.focus(); } } @@ -856,7 +856,7 @@ export class WindowsManager { public focusLastActive(cli: env.ICommandLineArguments): void { let lastActive = this.getLastActiveWindow(); if (lastActive) { - lastActive.restore(); + lastActive.focus(); } // No window - open new one