Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring zoomable title bar to macos #155354

Merged
merged 1 commit into from Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/part.ts
Expand Up @@ -126,7 +126,7 @@ export abstract class Part extends Component implements ISerializableView {

//#region ISerializableView

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

element!: HTMLElement;
Expand Down
23 changes: 17 additions & 6 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Expand Up @@ -49,8 +49,9 @@ export class TitlebarPart extends Part implements ITitleService {
readonly maximumWidth: number = Number.POSITIVE_INFINITY;
get minimumHeight(): number {
const value = this.isCommandCenterVisible ? 35 : 30;
return value / (this.currentMenubarVisibility === 'hidden' || getZoomFactor() < 1 ? getZoomFactor() : 1);
return value / (this.useCounterZoom ? getZoomFactor() : 1);
}

get maximumHeight(): number { return this.minimumHeight; }

//#endregion
Expand Down Expand Up @@ -158,6 +159,7 @@ export class TitlebarPart extends Part implements ITitleService {

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

if (event.affectsConfiguration(TitlebarPart.configCommandCenter)) {
Expand Down Expand Up @@ -416,17 +418,26 @@ export class TitlebarPart extends Part implements ITitleService {
return this.configurationService.getValue<boolean>('workbench.layoutControl.enabled');
}

protected get useCounterZoom(): boolean {
// Prevent zooming behavior if any of the following conditions are met:
// 1. Shrinking below the window control size (zoom < 1)
// 2. No custom items are present in the title bar
const zoomFactor = getZoomFactor();

const noMenubar = this.currentMenubarVisibility === 'hidden' || (!isWeb && isMacintosh);
const noCommandCenter = !this.isCommandCenterVisible;
const noLayoutControls = !this.layoutControlEnabled;
return zoomFactor < 1 || (noMenubar && noCommandCenter && noLayoutControls);
}

updateLayout(dimension: Dimension): void {
this.lastLayoutDimensions = dimension;

if (getTitleBarStyle(this.configurationService) === 'custom') {
// Prevent zooming behavior if any of the following conditions are met:
// 1. Native macOS
// 2. Menubar is hidden
// 3. Shrinking below the window control size (zoom < 1)
const zoomFactor = getZoomFactor();

this.element.style.setProperty('--zoom-factor', zoomFactor.toString());
this.rootContainer.classList.toggle('counter-zoom', zoomFactor < 1 || (!isWeb && isMacintosh) || this.currentMenubarVisibility === 'hidden');
this.rootContainer.classList.toggle('counter-zoom', this.useCounterZoom);

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

Expand Down
Expand Up @@ -43,7 +43,8 @@ export class TitlebarPart extends BrowserTitleBarPart {
if (!isMacintosh) {
return super.minimumHeight;
}
return (this.isCommandCenterVisible ? 35 : this.getMacTitlebarSize()) / getZoomFactor();

return (this.isCommandCenterVisible ? 35 : this.getMacTitlebarSize()) / (this.useCounterZoom ? getZoomFactor() : 1);
}
override get maximumHeight(): number { return this.minimumHeight; }

Expand Down