feat: reinvigorate visibleOnFullscreen option (#24956)

This commit is contained in:
Shelley Vohr 2020-08-19 13:31:25 -07:00 committed by GitHub
parent 52d7afa4ef
commit 53668445ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 9 deletions

View file

@ -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. Returns `Boolean` - Whether the menu bar is visible.
#### `win.setVisibleOnAllWorkspaces(visible)` #### `win.setVisibleOnAllWorkspaces(visible[, options])`
* `visible` Boolean * `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. Sets whether the window should be visible on all workspaces.

View file

@ -801,8 +801,13 @@ void BaseWindow::SetOverlayIcon(const gfx::Image& overlay,
window_->SetOverlayIcon(overlay, description); window_->SetOverlayIcon(overlay, description);
} }
void BaseWindow::SetVisibleOnAllWorkspaces(bool visible) { void BaseWindow::SetVisibleOnAllWorkspaces(bool visible,
return window_->SetVisibleOnAllWorkspaces(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() { bool BaseWindow::IsVisibleOnAllWorkspaces() {

View file

@ -179,7 +179,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
void SetProgressBar(double progress, gin_helper::Arguments* args); void SetProgressBar(double progress, gin_helper::Arguments* args);
void SetOverlayIcon(const gfx::Image& overlay, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description); const std::string& description);
void SetVisibleOnAllWorkspaces(bool visible); void SetVisibleOnAllWorkspaces(bool visible, gin_helper::Arguments* args);
bool IsVisibleOnAllWorkspaces(); bool IsVisibleOnAllWorkspaces();
void SetAutoHideCursor(bool auto_hide); void SetAutoHideCursor(bool auto_hide);
virtual void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value); virtual void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value);

View file

@ -185,7 +185,8 @@ class NativeWindow : public base::SupportsUserData,
const std::string& description) = 0; const std::string& description) = 0;
// Workspace APIs. // Workspace APIs.
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0; virtual void SetVisibleOnAllWorkspaces(bool visible,
bool visibleOnFullScreen = false) = 0;
virtual bool IsVisibleOnAllWorkspaces() = 0; virtual bool IsVisibleOnAllWorkspaces() = 0;

View file

@ -118,7 +118,8 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
void SetOverlayIcon(const gfx::Image& overlay, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override; const std::string& description) override;
void SetVisibleOnAllWorkspaces(bool visible) override; void SetVisibleOnAllWorkspaces(bool visible,
bool visibleOnFullScreen) override;
bool IsVisibleOnAllWorkspaces() override; bool IsVisibleOnAllWorkspaces() override;
void SetAutoHideCursor(bool auto_hide) override; void SetAutoHideCursor(bool auto_hide) override;

View file

@ -1351,8 +1351,24 @@ void NativeWindowMac::SetProgressBar(double progress,
void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay, void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) {} 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(visible, NSWindowCollectionBehaviorCanJoinAllSpaces);
SetCollectionBehavior(visibleOnFullScreen,
NSWindowCollectionBehaviorFullScreenAuxiliary);
} }
bool NativeWindowMac::IsVisibleOnAllWorkspaces() { bool NativeWindowMac::IsVisibleOnAllWorkspaces() {

View file

@ -1154,7 +1154,8 @@ bool NativeWindowViews::IsMenuBarVisible() {
return root_view_->IsMenuBarVisible(); return root_view_->IsMenuBarVisible();
} }
void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) { void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible,
bool visibleOnFullScreen) {
widget()->SetVisibleOnAllWorkspaces(visible); widget()->SetVisibleOnAllWorkspaces(visible);
} }

View file

@ -123,7 +123,8 @@ class NativeWindowViews : public NativeWindow,
void SetMenuBarVisibility(bool visible) override; void SetMenuBarVisibility(bool visible) override;
bool IsMenuBarVisible() override; bool IsMenuBarVisible() override;
void SetVisibleOnAllWorkspaces(bool visible) override; void SetVisibleOnAllWorkspaces(bool visible,
bool visibleOnFullScreen) override;
bool IsVisibleOnAllWorkspaces() override; bool IsVisibleOnAllWorkspaces() override;