From 9b44eda62a9ea9c6b9aa70f14edd7e876200dffa Mon Sep 17 00:00:00 2001 From: SteVen Batten <6561887+sbatten@users.noreply.github.com> Date: Wed, 27 Jul 2022 11:31:44 -0700 Subject: still allow system context menu in some cases (#156488) fixes #156222 --- src/vs/platform/windows/electron-main/window.ts | 29 ++++++++++++++++++---- .../parts/titlebar/titlebarPart.ts | 17 +------------ 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'src/vs') diff --git a/src/vs/platform/windows/electron-main/window.ts b/src/vs/platform/windows/electron-main/window.ts index fce751e1f2d..938c6eb7300 100644 --- a/src/vs/platform/windows/electron-main/window.ts +++ b/src/vs/platform/windows/electron-main/window.ts @@ -305,14 +305,33 @@ export class CodeWindow extends Disposable implements ICodeWindow { this._win.hookWindowMessage(WM_INITMENU, () => { const [x, y] = this._win.getPosition(); const cursorPos = screen.getCursorScreenPoint(); + const cx = cursorPos.x - x; + const cy = cursorPos.y - y; + + // In some cases, show the default system context menu + // 1) The mouse position is not within the title bar + // 2) The mouse position is within the title bar, but over the app icon + // We do not know the exact title bar height but we make an estimate based on window height + const shouldTriggerDefaultSystemContextMenu = () => { + // Use the custom context menu when over the title bar, but not over the app icon + // The app icon is estimated to be 30px wide + // The title bar is estimated to be the max of 35px and 15% of the window height + if (cx > 30 && cy >= 0 && cy <= Math.max(this._win.getBounds().height * 0.15, 35)) { + return false; + } + + return true; + }; - // This is necessary to make sure the native system context menu does not show up. - this._win.setEnabled(false); - this._win.setEnabled(true); + if (!shouldTriggerDefaultSystemContextMenu()) { + // This is necessary to make sure the native system context menu does not show up. + this._win.setEnabled(false); + this._win.setEnabled(true); - this._onDidTriggerSystemContextMenu.fire({ x: cursorPos.x - x, y: cursorPos.y - y }); + this._onDidTriggerSystemContextMenu.fire({ x: cx, y: cy }); + } - return 0; // skip native menu + return 0; }); } diff --git a/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts b/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts index f6f5b60e313..4720f73a32a 100644 --- a/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts @@ -207,22 +207,7 @@ export class TitlebarPart extends BrowserTitleBarPart { } const zoomFactor = getZoomFactor(); - const boundingRect = this.rootContainer.getBoundingClientRect(); - const eventPosition = { x, y }; - const relativeCoordinates = { x, y }; - // When comparing the coordinates with the title bar, account for zoom level if not using counter zoom. - if (!this.useCounterZoom) { - relativeCoordinates.x /= zoomFactor; - relativeCoordinates.y /= zoomFactor; - } - - // Don't trigger the menu if the click is not over the title bar - if (relativeCoordinates.x < boundingRect.left || relativeCoordinates.x > boundingRect.right || - relativeCoordinates.y < boundingRect.top || relativeCoordinates.y > boundingRect.bottom) { - return; - } - - this.onContextMenu(new MouseEvent('mouseup', { clientX: eventPosition.x / zoomFactor, clientY: eventPosition.y / zoomFactor }), MenuId.TitleBarContext); + this.onContextMenu(new MouseEvent('mouseup', { clientX: x / zoomFactor, clientY: y / zoomFactor }), MenuId.TitleBarContext); })); } -- cgit v1.2.3