Skip to content

Commit

Permalink
aux window - use active window bounds as location for new windows and…
Browse files Browse the repository at this point in the history
… offset as necessary (#199542)
  • Loading branch information
bpasero committed Nov 29, 2023
1 parent 856b69c commit 42e3500
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,34 @@ export class BrowserAuxiliaryWindowService extends Disposable implements IAuxili

private async openWindow(options?: IAuxiliaryWindowOpenOptions): Promise<Window | undefined> {
const activeWindow = getActiveWindow();
const activeWindowBounds = {
x: activeWindow.screenX,
y: activeWindow.screenY,
width: activeWindow.outerWidth,
height: activeWindow.outerHeight
};

const width = options?.bounds?.width ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.width;
const height = options?.bounds?.height ?? BrowserAuxiliaryWindowService.DEFAULT_SIZE.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);

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)
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
};

const auxiliaryWindow = mainWindow.open('about:blank', undefined, `popup=yes,left=${bounds.x},top=${bounds.y},width=${bounds.width},height=${bounds.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,
Expand All @@ -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
Expand Down

0 comments on commit 42e3500

Please sign in to comment.