From 3f44d8005977f51c3f2a5c5df3628b9715d224d3 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 10:58:58 +0000 Subject: [PATCH] Implement workspace-aware default window sizing with unified API (1440x900 for workspaces, 1200x800 for empty windows) (#262266) --- src/vs/platform/window/common/window.ts | 3 ++- src/vs/platform/window/electron-main/window.ts | 9 +++++---- .../windows/electron-main/windowsStateHandler.ts | 2 +- src/vs/workbench/browser/layout.ts | 9 +++++---- test/automation/src/playwrightBrowser.ts | 2 +- test/integration/browser/src/index.ts | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/vs/platform/window/common/window.ts b/src/vs/platform/window/common/window.ts index 86ad0229037..e6f7c87ffef 100644 --- a/src/vs/platform/window/common/window.ts +++ b/src/vs/platform/window/common/window.ts @@ -474,5 +474,6 @@ export function zoomLevelToZoomFactor(zoomLevel = 0): number { return Math.pow(1.2, zoomLevel); } -export const DEFAULT_WINDOW_SIZE = { width: 1200, height: 800 } as const; +export const DEFAULT_EMPTY_WINDOW_SIZE = { width: 1200, height: 800 } as const; +export const DEFAULT_WORKSPACE_WINDOW_SIZE = { width: 1440, height: 900 } as const; export const DEFAULT_AUX_WINDOW_SIZE = { width: 1024, height: 768 } as const; diff --git a/src/vs/platform/window/electron-main/window.ts b/src/vs/platform/window/electron-main/window.ts index bfd4632e83d..02efd8bccc8 100644 --- a/src/vs/platform/window/electron-main/window.ts +++ b/src/vs/platform/window/electron-main/window.ts @@ -12,7 +12,7 @@ import { NativeParsedArgs } from '../../environment/common/argv.js'; import { FocusMode } from '../../native/common/native.js'; import { IUserDataProfile } from '../../userDataProfile/common/userDataProfile.js'; import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from '../../workspace/common/workspace.js'; -import { DEFAULT_AUX_WINDOW_SIZE, DEFAULT_WINDOW_SIZE, INativeWindowConfiguration } from '../common/window.js'; +import { DEFAULT_AUX_WINDOW_SIZE, DEFAULT_EMPTY_WINDOW_SIZE, DEFAULT_WORKSPACE_WINDOW_SIZE, INativeWindowConfiguration } from '../common/window.js'; export interface IBaseWindow extends IDisposable { @@ -138,10 +138,11 @@ export interface IWindowState { readonly display?: number; } -export const defaultWindowState = function (mode = WindowMode.Normal): IWindowState { +export const defaultWindowState = function (mode = WindowMode.Normal, hasWorkspace = false): IWindowState { + const size = hasWorkspace ? DEFAULT_WORKSPACE_WINDOW_SIZE : DEFAULT_EMPTY_WINDOW_SIZE; return { - width: DEFAULT_WINDOW_SIZE.width, - height: DEFAULT_WINDOW_SIZE.height, + width: size.width, + height: size.height, mode }; }; diff --git a/src/vs/platform/windows/electron-main/windowsStateHandler.ts b/src/vs/platform/windows/electron-main/windowsStateHandler.ts index 1008f8217e5..1d04c4ac17e 100644 --- a/src/vs/platform/windows/electron-main/windowsStateHandler.ts +++ b/src/vs/platform/windows/electron-main/windowsStateHandler.ts @@ -372,7 +372,7 @@ export class WindowsStateHandler extends Disposable { // Compute x/y based on display bounds // Note: important to use Math.round() because Electron does not seem to be too happy about // display coordinates that are not absolute numbers. - let state = defaultWindowState(); + let state = defaultWindowState(undefined, isWorkspaceIdentifier(configuration.workspace) || isSingleFolderWorkspaceIdentifier(configuration.workspace)); state.x = Math.round(displayToUse.bounds.x + (displayToUse.bounds.width / 2) - (state.width! / 2)); state.y = Math.round(displayToUse.bounds.y + (displayToUse.bounds.height / 2) - (state.height! / 2)); diff --git a/src/vs/workbench/browser/layout.ts b/src/vs/workbench/browser/layout.ts index 59323d7facd..22ff6111dff 100644 --- a/src/vs/workbench/browser/layout.ts +++ b/src/vs/workbench/browser/layout.ts @@ -18,7 +18,7 @@ import { IConfigurationChangeEvent, IConfigurationService, isConfigured } from ' import { ITitleService } from '../services/title/browser/titleService.js'; import { ServicesAccessor } from '../../platform/instantiation/common/instantiation.js'; import { StartupKind, ILifecycleService } from '../services/lifecycle/common/lifecycle.js'; -import { getMenuBarVisibility, IPath, hasNativeTitlebar, hasCustomTitlebar, TitleBarSetting, CustomTitleBarVisibility, useWindowControlsOverlay, DEFAULT_WINDOW_SIZE, hasNativeMenu, MenuSettings } from '../../platform/window/common/window.js'; +import { getMenuBarVisibility, IPath, hasNativeTitlebar, hasCustomTitlebar, TitleBarSetting, CustomTitleBarVisibility, useWindowControlsOverlay, DEFAULT_EMPTY_WINDOW_SIZE, DEFAULT_WORKSPACE_WINDOW_SIZE, hasNativeMenu, MenuSettings } from '../../platform/window/common/window.js'; import { IHostService } from '../services/host/browser/host.js'; import { IBrowserWorkbenchEnvironmentService } from '../services/environment/browser/environmentService.js'; import { IEditorService } from '../services/editor/common/editorService.js'; @@ -132,7 +132,8 @@ export const TITLE_BAR_SETTINGS = [ TitleBarSetting.CUSTOM_TITLE_BAR_VISIBILITY, ]; -const DEFAULT_WINDOW_DIMENSIONS = new Dimension(DEFAULT_WINDOW_SIZE.width, DEFAULT_WINDOW_SIZE.height); +const DEFAULT_EMPTY_WINDOW_DIMENSIONS = new Dimension(DEFAULT_EMPTY_WINDOW_SIZE.width, DEFAULT_EMPTY_WINDOW_SIZE.height); +const DEFAULT_WORKSPACE_WINDOW_DIMENSIONS = new Dimension(DEFAULT_WORKSPACE_WINDOW_SIZE.width, DEFAULT_WORKSPACE_WINDOW_SIZE.height); export abstract class Layout extends Disposable implements IWorkbenchLayoutService { @@ -626,7 +627,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi } private initLayoutState(lifecycleService: ILifecycleService, fileService: IFileService): void { - this._mainContainerDimension = getClientArea(this.parent, DEFAULT_WINDOW_DIMENSIONS); // running with fallback to ensure no error is thrown (https://github.com/microsoft/vscode/issues/240242) + this._mainContainerDimension = getClientArea(this.parent, this.contextService.getWorkbenchState() === WorkbenchState.EMPTY ? DEFAULT_EMPTY_WINDOW_DIMENSIONS : DEFAULT_WORKSPACE_WINDOW_DIMENSIONS); // running with fallback to ensure no error is thrown (https://github.com/microsoft/vscode/issues/240242) this.stateModel = new LayoutStateModel(this.storageService, this.configurationService, this.contextService); this.stateModel.load({ @@ -1626,7 +1627,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi this._mainContainerDimension = getClientArea(this.state.runtime.mainWindowFullscreen ? mainWindow.document.body : // in fullscreen mode, make sure to use element because this.parent, // in that case the workbench will span the entire site - DEFAULT_WINDOW_DIMENSIONS // running with fallback to ensure no error is thrown (https://github.com/microsoft/vscode/issues/240242) + this.contextService.getWorkbenchState() === WorkbenchState.EMPTY ? DEFAULT_EMPTY_WINDOW_DIMENSIONS : DEFAULT_WORKSPACE_WINDOW_DIMENSIONS // running with fallback to ensure no error is thrown (https://github.com/microsoft/vscode/issues/240242) ); this.logService.trace(`Layout#layout, height: ${this._mainContainerDimension.height}, width: ${this._mainContainerDimension.width}`); diff --git a/test/automation/src/playwrightBrowser.ts b/test/automation/src/playwrightBrowser.ts index 6a2334fdc78..ca4b67e5ed2 100644 --- a/test/automation/src/playwrightBrowser.ts +++ b/test/automation/src/playwrightBrowser.ts @@ -111,7 +111,7 @@ async function launchBrowser(options: LaunchOptions, endpoint: string) { } const page = await measureAndLog(() => context.newPage(), 'context.newPage()', logger); - await measureAndLog(() => page.setViewportSize({ width: 1200, height: 800 }), 'page.setViewportSize', logger); + await measureAndLog(() => page.setViewportSize({ width: 1440, height: 900 }), 'page.setViewportSize', logger); if (options.verbose) { context.on('page', () => logger.log(`Playwright (Browser): context.on('page')`)); diff --git a/test/integration/browser/src/index.ts b/test/integration/browser/src/index.ts index 47ac09d9f8c..15475567df6 100644 --- a/test/integration/browser/src/index.ts +++ b/test/integration/browser/src/index.ts @@ -57,8 +57,8 @@ if (args.help) { process.exit(1); } -const width = 1200; -const height = 800; +const width = 1440; +const height = 900; type BrowserType = 'chromium' | 'firefox' | 'webkit'; type BrowserChannel = 'msedge' | 'chrome';