Skip to content

Commit 858b389

Browse files
authored
aux window - fix active window/document assumptions with focus involved (microsoft#199568)
1 parent 48b8416 commit 858b389

File tree

14 files changed

+30
-27
lines changed

14 files changed

+30
-27
lines changed

src/vs/base/browser/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ export function getActiveWindow(): CodeWindow {
893893

894894
export function focusWindow(element: Node): void {
895895
const window = getWindow(element);
896-
if (window !== getActiveWindow()) {
896+
if (!window.document.hasFocus()) {
897897
window.focus();
898898
}
899899
}

src/vs/workbench/browser/parts/titlebar/titlebarPart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
1919
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER, WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme';
2020
import { isMacintosh, isWindows, isLinux, isWeb, isNative, platformLocale } from 'vs/base/common/platform';
2121
import { Color } from 'vs/base/common/color';
22-
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getActiveWindow, getWindowId, isAncestor } from 'vs/base/browser/dom';
22+
import { EventType, EventHelper, Dimension, append, $, addDisposableListener, prepend, reset, getWindow, getWindowId, isAncestor } from 'vs/base/browser/dom';
2323
import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
2424
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2525
import { Emitter, Event } from 'vs/base/common/event';
@@ -254,7 +254,7 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
254254

255255
private registerListeners(targetWindowId: number): void {
256256
this._register(this.hostService.onDidChangeFocus(focused => focused ? this.onFocus() : this.onBlur()));
257-
this._register(this.hostService.onDidChangeActiveWindow(() => getActiveWindow().vscodeWindowId === targetWindowId ? this.onFocus() : this.onBlur()));
257+
this._register(this.hostService.onDidChangeActiveWindow(windowId => windowId === targetWindowId ? this.onFocus() : this.onBlur()));
258258
this._register(this.configurationService.onDidChangeConfiguration(e => this.onConfigurationChanged(e)));
259259
}
260260

src/vs/workbench/contrib/debug/browser/debugSession.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,11 @@ export class DebugSession implements IDebugSession, IDisposable {
10191019
await this.paneCompositeService.openPaneComposite(VIEWLET_ID, ViewContainerLocation.Sidebar);
10201020
}
10211021

1022-
if (this.configurationService.getValue<IDebugConfiguration>('debug').focusWindowOnBreak && !this.workbenchEnvironmentService.extensionTestsLocationURI && !getActiveWindow()) {
1023-
await this.hostService.focus(mainWindow, { force: true /* Application may not be active */ });
1022+
if (this.configurationService.getValue<IDebugConfiguration>('debug').focusWindowOnBreak && !this.workbenchEnvironmentService.extensionTestsLocationURI) {
1023+
const activeWindow = getActiveWindow();
1024+
if (!activeWindow.document.hasFocus()) {
1025+
await this.hostService.focus(mainWindow, { force: true /* Application may not be active */ });
1026+
}
10241027
}
10251028
}
10261029
}

src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
3939
import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable';
4040
import { generateUuid } from 'vs/base/common/uuid';
4141
import { getActiveWindow, runWhenWindowIdle } from 'vs/base/browser/dom';
42+
import { mainWindow } from 'vs/base/browser/window';
4243

4344
const enum ProcessConstants {
4445
/**
@@ -748,7 +749,7 @@ class SeamlessRelaunchDataFilter extends Disposable {
748749
this.triggerSwap();
749750
}
750751

751-
this._swapTimeout = getActiveWindow().setTimeout(() => this.triggerSwap(), SeamlessRelaunchConstants.SwapWaitMaximumDuration);
752+
this._swapTimeout = mainWindow.setTimeout(() => this.triggerSwap(), SeamlessRelaunchConstants.SwapWaitMaximumDuration);
752753

753754
// Pause all outgoing data events
754755
this._dataListener?.dispose();
@@ -773,7 +774,7 @@ class SeamlessRelaunchDataFilter extends Disposable {
773774
triggerSwap() {
774775
// Clear the swap timeout if it exists
775776
if (this._swapTimeout) {
776-
getActiveWindow().clearTimeout(this._swapTimeout);
777+
mainWindow.clearTimeout(this._swapTimeout);
777778
this._swapTimeout = undefined;
778779
}
779780

src/vs/workbench/contrib/terminal/browser/terminalStatusList.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { listErrorForeground, listWarningForeground } from 'vs/platform/theme/co
1313
import { spinningLoading } from 'vs/platform/theme/common/iconRegistry';
1414
import { ThemeIcon } from 'vs/base/common/themables';
1515
import { ITerminalStatus } from 'vs/workbench/contrib/terminal/common/terminal';
16-
import { getActiveWindow } from 'vs/base/browser/dom';
16+
import { mainWindow } from 'vs/base/browser/window';
1717

1818
/**
1919
* The set of _internal_ terminal statuses, other components building on the terminal should put
@@ -85,11 +85,11 @@ export class TerminalStatusList extends Disposable implements ITerminalStatusLis
8585
status = this._applyAnimationSetting(status);
8686
const outTimeout = this._statusTimeouts.get(status.id);
8787
if (outTimeout) {
88-
getActiveWindow().clearTimeout(outTimeout);
88+
mainWindow.clearTimeout(outTimeout);
8989
this._statusTimeouts.delete(status.id);
9090
}
9191
if (duration && duration > 0) {
92-
const timeout = getActiveWindow().setTimeout(() => this.remove(status), duration);
92+
const timeout = mainWindow.setTimeout(() => this.remove(status), duration);
9393
this._statusTimeouts.set(status.id, timeout);
9494
}
9595
const existingStatus = this._statuses.get(status.id);

src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { isWindows, OperatingSystem, OS } from 'vs/base/common/platform';
1212
import { IFileService } from 'vs/platform/files/common/files';
1313
import { IPath, posix, win32 } from 'vs/base/common/path';
1414
import { ITerminalBackend } from 'vs/platform/terminal/common/terminal';
15-
import { getActiveWindow } from 'vs/base/browser/dom';
15+
import { mainWindow } from 'vs/base/browser/window';
1616

1717
export class TerminalLinkResolver implements ITerminalLinkResolver {
1818
declare _serviceBrand: undefined;
@@ -170,9 +170,9 @@ class LinkCache {
170170
set(link: string | URI, value: ResolvedLink) {
171171
// Reset cached link TTL on any set
172172
if (this._cacheTilTimeout) {
173-
getActiveWindow().clearTimeout(this._cacheTilTimeout);
173+
mainWindow.clearTimeout(this._cacheTilTimeout);
174174
}
175-
this._cacheTilTimeout = getActiveWindow().setTimeout(() => this._cache.clear(), LinkCacheConstants.TTL);
175+
this._cacheTilTimeout = mainWindow.setTimeout(() => this._cache.clear(), LinkCacheConstants.TTL);
176176
this._cache.set(this._getKey(link), value);
177177
}
178178

src/vs/workbench/contrib/themes/browser/themes.contribution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
4444
import { isWeb } from 'vs/base/common/platform';
4545
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
4646
import { IHostService } from 'vs/workbench/services/host/browser/host';
47-
import { getActiveWindow } from 'vs/base/browser/dom';
47+
import { mainWindow } from 'vs/base/browser/window';
4848

4949
export const manageExtensionIcon = registerIcon('theme-selection-manage-extension', Codicon.gear, localize('manageExtensionIcon', 'Icon for the \'Manage\' action in the theme selection quick pick.'));
5050

@@ -307,7 +307,7 @@ class InstalledThemesPicker {
307307
if (selectThemeTimeout) {
308308
clearTimeout(selectThemeTimeout);
309309
}
310-
selectThemeTimeout = getActiveWindow().setTimeout(() => {
310+
selectThemeTimeout = mainWindow.setTimeout(() => {
311311
selectThemeTimeout = undefined;
312312
const newTheme = (theme ?? currentTheme) as IWorkbenchTheme;
313313
this.setTheme(newTheme, applyTheme ? 'auto' : 'preview').then(undefined,
@@ -702,7 +702,7 @@ registerAction2(class extends Action2 {
702702
if (selectThemeTimeout) {
703703
clearTimeout(selectThemeTimeout);
704704
}
705-
selectThemeTimeout = getActiveWindow().setTimeout(() => {
705+
selectThemeTimeout = mainWindow.setTimeout(() => {
706706
selectThemeTimeout = undefined;
707707
const newTheme = (theme ?? currentTheme) as IWorkbenchTheme;
708708
themeService.setColorTheme(newTheme as IWorkbenchColorTheme, applyTheme ? 'auto' : 'preview').then(undefined,

src/vs/workbench/electron-sandbox/window.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
77
import { URI } from 'vs/base/common/uri';
88
import { onUnexpectedError } from 'vs/base/common/errors';
99
import { equals } from 'vs/base/common/objects';
10-
import { EventType, EventHelper, addDisposableListener, ModifierKeyEmitter, getActiveElement, getActiveWindow, hasWindow, getWindow, getWindowById, getWindowId } from 'vs/base/browser/dom';
10+
import { EventType, EventHelper, addDisposableListener, ModifierKeyEmitter, getActiveElement, hasWindow, getWindow, getWindowById, getWindowId } from 'vs/base/browser/dom';
1111
import { Separator, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
1212
import { IFileService } from 'vs/platform/files/common/files';
1313
import { EditorResourceAccessor, IUntitledTextResourceEditorInput, SideBySideEditor, pathsToEditors, IResourceDiffEditorInput, IUntypedEditorInput, IEditorPane, isResourceEditorInput, IResourceMergeEditorInput } from 'vs/workbench/common/editor';
@@ -701,7 +701,7 @@ export class NativeWindow extends BaseWindow {
701701
mainWindow.focus = function () {
702702
originalWindowFocus();
703703

704-
if (getActiveWindow() !== mainWindow) {
704+
if (!mainWindow.document.hasFocus()) {
705705
that.nativeHostService.focusWindow({ targetWindowId: getWindowId(mainWindow) });
706706
}
707707
};

src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { IWindowsConfiguration } from 'vs/platform/window/common/window';
1212
import { DisposableStore } from 'vs/base/common/lifecycle';
1313
import { INativeHostService } from 'vs/platform/native/common/native';
1414
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
15-
import { getActiveWindow } from 'vs/base/browser/dom';
1615
import { CodeWindow } from 'vs/base/browser/window';
1716
import { mark } from 'vs/base/common/performance';
1817
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -95,7 +94,7 @@ export class NativeAuxiliaryWindowService extends BrowserAuxiliaryWindowService
9594
auxiliaryWindow.focus = function () {
9695
originalWindowFocus();
9796

98-
if (getActiveWindow() !== auxiliaryWindow) {
97+
if (!auxiliaryWindow.document.hasFocus()) {
9998
that.nativeHostService.focusWindow({ targetWindowId: auxiliaryWindow.vscodeWindowId });
10099
}
101100
};

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class BrowserHostService extends Disposable implements IHostService {
176176
//#region Window
177177

178178
@memoize
179-
get onDidChangeActiveWindow(): Event<void> {
179+
get onDidChangeActiveWindow(): Event<number> {
180180
const emitter = this._register(new Emitter<number>());
181181

182182
this._register(Event.runAndSubscribe(onDidRegisterWindow, ({ window, disposables }) => {
@@ -201,7 +201,7 @@ export class BrowserHostService extends Disposable implements IHostService {
201201
}
202202
}, { window: mainWindow, disposables: this._store }));
203203

204-
return Event.map(Event.latch(emitter.event, undefined, this._store), () => undefined, this._store);
204+
return Event.latch(emitter.event, undefined, this._store);
205205
}
206206

207207
openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;

0 commit comments

Comments
 (0)