Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/vs
diff options
context:
space:
mode:
authorSteVen Batten <6561887+sbatten@users.noreply.github.com>2022-07-27 21:31:44 +0300
committerGitHub <noreply@github.com>2022-07-27 21:31:44 +0300
commit9b44eda62a9ea9c6b9aa70f14edd7e876200dffa (patch)
tree5a61134d8ee0699c1a038adb28ab559d4cf936d0 /src/vs
parent857412ab10ab7377d0ba209811d4f8711d7c5693 (diff)
still allow system context menu in some cases (#156488)
fixes #156222
Diffstat (limited to 'src/vs')
-rw-r--r--src/vs/platform/windows/electron-main/window.ts29
-rw-r--r--src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts17
2 files changed, 25 insertions, 21 deletions
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);
}));
}