Skip to content

Commit

Permalink
Workspace level window.zoomLevel does not reset after closing proje…
Browse files Browse the repository at this point in the history
…ct (fix #187982) (#188655)
  • Loading branch information
bpasero authored Jul 24, 2023
1 parent e2693cf commit de6839a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/vs/base/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/vs/platform/window/electron-sandbox/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 21 additions & 8 deletions src/vs/workbench/electron-sandbox/desktop.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);

Expand All @@ -125,6 +131,13 @@ export class DesktopMain extends Disposable {
this._register(instantiationService.createInstance(NativeWindow));
}

private applyConfiguredWindowZoomLevel(configurationService: IConfigurationService) {
const windowConfig = configurationService.getValue<IWindowsConfiguration>();
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') {
Expand All @@ -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();


Expand Down Expand Up @@ -310,7 +323,7 @@ export class DesktopMain extends Disposable {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


return { serviceCollection, logService, storageService };
return { serviceCollection, logService, storageService, configurationService };
}

private resolveWorkspaceIdentifier(environmentService: INativeWorkbenchEnvironmentService): IAnyWorkspaceIdentifier {
Expand Down
20 changes: 3 additions & 17 deletions src/vs/workbench/electron-sandbox/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -605,21 +602,10 @@ export class NativeWindow extends Disposable {

private updateWindowZoomLevel(): void {
const windowConfig = this.configurationService.getValue<IWindowsConfiguration>();
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);
}
}

Expand Down

0 comments on commit de6839a

Please sign in to comment.