From f6d9f0edf5b3f652d41d72cb26d9e8ea2452297e Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 29 Aug 2024 21:22:47 +0200 Subject: [PATCH] title - more style fixes for proper positioning (#227139) --- .../parts/titlebar/media/titlebarpart.css | 2 +- .../browser/parts/titlebar/titlebarPart.ts | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css index 0cb74bbe2e6..9a66a127a4d 100644 --- a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css +++ b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css @@ -326,7 +326,7 @@ } .monaco-workbench.linux:not(.web) .part.titlebar .window-controls-container.wco-enabled { - width: calc(var(--title-wco-width, 138px) / var(--zoom-factor, 1)); + width: calc(var(--title-wco-width, 138px)); } .monaco-workbench.linux:not(.web) .part.titlebar .titlebar-container.counter-zoom .window-controls-container.wco-enabled { diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 202852d8cfa..ff858e53afe 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -7,7 +7,7 @@ import 'vs/css!./media/titlebarpart'; import { localize, localize2 } from 'vs/nls'; import { MultiWindowParts, Part } from 'vs/workbench/browser/part'; import { ITitleService } from 'vs/workbench/services/title/browser/titleService'; -import { getWCOTitlebarAreaRect, getZoomFactor, isWCOEnabled } from 'vs/base/browser/browser'; +import { getWCOTitlebarAreaRect, getZoomFactor, isWCOEnabled, onDidChangeZoomLevel } from 'vs/base/browser/browser'; import { MenuBarVisibility, getTitleBarStyle, getMenuBarVisibility, TitlebarStyle, hasCustomTitlebar, hasNativeTitlebar, DEFAULT_CUSTOM_TITLEBAR_HEIGHT } from 'vs/platform/window/common/window'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; @@ -478,7 +478,7 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart { // Window Controls Container if (!hasNativeTitlebar(this.configurationService, this.titleBarStyle)) { - let windowControlsLocation = isMacintosh ? 'left' : 'right'; + let primaryWindowControlsLocation = isMacintosh ? 'left' : 'right'; if (isMacintosh && isNative) { // Check if the locale is RTL, macOS will move traffic lights in RTL locales @@ -486,26 +486,37 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart { const localeInfo = new Intl.Locale(platformLocale) as any; if (localeInfo?.textInfo?.direction === 'rtl') { - windowControlsLocation = 'right'; + primaryWindowControlsLocation = 'right'; } } - if (isMacintosh && isNative && windowControlsLocation === 'left') { + if (isMacintosh && isNative && primaryWindowControlsLocation === 'left') { // macOS native: controls are on the left and the container is not needed to make room // for something, except for web where a custom menu being supported). not putting the // container helps with allowing to move the window when clicking very close to the // window control buttons. } else { - this.windowControlsContainer = append(windowControlsLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container')); + this.windowControlsContainer = append(primaryWindowControlsLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container')); + if (isWeb) { + // Web: its possible to have control overlays on both sides, for example on macOS + // with window controls on the left and PWA controls on the right. + append(primaryWindowControlsLocation === 'left' ? this.rightContent : this.leftContent, $('div.window-controls-container')); + } + if (isWCOEnabled()) { this.windowControlsContainer.classList.add('wco-enabled'); - const targetWindow = getWindow(this.element); - const wcoTitlebarAreaRect = getWCOTitlebarAreaRect(targetWindow); - if (wcoTitlebarAreaRect) { - const wcoWidth = targetWindow.innerWidth - wcoTitlebarAreaRect.width - wcoTitlebarAreaRect.x; - this.windowControlsContainer.style.setProperty('--title-wco-width', `${wcoWidth}px`); - } + const updateWCOWidthVariable = () => { + const targetWindow = getWindow(this.element); + const wcoTitlebarAreaRect = getWCOTitlebarAreaRect(targetWindow); + if (wcoTitlebarAreaRect) { + const wcoWidth = targetWindow.innerWidth - wcoTitlebarAreaRect.width - wcoTitlebarAreaRect.x; + this.windowControlsContainer?.style.setProperty('--title-wco-width', `${wcoWidth}px`); + } + }; + updateWCOWidthVariable(); + + this._register(onDidChangeZoomLevel(() => setTimeout(() => updateWCOWidthVariable(), 5))); // Somehow it does not get the right size without this timeout :-/ } } }