Skip to content

Commit

Permalink
center aux window on current screen (#224440)
Browse files Browse the repository at this point in the history
center issue reporter window
  • Loading branch information
justschen authored Aug 1, 2024
1 parent c0331c8 commit 3ccbb8a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/native/common/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface ICommonNativeHostService {
getWindows(options: { includeAuxiliaryWindows: false }): Promise<Array<IOpenedMainWindow>>;
getWindowCount(): Promise<number>;
getActiveWindowId(): Promise<number | undefined>;
getActiveWindowPosition(): Promise<IRectangle | undefined>;

openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
Expand Down
8 changes: 8 additions & 0 deletions src/vs/platform/native/electron-main/nativeHostMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
return undefined;
}

async getActiveWindowPosition(): Promise<IRectangle | undefined> {
const activeWindow = this.windowsMainService.getFocusedWindow() || this.windowsMainService.getLastActiveWindow();
if (activeWindow) {
return activeWindow.getBounds();
}
return undefined;
}

openWindow(windowId: number | undefined, options?: IOpenEmptyWindowOptions): Promise<void>;
openWindow(windowId: number | undefined, toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
openWindow(windowId: number | undefined, arg1?: IOpenEmptyWindowOptions | IWindowOpenable[], arg2?: IOpenWindowOptions): Promise<void> {
Expand Down
15 changes: 13 additions & 2 deletions src/vs/workbench/contrib/issue/browser/issueFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ExtensionIdentifier, ExtensionIdentifierSet } from 'vs/platform/extensi
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import product from 'vs/platform/product/common/product';
import { IRectangle } from 'vs/platform/window/common/window';
import BaseHtml from 'vs/workbench/contrib/issue/browser/issueReporterPage';
import { IssueWebReporter } from 'vs/workbench/contrib/issue/browser/issueReporterService';
import { IIssueFormService, IssueReporterData } from 'vs/workbench/contrib/issue/common/issue';
Expand Down Expand Up @@ -61,11 +62,21 @@ export class IssueFormService implements IIssueFormService {
}
}

async openAuxIssueReporter(data: IssueReporterData): Promise<void> {
async openAuxIssueReporter(data: IssueReporterData, bounds?: IRectangle): Promise<void> {

let issueReporterBounds: Partial<IRectangle> = { width: 700, height: 800 };

// Center Issue Reporter Window based on bounds from native host service
if (bounds && bounds.x && bounds.y) {
const centerX = bounds.x + bounds.width / 2;
const centerY = bounds.y + bounds.height / 2;
issueReporterBounds = { ...issueReporterBounds, x: centerX - 350, y: centerY - 400 };
}

const disposables = new DisposableStore();

// Auxiliary Window
const auxiliaryWindow = disposables.add(await this.auxiliaryWindowService.open({ mode: AuxiliaryWindowMode.Custom, bounds: { width: 700, height: 800 } }));
const auxiliaryWindow = disposables.add(await this.auxiliaryWindowService.open({ mode: AuxiliaryWindowMode.Custom, bounds: issueReporterBounds }));

if (auxiliaryWindow) {
await auxiliaryWindow.whenStylesHaveLoaded;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class NativeIssueFormService extends IssueFormService implements IIssueFo
return;
}

await super.openAuxIssueReporter(data);
const bounds = await this.nativeHostService.getActiveWindowPosition();
if (!bounds) {
return;
}

await this.openAuxIssueReporter(data, bounds);

// Get platform information
const { arch, release, type } = await this.nativeHostService.getOSProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class TestNativeHostService implements INativeHostService {

async getWindows(): Promise<IOpenedMainWindow[]> { return []; }
async getActiveWindowId(): Promise<number | undefined> { return undefined; }
async getActiveWindowPosition(): Promise<IRectangle | undefined> { return undefined; }

openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
Expand Down

0 comments on commit 3ccbb8a

Please sign in to comment.