Skip to content

Commit 42e3500

Browse files
authored
aux window - use active window bounds as location for new windows and offset as necessary (microsoft#199542)
1 parent 856b69c commit 42e3500

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,34 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili
207207

208208
private async openWindow(options?: IAuxiliaryWindowOpenOptions): Promise<Window | undefined> {
209209
const activeWindow = getActiveWindow();
210+
const activeWindowBounds = {
211+
x: activeWindow.screenX,
212+
y: activeWindow.screenY,
213+
width: activeWindow.outerWidth,
214+
height: activeWindow.outerHeight
215+
};
210216

211-
const width = options?.bounds?.width ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.width;
212-
const height = options?.bounds?.height ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.height;
217+
const width = Math.max(options?.bounds?.width ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.width, WindowMinimumSize.WIDTH);
218+
const height = Math.max(options?.bounds?.height ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.height, WindowMinimumSize.HEIGHT);
213219

214-
const bounds: IRectangle = {
215-
x: options?.bounds?.x ?? (activeWindow.screen.availWidth / 2 - width / 2),
216-
y: options?.bounds?.y ?? (activeWindow.screen.availHeight / 2 - height / 2),
217-
width: Math.max(width, WindowMinimumSize.WIDTH),
218-
height: Math.max(height, WindowMinimumSize.HEIGHT)
220+
let newWindowBounds: IRectangle = {
221+
x: options?.bounds?.x ?? (activeWindowBounds.x + activeWindowBounds.width / 2 - width / 2),
222+
y: options?.bounds?.y ?? (activeWindowBounds.y + activeWindowBounds.height / 2 - height / 2),
223+
width,
224+
height
219225
};
220226

221-
const auxiliaryWindow = mainWindow.open('about:blank', undefined, `popup=yes,left=${bounds.x},top=${bounds.y},width=${bounds.width},height=${bounds.height}`);
227+
if (newWindowBounds.x === activeWindowBounds.x && newWindowBounds.y === activeWindowBounds.y) {
228+
// Offset the new window a bit so that it does not overlap
229+
// with the active window
230+
newWindowBounds = {
231+
...newWindowBounds,
232+
x: newWindowBounds.x + 30,
233+
y: newWindowBounds.y + 30
234+
};
235+
}
236+
237+
const auxiliaryWindow = mainWindow.open('about:blank', undefined, `popup=yes,left=${newWindowBounds.x},top=${newWindowBounds.y},width=${newWindowBounds.width},height=${newWindowBounds.height}`);
222238
if (!auxiliaryWindow && isWeb) {
223239
return (await this.dialogService.prompt({
224240
type: Severity.Warning,
@@ -227,7 +243,7 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili
227243
buttons: [
228244
{
229245
label: localize({ key: 'retry', comment: ['&& denotes a mnemonic'] }, "&&Retry"),
230-
run: () => this.openWindow({ bounds })
246+
run: () => this.openWindow(options)
231247
}
232248
],
233249
cancelButton: true

0 commit comments

Comments
 (0)