From 42e35009a08896a514c19b23c4580cbc66e21883 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 29 Nov 2023 14:59:03 +0100 Subject: [PATCH] aux window - use active window bounds as location for new windows and offset as necessary (#199542) --- .../browser/auxiliaryWindowService.ts | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts b/src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts index 8a9f0cdaf50..aedc4393850 100644 --- a/src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts +++ b/src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts @@ -207,18 +207,34 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili private async openWindow(options?: IAuxiliaryWindowOpenOptions): Promise { const activeWindow = getActiveWindow(); - - const width = options?.bounds?.width ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.width; - const height = options?.bounds?.height ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.height; - - const bounds: IRectangle = { - x: options?.bounds?.x ?? (activeWindow.screen.availWidth / 2 - width / 2), - y: options?.bounds?.y ?? (activeWindow.screen.availHeight / 2 - height / 2), - width: Math.max(width, WindowMinimumSize.WIDTH), - height: Math.max(height, WindowMinimumSize.HEIGHT) + const activeWindowBounds = { + x: activeWindow.screenX, + y: activeWindow.screenY, + width: activeWindow.outerWidth, + height: activeWindow.outerHeight }; - const auxiliaryWindow = mainWindow.open('about:blank', undefined, `popup=yes,left=${bounds.x},top=${bounds.y},width=${bounds.width},height=${bounds.height}`); + const width = Math.max(options?.bounds?.width ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.width, WindowMinimumSize.WIDTH); + const height = Math.max(options?.bounds?.height ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.height, WindowMinimumSize.HEIGHT); + + let newWindowBounds: IRectangle = { + x: options?.bounds?.x ?? (activeWindowBounds.x + activeWindowBounds.width / 2 - width / 2), + y: options?.bounds?.y ?? (activeWindowBounds.y + activeWindowBounds.height / 2 - height / 2), + width, + height + }; + + if (newWindowBounds.x === activeWindowBounds.x && newWindowBounds.y === activeWindowBounds.y) { + // Offset the new window a bit so that it does not overlap + // with the active window + newWindowBounds = { + ...newWindowBounds, + x: newWindowBounds.x + 30, + y: newWindowBounds.y + 30 + }; + } + + const auxiliaryWindow = mainWindow.open('about:blank', undefined, `popup=yes,left=${newWindowBounds.x},top=${newWindowBounds.y},width=${newWindowBounds.width},height=${newWindowBounds.height}`); if (!auxiliaryWindow && isWeb) { return (await this.dialogService.prompt({ type: Severity.Warning, @@ -227,7 +243,7 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili buttons: [ { label: localize({ key: 'retry', comment: ['&& denotes a mnemonic'] }, "&&Retry"), - run: () => this.openWindow({ bounds }) + run: () => this.openWindow(options) } ], cancelButton: true