Skip to content

Commit c2521c5

Browse files
committed
feat: add visible-on-all-workspaces-changed event
1 parent 9bd0fc5 commit c2521c5

9 files changed

+34
-0
lines changed

docs/api/browser-window.md

+9
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ Returns:
580580

581581
Emitted when the window is set or unset to show always on top of other windows.
582582

583+
#### Event: 'visible-on-all-workspaces-changed'
584+
585+
Returns:
586+
587+
* `event` Event
588+
* `isVisibleOnAllWorkspaces` Boolean
589+
590+
Emitted when a window is set or unset to be visible on all workspaces.
591+
583592
#### Event: 'app-command' _Windows_ _Linux_
584593

585594
Returns:

shell/browser/api/electron_api_base_window.cc

+4
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ void BaseWindow::OnWindowAlwaysOnTopChanged() {
280280
Emit("always-on-top-changed", IsAlwaysOnTop());
281281
}
282282

283+
void BaseWindow::OnWindowVisibleOnAllWorkspacesChanged() {
284+
Emit("visible-on-all-workspaces-changed", IsVisibleOnAllWorkspaces());
285+
}
286+
283287
void BaseWindow::OnExecuteAppCommand(const std::string& command_name) {
284288
Emit("app-command", command_name);
285289
}

shell/browser/api/electron_api_base_window.h

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
7878
void OnWindowEnterHtmlFullScreen() override;
7979
void OnWindowLeaveHtmlFullScreen() override;
8080
void OnWindowAlwaysOnTopChanged() override;
81+
void OnWindowVisibleOnAllWorkspacesChanged() override;
8182
void OnExecuteAppCommand(const std::string& command_name) override;
8283
void OnTouchBarItemResult(const std::string& item_id,
8384
const base::DictionaryValue& details) override;

shell/browser/native_window.cc

+5
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
556556
observer.OnWindowAlwaysOnTopChanged();
557557
}
558558

559+
void NativeWindow::NotifyWindowVisibleOnAllWorkspacesChanged() {
560+
for (NativeWindowObserver& observer : observers_)
561+
observer.OnWindowVisibleOnAllWorkspacesChanged();
562+
}
563+
559564
void NativeWindow::NotifyWindowExecuteAppCommand(const std::string& command) {
560565
for (NativeWindowObserver& observer : observers_)
561566
observer.OnExecuteAppCommand(command);

shell/browser/native_window.h

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class NativeWindow : public base::SupportsUserData,
280280
void NotifyWindowEnterHtmlFullScreen();
281281
void NotifyWindowLeaveHtmlFullScreen();
282282
void NotifyWindowAlwaysOnTopChanged();
283+
void NotifyWindowVisibleOnAllWorkspacesChanged();
283284
void NotifyWindowExecuteAppCommand(const std::string& command);
284285
void NotifyTouchBarItemInteraction(const std::string& item_id,
285286
const base::DictionaryValue& details);

shell/browser/native_window_mac.mm

+2
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
13531353

13541354
void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) {
13551355
SetCollectionBehavior(visible, NSWindowCollectionBehaviorCanJoinAllSpaces);
1356+
1357+
NativeWindow::NotifyWindowVisibleOnAllWorkspacesChanged();
13561358
}
13571359

13581360
bool NativeWindowMac::IsVisibleOnAllWorkspaces() {

shell/browser/native_window_observer.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class NativeWindowObserver : public base::CheckedObserver {
8989
virtual void OnWindowEnterHtmlFullScreen() {}
9090
virtual void OnWindowLeaveHtmlFullScreen() {}
9191
virtual void OnWindowAlwaysOnTopChanged() {}
92+
virtual void OnWindowVisibleOnAllWorkspacesChanged() {}
9293
virtual void OnTouchBarItemResult(const std::string& item_id,
9394
const base::DictionaryValue& details) {}
9495
virtual void OnNewWindowForTab() {}

shell/browser/native_window_views.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,8 @@ bool NativeWindowViews::IsMenuBarVisible() {
11451145

11461146
void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) {
11471147
widget()->SetVisibleOnAllWorkspaces(visible);
1148+
1149+
NativeWindow::NotifyWindowVisibleOnAllWorkspacesChanged();
11481150
}
11491151

11501152
bool NativeWindowViews::IsVisibleOnAllWorkspaces() {

spec-main/api-browser-window-spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,15 @@ describe('BrowserWindow module', () => {
35503550
expect(w.isVisibleOnAllWorkspaces()).to.be.true();
35513551
});
35523552
});
3553+
3554+
ifit(process.platform !== 'win32')('emits an event when the visibleOnAllWorkspaces state changes', async () => {
3555+
const w = new BrowserWindow({ show: false });
3556+
const visibleOnAllWorkspacesEvent = emittedOnce(w, 'visible-on-all-workspaces-changed');
3557+
expect(w.visibleOnAllWorkspaces).to.be.false();
3558+
w.visibleOnAllWorkspaces = true;
3559+
const [, visibleOnAllWorkspaces] = await visibleOnAllWorkspacesEvent;
3560+
expect(visibleOnAllWorkspaces).to.be.true();
3561+
});
35533562
});
35543563

35553564
ifdescribe(process.platform === 'darwin')('documentEdited state', () => {

0 commit comments

Comments
 (0)