diff --git a/src/vs/base/browser/browser.ts b/src/vs/base/browser/browser.ts index 4194d976db257..2ac4671e49786 100644 --- a/src/vs/base/browser/browser.ts +++ b/src/vs/base/browser/browser.ts @@ -16,7 +16,7 @@ class WindowManager { public getZoomLevel(): number { return this._zoomLevel; } - public setZoomLevel(zoomLevel: number, isTrusted: boolean): void { + public setZoomLevel(zoomLevel: number): void { if (this._zoomLevel === zoomLevel) { return; } @@ -159,8 +159,8 @@ export function addMatchMediaChangeListener(query: string | MediaQueryList, call export const PixelRatio = new PixelRatioFacade(); /** A zoom index, e.g. 1, 2, 3 */ -export function setZoomLevel(zoomLevel: number, isTrusted: boolean): void { - WindowManager.INSTANCE.setZoomLevel(zoomLevel, isTrusted); +export function setZoomLevel(zoomLevel: number): void { + WindowManager.INSTANCE.setZoomLevel(zoomLevel); } export function getZoomLevel(): number { return WindowManager.INSTANCE.getZoomLevel(); diff --git a/src/vs/platform/window/electron-sandbox/window.ts b/src/vs/platform/window/electron-sandbox/window.ts index 7ffa0edf69cef..90f1371bdeee3 100644 --- a/src/vs/platform/window/electron-sandbox/window.ts +++ b/src/vs/platform/window/electron-sandbox/window.ts @@ -14,10 +14,7 @@ import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window'; export function applyZoom(zoomLevel: number): void { webFrame.setZoomLevel(zoomLevel); setZoomFactor(zoomLevelToZoomFactor(zoomLevel)); - // Cannot be trusted because the webFrame might take some time - // until it really applies the new zoom level - // See https://github.com/microsoft/vscode/issues/26151 - setZoomLevel(zoomLevel, false /* isTrusted */); + setZoomLevel(zoomLevel); } export function zoomIn(): void { diff --git a/src/vs/workbench/electron-sandbox/desktop.main.ts b/src/vs/workbench/electron-sandbox/desktop.main.ts index 9609e5f96bb7d..d2a26882677c2 100644 --- a/src/vs/workbench/electron-sandbox/desktop.main.ts +++ b/src/vs/workbench/electron-sandbox/desktop.main.ts @@ -5,10 +5,10 @@ import { localize } from 'vs/nls'; import product from 'vs/platform/product/common/product'; -import { INativeWindowConfiguration, zoomLevelToZoomFactor } from 'vs/platform/window/common/window'; +import { INativeWindowConfiguration, IWindowsConfiguration } from 'vs/platform/window/common/window'; import { Workbench } from 'vs/workbench/browser/workbench'; import { NativeWindow } from 'vs/workbench/electron-sandbox/window'; -import { setZoomLevel, setZoomFactor, setFullscreen } from 'vs/base/browser/browser'; +import { setFullscreen } from 'vs/base/browser/browser'; import { domContentLoaded } from 'vs/base/browser/dom'; import { onUnexpectedError } from 'vs/base/common/errors'; import { URI } from 'vs/base/common/uri'; @@ -58,6 +58,8 @@ import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/c import { BrowserSocketFactory } from 'vs/platform/remote/browser/browserSocketFactory'; import { RemoteSocketFactoryService, IRemoteSocketFactoryService } from 'vs/platform/remote/common/remoteSocketFactoryService'; import { ElectronRemoteResourceLoader } from 'vs/platform/remote/electron-sandbox/electronRemoteResourceLoader'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { applyZoom } from 'vs/platform/window/electron-sandbox/window'; export class DesktopMain extends Disposable { @@ -74,10 +76,7 @@ export class DesktopMain extends Disposable { // Massage configuration file URIs this.reviveUris(); - // Browser config - const zoomLevel = this.configuration.zoomLevel || 0; - setZoomFactor(zoomLevelToZoomFactor(zoomLevel)); - setZoomLevel(zoomLevel, true /* isTrusted */); + // Apply fullscreen early if configured setFullscreen(!!this.configuration.fullscreen); } @@ -112,6 +111,13 @@ export class DesktopMain extends Disposable { // Init services and wait for DOM to be ready in parallel const [services] = await Promise.all([this.initServices(), domContentLoaded()]); + // Apply zoom level early once we have a configuration service + // and before the workbench is created to prevent flickering. + // We also need to respect that zoom level can be configured per + // workspace, so we need the resolved configuration service. + // (fixes https://github.com/microsoft/vscode/issues/187982) + this.applyConfiguredWindowZoomLevel(services.configurationService); + // Create Workbench const workbench = new Workbench(document.body, { extraClasses: this.getExtraClasses() }, services.serviceCollection, services.logService); @@ -125,6 +131,13 @@ export class DesktopMain extends Disposable { this._register(instantiationService.createInstance(NativeWindow)); } + private applyConfiguredWindowZoomLevel(configurationService: IConfigurationService) { + const windowConfig = configurationService.getValue(); + const windowZoomLevel = typeof windowConfig.window?.zoomLevel === 'number' ? windowConfig.window.zoomLevel : 0; + + applyZoom(windowZoomLevel); + } + private getExtraClasses(): string[] { if (isMacintosh) { if (this.configuration.os.release > '20.0.0') { @@ -142,7 +155,7 @@ export class DesktopMain extends Disposable { this._register(workbench.onDidShutdown(() => this.dispose())); } - private async initServices(): Promise<{ serviceCollection: ServiceCollection; logService: ILogService; storageService: NativeWorkbenchStorageService }> { + private async initServices(): Promise<{ serviceCollection: ServiceCollection; logService: ILogService; storageService: NativeWorkbenchStorageService; configurationService: IConfigurationService }> { const serviceCollection = new ServiceCollection(); @@ -310,7 +323,7 @@ export class DesktopMain extends Disposable { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - return { serviceCollection, logService, storageService }; + return { serviceCollection, logService, storageService, configurationService }; } private resolveWorkspaceIdentifier(environmentService: INativeWorkbenchEnvironmentService): IAnyWorkspaceIdentifier { diff --git a/src/vs/workbench/electron-sandbox/window.ts b/src/vs/workbench/electron-sandbox/window.ts index 12859500a5882..7ab81debcbe34 100644 --- a/src/vs/workbench/electron-sandbox/window.ts +++ b/src/vs/workbench/electron-sandbox/window.ts @@ -79,8 +79,6 @@ export class NativeWindow extends Disposable { private readonly customTitleContextMenuDisposable = this._register(new DisposableStore()); - private previousConfiguredZoomLevel: number | undefined; - private readonly addFoldersScheduler = this._register(new RunOnceScheduler(() => this.doAddFolders(), 100)); private pendingFoldersToAdd: URI[] = []; @@ -320,7 +318,6 @@ export class NativeWindow extends Disposable { }); // Zoom level changes - this.updateWindowZoomLevel(); this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration('window.zoomLevel')) { this.updateWindowZoomLevel(); @@ -605,21 +602,10 @@ export class NativeWindow extends Disposable { private updateWindowZoomLevel(): void { const windowConfig = this.configurationService.getValue(); + const windowZoomLevel = typeof windowConfig.window?.zoomLevel === 'number' ? windowConfig.window.zoomLevel : 0; - let configuredZoomLevel = 0; - if (windowConfig.window && typeof windowConfig.window.zoomLevel === 'number') { - configuredZoomLevel = windowConfig.window.zoomLevel; - - // Leave early if the configured zoom level did not change (https://github.com/microsoft/vscode/issues/1536) - if (this.previousConfiguredZoomLevel === configuredZoomLevel) { - return; - } - - this.previousConfiguredZoomLevel = configuredZoomLevel; - } - - if (getZoomLevel() !== configuredZoomLevel) { - applyZoom(configuredZoomLevel); + if (getZoomLevel() !== windowZoomLevel) { + applyZoom(windowZoomLevel); } }