From 53668445bac8a9cd602300fe13f57bd2c01e8035 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 19 Aug 2020 13:31:25 -0700 Subject: [PATCH] feat: reinvigorate visibleOnFullscreen option (#24956) --- docs/api/browser-window.md | 5 ++++- shell/browser/api/electron_api_base_window.cc | 9 +++++++-- shell/browser/api/electron_api_base_window.h | 2 +- shell/browser/native_window.h | 3 ++- shell/browser/native_window_mac.h | 3 ++- shell/browser/native_window_mac.mm | 18 +++++++++++++++++- shell/browser/native_window_views.cc | 3 ++- shell/browser/native_window_views.h | 3 ++- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index ea60844c6ef..cf0d26a9621 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1669,9 +1669,12 @@ Sets whether the menu bar should be visible. If the menu bar is auto-hide, users Returns `Boolean` - Whether the menu bar is visible. -#### `win.setVisibleOnAllWorkspaces(visible)` +#### `win.setVisibleOnAllWorkspaces(visible[, options])` * `visible` Boolean +* `options` Object (optional) + * `visibleOnFullScreen` Boolean (optional) _macOS_ - Sets whether + the window should be visible above fullscreen windows Sets whether the window should be visible on all workspaces. diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index b4679bc24e8..731e1d8ca99 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -801,8 +801,13 @@ void BaseWindow::SetOverlayIcon(const gfx::Image& overlay, window_->SetOverlayIcon(overlay, description); } -void BaseWindow::SetVisibleOnAllWorkspaces(bool visible) { - return window_->SetVisibleOnAllWorkspaces(visible); +void BaseWindow::SetVisibleOnAllWorkspaces(bool visible, + gin_helper::Arguments* args) { + gin_helper::Dictionary options; + bool visibleOnFullScreen = false; + args->GetNext(&options) && + options.Get("visibleOnFullScreen", &visibleOnFullScreen); + return window_->SetVisibleOnAllWorkspaces(visible, visibleOnFullScreen); } bool BaseWindow::IsVisibleOnAllWorkspaces() { diff --git a/shell/browser/api/electron_api_base_window.h b/shell/browser/api/electron_api_base_window.h index 075d1a470f6..056e32188b7 100644 --- a/shell/browser/api/electron_api_base_window.h +++ b/shell/browser/api/electron_api_base_window.h @@ -179,7 +179,7 @@ class BaseWindow : public gin_helper::TrackableObject, void SetProgressBar(double progress, gin_helper::Arguments* args); void SetOverlayIcon(const gfx::Image& overlay, const std::string& description); - void SetVisibleOnAllWorkspaces(bool visible); + void SetVisibleOnAllWorkspaces(bool visible, gin_helper::Arguments* args); bool IsVisibleOnAllWorkspaces(); void SetAutoHideCursor(bool auto_hide); virtual void SetVibrancy(v8::Isolate* isolate, v8::Local value); diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index a29fd316031..87b83184689 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -185,7 +185,8 @@ class NativeWindow : public base::SupportsUserData, const std::string& description) = 0; // Workspace APIs. - virtual void SetVisibleOnAllWorkspaces(bool visible) = 0; + virtual void SetVisibleOnAllWorkspaces(bool visible, + bool visibleOnFullScreen = false) = 0; virtual bool IsVisibleOnAllWorkspaces() = 0; diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index 8cf446a1dd4..aa1e549ef79 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -118,7 +118,8 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver { void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) override; - void SetVisibleOnAllWorkspaces(bool visible) override; + void SetVisibleOnAllWorkspaces(bool visible, + bool visibleOnFullScreen) override; bool IsVisibleOnAllWorkspaces() override; void SetAutoHideCursor(bool auto_hide) override; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 4255e6b7c2c..8172ee4310a 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1351,8 +1351,24 @@ void NativeWindowMac::SetProgressBar(double progress, void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay, const std::string& description) {} -void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) { +void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible, + bool visibleOnFullScreen) { + // In order for NSWindows to be visible on fullscreen we need to functionally + // mimic app.dock.hide() since Apple changed the underlying functionality of + // NSWindows starting with 10.14 to disallow NSWindows from floating on top of + // fullscreen apps. + ProcessSerialNumber psn = {0, kCurrentProcess}; + if (visibleOnFullScreen) { + [window_ setCanHide:NO]; + TransformProcessType(&psn, kProcessTransformToUIElementApplication); + } else { + [window_ setCanHide:YES]; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + } + SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces); + SetCollectionBehavior(visibleOnFullScreen, + NSWindowCollectionBehaviorFullScreenAuxiliary); } bool NativeWindowMac::IsVisibleOnAllWorkspaces() { diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index e753b671431..1fb181a6b4f 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1154,7 +1154,8 @@ bool NativeWindowViews::IsMenuBarVisible() { return root_view_->IsMenuBarVisible(); } -void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) { +void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible, + bool visibleOnFullScreen) { widget()->SetVisibleOnAllWorkspaces(visible); } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 6ad3cac7913..98d10807c21 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -123,7 +123,8 @@ class NativeWindowViews : public NativeWindow, void SetMenuBarVisibility(bool visible) override; bool IsMenuBarVisible() override; - void SetVisibleOnAllWorkspaces(bool visible) override; + void SetVisibleOnAllWorkspaces(bool visible, + bool visibleOnFullScreen) override; bool IsVisibleOnAllWorkspaces() override;