Skip to content

Commit 4e57a73

Browse files
authored
feat: allow windows to be excluded from the windows menu (electron#17404)
* feat: allow windows to be excluded from the windows menu * excludedfromWindowsMenu => excludedFromShownWindowsMenu * implement no-op for win & linux
1 parent ec5e0ef commit 4e57a73

File tree

8 files changed

+57
-0
lines changed

8 files changed

+57
-0
lines changed

atom/browser/api/atom_api_top_level_window.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,14 @@ void TopLevelWindow::SetSkipTaskbar(bool skip) {
567567
window_->SetSkipTaskbar(skip);
568568
}
569569

570+
void TopLevelWindow::SetExcludedFromShownWindowsMenu(bool excluded) {
571+
window_->SetExcludedFromShownWindowsMenu(excluded);
572+
}
573+
574+
bool TopLevelWindow::IsExcludedFromShownWindowsMenu() {
575+
return window_->IsExcludedFromShownWindowsMenu();
576+
}
577+
570578
void TopLevelWindow::SetSimpleFullScreen(bool simple_fullscreen) {
571579
window_->SetSimpleFullScreen(simple_fullscreen);
572580
}
@@ -1133,6 +1141,9 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
11331141
.SetMethod("addTabbedWindow", &TopLevelWindow::AddTabbedWindow)
11341142
.SetMethod("setWindowButtonVisibility",
11351143
&TopLevelWindow::SetWindowButtonVisibility)
1144+
.SetProperty("excludedFromShownWindowsMenu",
1145+
&TopLevelWindow::IsExcludedFromShownWindowsMenu,
1146+
&TopLevelWindow::SetExcludedFromShownWindowsMenu)
11361147
#endif
11371148
.SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar)
11381149
.SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide)

atom/browser/api/atom_api_top_level_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
145145
std::string GetTitle();
146146
void FlashFrame(bool flash);
147147
void SetSkipTaskbar(bool skip);
148+
void SetExcludedFromShownWindowsMenu(bool excluded);
149+
bool IsExcludedFromShownWindowsMenu();
148150
void SetSimpleFullScreen(bool simple_fullscreen);
149151
bool IsSimpleFullScreen();
150152
void SetKiosk(bool kiosk);

atom/browser/native_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class NativeWindow : public base::SupportsUserData,
136136
virtual std::string GetTitle() = 0;
137137
virtual void FlashFrame(bool flash) = 0;
138138
virtual void SetSkipTaskbar(bool skip) = 0;
139+
virtual void SetExcludedFromShownWindowsMenu(bool excluded) = 0;
140+
virtual bool IsExcludedFromShownWindowsMenu() = 0;
139141
virtual void SetSimpleFullScreen(bool simple_fullscreen) = 0;
140142
virtual bool IsSimpleFullScreen() = 0;
141143
virtual void SetKiosk(bool kiosk) = 0;

atom/browser/native_window_mac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class NativeWindowMac : public NativeWindow {
8787
std::string GetTitle() override;
8888
void FlashFrame(bool flash) override;
8989
void SetSkipTaskbar(bool skip) override;
90+
void SetExcludedFromShownWindowsMenu(bool excluded) override;
91+
bool IsExcludedFromShownWindowsMenu() override;
9092
void SetSimpleFullScreen(bool simple_fullscreen) override;
9193
bool IsSimpleFullScreen() override;
9294
void SetKiosk(bool kiosk) override;

atom/browser/native_window_mac.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,16 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
886886

887887
void NativeWindowMac::SetSkipTaskbar(bool skip) {}
888888

889+
bool NativeWindowMac::IsExcludedFromShownWindowsMenu() {
890+
NSWindow* window = GetNativeWindow().GetNativeNSWindow();
891+
return [window isExcludedFromWindowsMenu];
892+
}
893+
894+
void NativeWindowMac::SetExcludedFromShownWindowsMenu(bool excluded) {
895+
NSWindow* window = GetNativeWindow().GetNativeNSWindow();
896+
[window setExcludedFromWindowsMenu:excluded];
897+
}
898+
889899
void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
890900
NSWindow* window = GetNativeWindow().GetNativeNSWindow();
891901

atom/browser/native_window_views.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,13 @@ bool NativeWindowViews::IsMaximizable() {
721721
#endif
722722
}
723723

724+
void NativeWindowViews::SetExcludedFromShownWindowsMenu(bool excluded) {}
725+
726+
bool NativeWindowViews::IsExcludedFromShownWindowsMenu() {
727+
// return false on unsupported platforms
728+
return false;
729+
}
730+
724731
void NativeWindowViews::SetFullScreenable(bool fullscreenable) {
725732
fullscreenable_ = fullscreenable;
726733
}

atom/browser/native_window_views.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class NativeWindowViews : public NativeWindow,
9797
std::string GetTitle() override;
9898
void FlashFrame(bool flash) override;
9999
void SetSkipTaskbar(bool skip) override;
100+
void SetExcludedFromShownWindowsMenu(bool excluded) override;
101+
bool IsExcludedFromShownWindowsMenu() override;
100102
void SetSimpleFullScreen(bool simple_fullscreen) override;
101103
bool IsSimpleFullScreen() override;
102104
void SetKiosk(bool kiosk) override;

docs/api/browser-window.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,3 +1648,24 @@ removed in future Electron releases.
16481648
[vibrancy-docs]: https://developer.apple.com/documentation/appkit/nsvisualeffectview?preferredLanguage=objc
16491649
[window-levels]: https://developer.apple.com/documentation/appkit/nswindow/level
16501650
[chrome-content-scripts]: https://developer.chrome.com/extensions/content_scripts#execution-environment
1651+
1652+
### Properties
1653+
1654+
#### `win.excludedFromShownWindowsMenu` _macOS_
1655+
1656+
A `Boolean` property that determines whether the window is excluded from the application’s Windows menu. `false` by default.
1657+
1658+
```js
1659+
const win = new BrowserWindow({ height: 600, width: 600 })
1660+
1661+
const template = [
1662+
{
1663+
role: 'windowmenu'
1664+
}
1665+
]
1666+
1667+
win.excludedFromShownWindowsMenu = true
1668+
1669+
const menu = Menu.buildFromTemplate(template)
1670+
Menu.setApplicationMenu(menu)
1671+
```

0 commit comments

Comments
 (0)