Skip to content

Commit

Permalink
feat: reinvigorate visibleOnFullscreen option (#24956)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 19, 2020
1 parent 52d7afa commit 5366844
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
5 changes: 4 additions & 1 deletion docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 7 additions & 2 deletions shell/browser/api/electron_api_base_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_base_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
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<v8::Value> value);
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,24 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
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() {
Expand Down
3 changes: 2 additions & 1 deletion shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion shell/browser/native_window_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5366844

Please sign in to comment.