Skip to content

Commit c718903

Browse files
authored
Linux: Support OS title menu in custom title bar (fix microsoft#241467) (microsoft#250324)
1 parent a74b37c commit c718903

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Emitter, Event } from '../../../base/common/event.js';
1111
import { Disposable } from '../../../base/common/lifecycle.js';
1212
import { FileAccess, Schemas } from '../../../base/common/network.js';
1313
import { getMarks, mark } from '../../../base/common/performance.js';
14-
import { isBigSurOrNewer, isMacintosh, isWindows } from '../../../base/common/platform.js';
14+
import { isBigSurOrNewer, isLinux, isMacintosh, isWindows } from '../../../base/common/platform.js';
1515
import { URI } from '../../../base/common/uri.js';
1616
import { localize } from '../../../nls.js';
1717
import { release } from 'os';
@@ -172,30 +172,15 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
172172
}
173173
}
174174

175-
// Setup windows system context menu so it only is allowed in certain cases
176-
if (isWindows && useCustomTitleStyle) {
177-
this._register(Event.fromNodeEventEmitter(win, 'system-context-menu', (event: Electron.Event, point: Electron.Point) => ({ event, point }))((e) => {
175+
// Setup windows/linux system context menu so it only is allowed over the app icon
176+
if ((isWindows || (isLinux && typeof electron.screen.screenToDipPoint === 'function') /* TODO@bpasero remove check */) && useCustomTitleStyle) {
177+
this._register(Event.fromNodeEventEmitter(win, 'system-context-menu', (event: Electron.Event, point: Electron.Point) => ({ event, point }))(e => {
178178
const [x, y] = win.getPosition();
179179
const cursorPos = electron.screen.screenToDipPoint(e.point);
180180
const cx = Math.floor(cursorPos.x) - x;
181181
const cy = Math.floor(cursorPos.y) - y;
182182

183-
// In some cases, show the default system context menu
184-
// 1) The mouse position is not within the title bar
185-
// 2) The mouse position is within the title bar, but over the app icon
186-
// We do not know the exact title bar height but we make an estimate based on window height
187-
const shouldTriggerDefaultSystemContextMenu = () => {
188-
// Use the custom context menu when over the title bar, but not over the app icon
189-
// The app icon is estimated to be 30px wide
190-
// The title bar is estimated to be the max of 35px and 15% of the window height
191-
if (cx > 30 && cy >= 0 && cy <= Math.max(win.getBounds().height * 0.15, 35)) {
192-
return false;
193-
}
194-
195-
return true;
196-
};
197-
198-
if (!shouldTriggerDefaultSystemContextMenu()) {
183+
if (cx > 35 /* Cursor is beyond app icon in title bar */) {
199184
e.event.preventDefault();
200185

201186
this._onDidTriggerSystemContextMenu.fire({ x: cx, y: cy });

0 commit comments

Comments
 (0)