Skip to content

Commit 054a536

Browse files
authored
Merge pull request microsoft#155276 from microsoft/joh/cruel-hoverfly
joh/cruel hoverfly
2 parents 425a6de + 338a23f commit 054a536

File tree

14 files changed

+94
-46
lines changed

14 files changed

+94
-46
lines changed

src/vs/platform/actions/common/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class MenuId {
109109
static readonly TestPeekTitle = new MenuId('TestPeekTitle');
110110
static readonly TouchBarContext = new MenuId('TouchBarContext');
111111
static readonly TitleBarContext = new MenuId('TitleBarContext');
112+
static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext');
112113
static readonly TunnelContext = new MenuId('TunnelContext');
113114
static readonly TunnelPrivacy = new MenuId('TunnelPrivacy');
114115
static readonly TunnelProtocol = new MenuId('TunnelProtocol');

src/vs/platform/native/common/native.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface ICommonNativeHostService {
5555

5656
readonly onDidChangePassword: Event<{ service: string; account: string }>;
5757

58+
readonly onDidTriggerSystemContextMenu: Event<{ windowId: number; x: number; y: number }>;
59+
5860
// Window
5961
getWindows(): Promise<IOpenedWindow[]>;
6062
getWindowCount(): Promise<number>;

src/vs/platform/native/electron-main/nativeHostMainService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain
7474
//#region Events
7575

7676
readonly onDidOpenWindow = Event.map(this.windowsMainService.onDidOpenWindow, window => window.id);
77+
readonly onDidTriggerSystemContextMenu = Event.filter(Event.map(this.windowsMainService.onDidTriggerSystemContextMenu, ({ window, x, y }) => { return { windowId: window.id, x, y }; }), ({ windowId }) => !!this.windowsMainService.getWindowById(windowId));
7778

7879
readonly onDidMaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));
7980
readonly onDidUnmaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-unmaximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));

src/vs/platform/window/electron-main/window.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ICodeWindow extends IDisposable {
1717

1818
readonly onWillLoad: Event<ILoadEvent>;
1919
readonly onDidSignalReady: Event<void>;
20+
readonly onDidTriggerSystemContextMenu: Event<{ x: number; y: number }>;
2021
readonly onDidClose: Event<void>;
2122
readonly onDidDestroy: Event<void>;
2223

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export class CodeWindow extends Disposable implements ICodeWindow {
9090
private readonly _onDidSignalReady = this._register(new Emitter<void>());
9191
readonly onDidSignalReady = this._onDidSignalReady.event;
9292

93+
private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ x: number; y: number }>());
94+
readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event;
95+
9396
private readonly _onDidClose = this._register(new Emitter<void>());
9497
readonly onDidClose = this._onDidClose.event;
9598

@@ -286,6 +289,22 @@ export class CodeWindow extends Disposable implements ICodeWindow {
286289
this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any
287290
}
288291

292+
// Windows Custom System Context Menu
293+
// See https://github.com/electron/electron/issues/24893
294+
if (isWindows && useCustomTitleStyle) {
295+
const WM_INITMENU = 0x0116;
296+
this._win.hookWindowMessage(WM_INITMENU, () => {
297+
const [x, y] = this._win.getPosition();
298+
const cursorPos = screen.getCursorScreenPoint();
299+
300+
this._win.setEnabled(false);
301+
this._win.setEnabled(true);
302+
303+
this._onDidTriggerSystemContextMenu.fire({ x: cursorPos.x - x, y: cursorPos.y - y });
304+
return 0; // skip native menu
305+
});
306+
}
307+
289308
// TODO@electron (Electron 4 regression): when running on multiple displays where the target display
290309
// to open the window has a larger resolution than the primary display, the window will not size
291310
// correctly unless we set the bounds again (https://github.com/microsoft/vscode/issues/74872)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface IWindowsMainService {
2222

2323
readonly onDidOpenWindow: Event<ICodeWindow>;
2424
readonly onDidSignalReadyWindow: Event<ICodeWindow>;
25+
readonly onDidTriggerSystemContextMenu: Event<{ window: ICodeWindow; x: number; y: number }>;
2526
readonly onDidDestroyWindow: Event<ICodeWindow>;
2627

2728
open(openConfig: IOpenConfiguration): ICodeWindow[];

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
187187
private readonly _onDidChangeWindowsCount = this._register(new Emitter<IWindowsCountChangedEvent>());
188188
readonly onDidChangeWindowsCount = this._onDidChangeWindowsCount.event;
189189

190+
private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ window: ICodeWindow; x: number; y: number }>());
191+
readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event;
192+
190193
private readonly windowsStateHandler = this._register(new WindowsStateHandler(this, this.stateMainService, this.lifecycleMainService, this.logService, this.configurationService));
191194

192195
constructor(
@@ -1379,6 +1382,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
13791382
once(createdWindow.onDidSignalReady)(() => this._onDidSignalReadyWindow.fire(createdWindow));
13801383
once(createdWindow.onDidClose)(() => this.onWindowClosed(createdWindow));
13811384
once(createdWindow.onDidDestroy)(() => this._onDidDestroyWindow.fire(createdWindow));
1385+
createdWindow.onDidTriggerSystemContextMenu(({ x, y }) => this._onDidTriggerSystemContextMenu.fire({ window: createdWindow, x, y }));
13821386

13831387
const webContents = assertIsDefined(createdWindow.win?.webContents);
13841388
webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own

src/vs/platform/windows/test/electron-main/windowsFinder.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ suite('WindowsFinder', () => {
3434
function createTestCodeWindow(options: { lastFocusTime: number; openedFolderUri?: URI; openedWorkspace?: IWorkspaceIdentifier }): ICodeWindow {
3535
return new class implements ICodeWindow {
3636
onWillLoad: Event<ILoadEvent> = Event.None;
37+
onDidTriggerSystemContextMenu: Event<{ x: number; y: number }> = Event.None;
3738
onDidSignalReady: Event<void> = Event.None;
3839
onDidClose: Event<void> = Event.None;
3940
onDidDestroy: Event<void> = Event.None;

src/vs/workbench/browser/actions/layoutActions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ if (isWindows || isLinux || isWeb) {
583583
id: MenuId.MenubarAppearanceMenu,
584584
group: '2_workbench_layout',
585585
order: 0
586+
}, {
587+
id: MenuId.TitleBarContext,
588+
order: 0
586589
}]
587590
});
588591
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
width: 35px;
192192
height: 100%;
193193
position: relative;
194-
z-index: 3000;
194+
z-index: 2500;
195195
flex-shrink: 0;
196196
}
197197

0 commit comments

Comments
 (0)