Browse Source

feat: add evt listeners for SetAlwaysOnTop (#14951)

* feat: add evt listeners for SetAlwaysOnTop

* only emit one event on AlwaysOnTop change

* docs: add new alwaysontop event

* dont emit if theres no change

* address feedback from review
Shelley Vohr 6 years ago
parent
commit
27bbf6a3c6

+ 4 - 0
atom/browser/api/atom_api_top_level_window.cc

@@ -262,6 +262,10 @@ void TopLevelWindow::OnWindowLeaveHtmlFullScreen() {
   Emit("leave-html-full-screen");
 }
 
+void TopLevelWindow::OnWindowAlwaysOnTopChanged() {
+  Emit("always-on-top-changed", IsAlwaysOnTop());
+}
+
 void TopLevelWindow::OnExecuteWindowsCommand(const std::string& command_name) {
   Emit("app-command", command_name);
 }

+ 1 - 0
atom/browser/api/atom_api_top_level_window.h

@@ -77,6 +77,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
   void OnWindowLeaveFullScreen() override;
   void OnWindowEnterHtmlFullScreen() override;
   void OnWindowLeaveHtmlFullScreen() override;
+  void OnWindowAlwaysOnTopChanged() override;
   void OnExecuteWindowsCommand(const std::string& command_name) override;
   void OnTouchBarItemResult(const std::string& item_id,
                             const base::DictionaryValue& details) override;

+ 5 - 0
atom/browser/native_window.cc

@@ -537,6 +537,11 @@ void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
     observer.OnWindowLeaveHtmlFullScreen();
 }
 
+void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
+  for (NativeWindowObserver& observer : observers_)
+    observer.OnWindowAlwaysOnTopChanged();
+}
+
 void NativeWindow::NotifyWindowExecuteWindowsCommand(
     const std::string& command) {
   for (NativeWindowObserver& observer : observers_)

+ 1 - 0
atom/browser/native_window.h

@@ -254,6 +254,7 @@ class NativeWindow : public base::SupportsUserData,
   void NotifyWindowLeaveFullScreen();
   void NotifyWindowEnterHtmlFullScreen();
   void NotifyWindowLeaveHtmlFullScreen();
+  void NotifyWindowAlwaysOnTopChanged();
   void NotifyWindowExecuteWindowsCommand(const std::string& command);
   void NotifyTouchBarItemInteraction(const std::string& item_id,
                                      const base::DictionaryValue& details);

+ 1 - 0
atom/browser/native_window_observer.h

@@ -83,6 +83,7 @@ class NativeWindowObserver {
   virtual void OnWindowLeaveFullScreen() {}
   virtual void OnWindowEnterHtmlFullScreen() {}
   virtual void OnWindowLeaveHtmlFullScreen() {}
+  virtual void OnWindowAlwaysOnTopChanged() {}
   virtual void OnTouchBarItemResult(const std::string& item_id,
                                     const base::DictionaryValue& details) {}
   virtual void OnNewWindowForTab() {}

+ 3 - 0
atom/browser/native_window_views.cc

@@ -706,6 +706,9 @@ void NativeWindowViews::SetAlwaysOnTop(bool top,
                                        const std::string& level,
                                        int relativeLevel,
                                        std::string* error) {
+  if (top != widget()->IsAlwaysOnTop())
+    NativeWindow::NotifyWindowAlwaysOnTopChanged();
+
   widget()->SetAlwaysOnTop(top);
 }
 

+ 9 - 0
docs/api/browser-window.md

@@ -542,6 +542,15 @@ Emitted when the window enters a full-screen state triggered by HTML API.
 
 Emitted when the window leaves a full-screen state triggered by HTML API.
 
+#### Event: 'always-on-top-changed' _macOS_
+
+Returns:
+
+* `event` Event
+* `isAlwaysOnTop` Boolean
+
+Emitted when the window is set or unset to show always on top of other windows.
+
 #### Event: 'app-command' _Windows_
 
 Returns: