Skip to content

Commit da2a179

Browse files
authored
bring zoomable title bar to macos (microsoft#155354)
bring zoomable menu bar to macos fixes microsoft#149740
1 parent 5acd950 commit da2a179

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/vs/workbench/browser/part.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export abstract class Part extends Component implements ISerializableView {
126126

127127
//#region ISerializableView
128128

129-
private _onDidChange = this._register(new Emitter<IViewSize | undefined>());
129+
protected _onDidChange = this._register(new Emitter<IViewSize | undefined>());
130130
get onDidChange(): Event<IViewSize | undefined> { return this._onDidChange.event; }
131131

132132
element!: HTMLElement;

src/vs/workbench/browser/parts/titlebar/titlebarPart.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ export class TitlebarPart extends Part implements ITitleService {
5050
readonly maximumWidth: number = Number.POSITIVE_INFINITY;
5151
get minimumHeight(): number {
5252
const value = this.isCommandCenterVisible ? 35 : 30;
53-
return value / (this.currentMenubarVisibility === 'hidden' || getZoomFactor() < 1 ? getZoomFactor() : 1);
53+
return value / (this.useCounterZoom ? getZoomFactor() : 1);
5454
}
55+
5556
get maximumHeight(): number { return this.minimumHeight; }
5657

5758
//#endregion
@@ -159,6 +160,7 @@ export class TitlebarPart extends Part implements ITitleService {
159160

160161
if (this.titleBarStyle !== 'native' && this.layoutControls && event.affectsConfiguration('workbench.layoutControl.enabled')) {
161162
this.layoutControls.classList.toggle('show-layout-control', this.layoutControlEnabled);
163+
this._onDidChange.fire(undefined);
162164
}
163165

164166
if (event.affectsConfiguration(TitlebarPart.configCommandCenter)) {
@@ -438,17 +440,26 @@ export class TitlebarPart extends Part implements ITitleService {
438440
return this.configurationService.getValue<boolean>('workbench.layoutControl.enabled');
439441
}
440442

443+
protected get useCounterZoom(): boolean {
444+
// Prevent zooming behavior if any of the following conditions are met:
445+
// 1. Shrinking below the window control size (zoom < 1)
446+
// 2. No custom items are present in the title bar
447+
const zoomFactor = getZoomFactor();
448+
449+
const noMenubar = this.currentMenubarVisibility === 'hidden' || (!isWeb && isMacintosh);
450+
const noCommandCenter = !this.isCommandCenterVisible;
451+
const noLayoutControls = !this.layoutControlEnabled;
452+
return zoomFactor < 1 || (noMenubar && noCommandCenter && noLayoutControls);
453+
}
454+
441455
updateLayout(dimension: Dimension): void {
442456
this.lastLayoutDimensions = dimension;
443457

444458
if (getTitleBarStyle(this.configurationService) === 'custom') {
445-
// Prevent zooming behavior if any of the following conditions are met:
446-
// 1. Native macOS
447-
// 2. Menubar is hidden
448-
// 3. Shrinking below the window control size (zoom < 1)
449459
const zoomFactor = getZoomFactor();
460+
450461
this.element.style.setProperty('--zoom-factor', zoomFactor.toString());
451-
this.rootContainer.classList.toggle('counter-zoom', zoomFactor < 1 || (!isWeb && isMacintosh) || this.currentMenubarVisibility === 'hidden');
462+
this.rootContainer.classList.toggle('counter-zoom', this.useCounterZoom);
452463

453464
runAtThisOrScheduleAtNextAnimationFrame(() => this.adjustTitleMarginToCenter());
454465

src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export class TitlebarPart extends BrowserTitleBarPart {
4343
if (!isMacintosh) {
4444
return super.minimumHeight;
4545
}
46-
return (this.isCommandCenterVisible ? 35 : this.getMacTitlebarSize()) / getZoomFactor();
46+
47+
return (this.isCommandCenterVisible ? 35 : this.getMacTitlebarSize()) / (this.useCounterZoom ? getZoomFactor() : 1);
4748
}
4849
override get maximumHeight(): number { return this.minimumHeight; }
4950

0 commit comments

Comments
 (0)