Skip to content

Commit f6d9f0e

Browse files
authored
title - more style fixes for proper positioning (microsoft#227139)
1 parent beefaee commit f6d9f0e

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
}
327327

328328
.monaco-workbench.linux:not(.web) .part.titlebar .window-controls-container.wco-enabled {
329-
width: calc(var(--title-wco-width, 138px) / var(--zoom-factor, 1));
329+
width: calc(var(--title-wco-width, 138px));
330330
}
331331

332332
.monaco-workbench.linux:not(.web) .part.titlebar .titlebar-container.counter-zoom .window-controls-container.wco-enabled {

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'vs/css!./media/titlebarpart';
77
import { localize, localize2 } from 'vs/nls';
88
import { MultiWindowParts, Part } from 'vs/workbench/browser/part';
99
import { ITitleService } from 'vs/workbench/services/title/browser/titleService';
10-
import { getWCOTitlebarAreaRect, getZoomFactor, isWCOEnabled } from 'vs/base/browser/browser';
10+
import { getWCOTitlebarAreaRect, getZoomFactor, isWCOEnabled, onDidChangeZoomLevel } from 'vs/base/browser/browser';
1111
import { MenuBarVisibility, getTitleBarStyle, getMenuBarVisibility, TitlebarStyle, hasCustomTitlebar, hasNativeTitlebar, DEFAULT_CUSTOM_TITLEBAR_HEIGHT } from 'vs/platform/window/common/window';
1212
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
1313
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
@@ -478,34 +478,45 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
478478

479479
// Window Controls Container
480480
if (!hasNativeTitlebar(this.configurationService, this.titleBarStyle)) {
481-
let windowControlsLocation = isMacintosh ? 'left' : 'right';
481+
let primaryWindowControlsLocation = isMacintosh ? 'left' : 'right';
482482
if (isMacintosh && isNative) {
483483

484484
// Check if the locale is RTL, macOS will move traffic lights in RTL locales
485485
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/textInfo
486486

487487
const localeInfo = new Intl.Locale(platformLocale) as any;
488488
if (localeInfo?.textInfo?.direction === 'rtl') {
489-
windowControlsLocation = 'right';
489+
primaryWindowControlsLocation = 'right';
490490
}
491491
}
492492

493-
if (isMacintosh && isNative && windowControlsLocation === 'left') {
493+
if (isMacintosh && isNative && primaryWindowControlsLocation === 'left') {
494494
// macOS native: controls are on the left and the container is not needed to make room
495495
// for something, except for web where a custom menu being supported). not putting the
496496
// container helps with allowing to move the window when clicking very close to the
497497
// window control buttons.
498498
} else {
499-
this.windowControlsContainer = append(windowControlsLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container'));
499+
this.windowControlsContainer = append(primaryWindowControlsLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container'));
500+
if (isWeb) {
501+
// Web: its possible to have control overlays on both sides, for example on macOS
502+
// with window controls on the left and PWA controls on the right.
503+
append(primaryWindowControlsLocation === 'left' ? this.rightContent : this.leftContent, $('div.window-controls-container'));
504+
}
505+
500506
if (isWCOEnabled()) {
501507
this.windowControlsContainer.classList.add('wco-enabled');
502508

503-
const targetWindow = getWindow(this.element);
504-
const wcoTitlebarAreaRect = getWCOTitlebarAreaRect(targetWindow);
505-
if (wcoTitlebarAreaRect) {
506-
const wcoWidth = targetWindow.innerWidth - wcoTitlebarAreaRect.width - wcoTitlebarAreaRect.x;
507-
this.windowControlsContainer.style.setProperty('--title-wco-width', `${wcoWidth}px`);
508-
}
509+
const updateWCOWidthVariable = () => {
510+
const targetWindow = getWindow(this.element);
511+
const wcoTitlebarAreaRect = getWCOTitlebarAreaRect(targetWindow);
512+
if (wcoTitlebarAreaRect) {
513+
const wcoWidth = targetWindow.innerWidth - wcoTitlebarAreaRect.width - wcoTitlebarAreaRect.x;
514+
this.windowControlsContainer?.style.setProperty('--title-wco-width', `${wcoWidth}px`);
515+
}
516+
};
517+
updateWCOWidthVariable();
518+
519+
this._register(onDidChangeZoomLevel(() => setTimeout(() => updateWCOWidthVariable(), 5))); // Somehow it does not get the right size without this timeout :-/
509520
}
510521
}
511522
}

0 commit comments

Comments
 (0)