Skip to content

Commit ab9f00c

Browse files
authored
linux - compute WCO width based on actual values (microsoft#227075)
1 parent 4711122 commit ab9f00c

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

build/lib/stylelint/vscode-known-variables.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@
831831
"--testMessageDecorationFontFamily",
832832
"--testMessageDecorationFontSize",
833833
"--title-border-bottom-color",
834+
"--title-wco-width",
834835
"--vscode-chat-list-background",
835836
"--vscode-editorCodeLens-fontFamily",
836837
"--vscode-editorCodeLens-fontFamilyDefault",
@@ -880,4 +881,4 @@
880881
"--widget-color",
881882
"--text-link-decoration"
882883
]
883-
}
884+
}

src/vs/base/browser/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ export function isWCOEnabled(): boolean {
136136

137137
// Returns the bounding rect of the titlebar area if it is supported and defined
138138
// See docs at https://developer.mozilla.org/en-US/docs/Web/API/WindowControlsOverlay/getTitlebarAreaRect
139-
export function getWCOBoundingRect(): DOMRect | undefined {
140-
return (navigator as any)?.windowControlsOverlay?.getTitlebarAreaRect();
139+
export function getWCOTitlebarAreaRect(targetWindow: Window): DOMRect | undefined {
140+
return (targetWindow.navigator as any)?.windowControlsOverlay?.getTitlebarAreaRect();
141141
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@
326326
}
327327

328328
.monaco-workbench.linux:not(.web) .part.titlebar .window-controls-container.wco-enabled {
329-
width: calc(100px / var(--zoom-factor, 1)); /* TODO@bpasero TODO@benibenj this should not be hardcoded (https://github.com/microsoft/vscode/issues/226804) */
329+
width: calc(var(--title-wco-width, 138px) / var(--zoom-factor, 1));
330330
}
331331

332332
.monaco-workbench.linux:not(.web) .part.titlebar .titlebar-container.counter-zoom .window-controls-container.wco-enabled {
333-
width: 100px; /* TODO@bpasero TODO@benibenj this should not be hardcoded (https://github.com/microsoft/vscode/issues/226804) */
333+
width: var(--title-wco-width, 138px);
334334
}
335335

336336
.monaco-workbench:not(.web):not(.mac) .part.titlebar .titlebar-container:not(.counter-zoom) .window-controls-container * {

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

Lines changed: 9 additions & 2 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 { getWCOBoundingRect, getZoomFactor, isWCOEnabled } from 'vs/base/browser/browser';
10+
import { getWCOTitlebarAreaRect, getZoomFactor, isWCOEnabled } 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';
@@ -228,7 +228,7 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
228228
const wcoEnabled = isWeb && isWCOEnabled();
229229
let value = this.isCommandCenterVisible || wcoEnabled ? DEFAULT_CUSTOM_TITLEBAR_HEIGHT : 30;
230230
if (wcoEnabled) {
231-
value = Math.max(value, getWCOBoundingRect()?.height ?? 0);
231+
value = Math.max(value, getWCOTitlebarAreaRect(getWindow(this.element))?.height ?? 0);
232232
}
233233

234234
return value / (this.preventZoom ? getZoomFactor(getWindow(this.element)) : 1);
@@ -499,6 +499,13 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart {
499499
this.windowControlsContainer = append(windowControlsLocation === 'left' ? this.leftContent : this.rightContent, $('div.window-controls-container'));
500500
if (isWCOEnabled()) {
501501
this.windowControlsContainer.classList.add('wco-enabled');
502+
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+
}
502509
}
503510
}
504511
}

0 commit comments

Comments
 (0)