From 4e57a732a8821a9637df50e8d593bfab46dec9ea Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 27 Mar 2019 08:10:23 -0400 Subject: [PATCH] feat: allow windows to be excluded from the windows menu (#17404) * feat: allow windows to be excluded from the windows menu * excludedfromWindowsMenu => excludedFromShownWindowsMenu * implement no-op for win & linux --- atom/browser/api/atom_api_top_level_window.cc | 11 ++++++++++ atom/browser/api/atom_api_top_level_window.h | 2 ++ atom/browser/native_window.h | 2 ++ atom/browser/native_window_mac.h | 2 ++ atom/browser/native_window_mac.mm | 10 +++++++++ atom/browser/native_window_views.cc | 7 +++++++ atom/browser/native_window_views.h | 2 ++ docs/api/browser-window.md | 21 +++++++++++++++++++ 8 files changed, 57 insertions(+) diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index bd1365113c35..850e8abccab8 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -567,6 +567,14 @@ void TopLevelWindow::SetSkipTaskbar(bool skip) { window_->SetSkipTaskbar(skip); } +void TopLevelWindow::SetExcludedFromShownWindowsMenu(bool excluded) { + window_->SetExcludedFromShownWindowsMenu(excluded); +} + +bool TopLevelWindow::IsExcludedFromShownWindowsMenu() { + return window_->IsExcludedFromShownWindowsMenu(); +} + void TopLevelWindow::SetSimpleFullScreen(bool simple_fullscreen) { window_->SetSimpleFullScreen(simple_fullscreen); } @@ -1133,6 +1141,9 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate, .SetMethod("addTabbedWindow", &TopLevelWindow::AddTabbedWindow) .SetMethod("setWindowButtonVisibility", &TopLevelWindow::SetWindowButtonVisibility) + .SetProperty("excludedFromShownWindowsMenu", + &TopLevelWindow::IsExcludedFromShownWindowsMenu, + &TopLevelWindow::SetExcludedFromShownWindowsMenu) #endif .SetMethod("setAutoHideMenuBar", &TopLevelWindow::SetAutoHideMenuBar) .SetMethod("isMenuBarAutoHide", &TopLevelWindow::IsMenuBarAutoHide) diff --git a/atom/browser/api/atom_api_top_level_window.h b/atom/browser/api/atom_api_top_level_window.h index 9366a9177234..3681225b56de 100644 --- a/atom/browser/api/atom_api_top_level_window.h +++ b/atom/browser/api/atom_api_top_level_window.h @@ -145,6 +145,8 @@ class TopLevelWindow : public mate::TrackableObject, std::string GetTitle(); void FlashFrame(bool flash); void SetSkipTaskbar(bool skip); + void SetExcludedFromShownWindowsMenu(bool excluded); + bool IsExcludedFromShownWindowsMenu(); void SetSimpleFullScreen(bool simple_fullscreen); bool IsSimpleFullScreen(); void SetKiosk(bool kiosk); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d2a52c5dbb51..9bdbb153d903 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -136,6 +136,8 @@ class NativeWindow : public base::SupportsUserData, virtual std::string GetTitle() = 0; virtual void FlashFrame(bool flash) = 0; virtual void SetSkipTaskbar(bool skip) = 0; + virtual void SetExcludedFromShownWindowsMenu(bool excluded) = 0; + virtual bool IsExcludedFromShownWindowsMenu() = 0; virtual void SetSimpleFullScreen(bool simple_fullscreen) = 0; virtual bool IsSimpleFullScreen() = 0; virtual void SetKiosk(bool kiosk) = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index faff517a8814..f8f598cecc3c 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -87,6 +87,8 @@ class NativeWindowMac : public NativeWindow { std::string GetTitle() override; void FlashFrame(bool flash) override; void SetSkipTaskbar(bool skip) override; + void SetExcludedFromShownWindowsMenu(bool excluded) override; + bool IsExcludedFromShownWindowsMenu() override; void SetSimpleFullScreen(bool simple_fullscreen) override; bool IsSimpleFullScreen() override; void SetKiosk(bool kiosk) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index ca70e93f3703..83bc53f746e4 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -886,6 +886,16 @@ void NativeWindowMac::FlashFrame(bool flash) { void NativeWindowMac::SetSkipTaskbar(bool skip) {} +bool NativeWindowMac::IsExcludedFromShownWindowsMenu() { + NSWindow* window = GetNativeWindow().GetNativeNSWindow(); + return [window isExcludedFromWindowsMenu]; +} + +void NativeWindowMac::SetExcludedFromShownWindowsMenu(bool excluded) { + NSWindow* window = GetNativeWindow().GetNativeNSWindow(); + [window setExcludedFromWindowsMenu:excluded]; +} + void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) { NSWindow* window = GetNativeWindow().GetNativeNSWindow(); diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5b9d2ebcf19b..2bf425ba91bd 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -721,6 +721,13 @@ bool NativeWindowViews::IsMaximizable() { #endif } +void NativeWindowViews::SetExcludedFromShownWindowsMenu(bool excluded) {} + +bool NativeWindowViews::IsExcludedFromShownWindowsMenu() { + // return false on unsupported platforms + return false; +} + void NativeWindowViews::SetFullScreenable(bool fullscreenable) { fullscreenable_ = fullscreenable; } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 53028b4bff12..43fc2208afd9 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -97,6 +97,8 @@ class NativeWindowViews : public NativeWindow, std::string GetTitle() override; void FlashFrame(bool flash) override; void SetSkipTaskbar(bool skip) override; + void SetExcludedFromShownWindowsMenu(bool excluded) override; + bool IsExcludedFromShownWindowsMenu() override; void SetSimpleFullScreen(bool simple_fullscreen) override; bool IsSimpleFullScreen() override; void SetKiosk(bool kiosk) override; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 19cc3f5de5fb..9e8d1300b69f 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1648,3 +1648,24 @@ removed in future Electron releases. [vibrancy-docs]: https://developer.apple.com/documentation/appkit/nsvisualeffectview?preferredLanguage=objc [window-levels]: https://developer.apple.com/documentation/appkit/nswindow/level [chrome-content-scripts]: https://developer.chrome.com/extensions/content_scripts#execution-environment + +### Properties + +#### `win.excludedFromShownWindowsMenu` _macOS_ + +A `Boolean` property that determines whether the window is excluded from the application’s Windows menu. `false` by default. + +```js +const win = new BrowserWindow({ height: 600, width: 600 }) + +const template = [ + { + role: 'windowmenu' + } +] + +win.excludedFromShownWindowsMenu = true + +const menu = Menu.buildFromTemplate(template) +Menu.setApplicationMenu(menu) +```