]> khamidou — GitHub mirrors - electron.git/commitdiff
Add SetVisibleOnAllWorkspaces/IsVisibleOnAllWorkspaces API.
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 26 Mar 2015 06:18:37 +0000 (14:18 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 26 Mar 2015 06:18:37 +0000 (14:18 +0800)
These two APIs are only available on OS X/Linux platforms.

atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index d8e18854c7446013acc9a191ef8d7295b3865e1c..fdc117d4d7aeee8a7859c1a803d869758d40ee9c 100644 (file)
@@ -424,6 +424,16 @@ void Window::ShowDefinitionForSelection() {
 }
 #endif
 
+#if defined(OS_MACOSX) || defined(OS_LINUX)
+void Window::SetVisibleOnAllWorkspaces(bool visible) {
+  return window_->SetVisibleOnAllWorkspaces(visible);
+}
+
+bool Window::IsVisibleOnAllWorkspaces() {
+  return window_->IsVisibleOnAllWorkspaces();
+}
+#endif
+
 mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
   return WebContents::CreateFrom(isolate, window_->GetWebContents());
 }
@@ -494,6 +504,12 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
       .SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
       .SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
+#if defined(OS_MACOSX) || defined(OS_LINUX)
+      .SetMethod("setVisibleOnAllWorkspaces",
+                 &Window::SetVisibleOnAllWorkspaces)
+      .SetMethod("isVisibleOnAllWorkspaces",
+                 &Window::IsVisibleOnAllWorkspaces)
+#endif
 #if defined(OS_MACOSX)
       .SetMethod("showDefinitionForSelection",
                  &Window::ShowDefinitionForSelection)
index b6805c83d89af67d0b4bbf2ee7f7f53b0e7bde87..359fff26e6eb6f7054657311d03991deafc1dfff 100644 (file)
@@ -130,6 +130,11 @@ class Window : public mate::EventEmitter,
   void ShowDefinitionForSelection();
 #endif
 
+#if defined(OS_MACOSX) || defined(OS_LINUX)
+  void SetVisibleOnAllWorkspaces(bool visible);
+  bool IsVisibleOnAllWorkspaces();
+#endif
+
   // APIs for WebContents.
   mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
   mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
index df36bfa8570a30dcc5b4b45ffc16e9aa6e9bd1a8..f39959a8769902a7e4f7de5bf2ddf73f643a0623 100644 (file)
@@ -280,6 +280,13 @@ bool NativeWindow::IsMenuBarVisible() {
   return true;
 }
 
+void NativeWindow::SetVisibleOnAllWorkspaces(bool visible) {
+}
+
+bool NativeWindow::IsVisibleOnAllWorkspaces() {
+  return false;
+}
+
 bool NativeWindow::HasModalDialog() {
   return has_dialog_attached_;
 }
index 2495259d82d868e7ec3864b6e5526438adad38f5..85b6c5390b8010f26c2afefd8923e257d10ff8db 100644 (file)
@@ -172,6 +172,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void SetMenuBarVisibility(bool visible);
   virtual bool IsMenuBarVisible();
 
+  // Visible on all workspaces.
+  virtual void SetVisibleOnAllWorkspaces(bool visible);
+  virtual bool IsVisibleOnAllWorkspaces();
+
   // The same with closing a tab in a real browser.
   //
   // Should be called by platform code when user want to close the window.
index 643d885c5dc0fcd6a1f2031cdefb685c27fe0e6e..8a45a856764cf0a511ba3f385c38f9e806339437 100644 (file)
@@ -77,6 +77,9 @@ class NativeWindowMac : public NativeWindow {
                       const std::string& description) override;
   void ShowDefinitionForSelection() override;
 
+  void SetVisibleOnAllWorkspaces(bool visible) override;
+  bool IsVisibleOnAllWorkspaces() override;
+
   // Returns true if |point| in local Cocoa coordinate system falls within
   // the draggable region.
   bool IsWithinDraggableRegion(NSPoint point) const;
@@ -112,6 +115,8 @@ class NativeWindowMac : public NativeWindow {
 
   bool is_kiosk_;
 
+  bool is_visible_on_all_workspaces_;
+
   NSInteger attention_request_id_;  // identifier from requestUserAttention
 
   // The presentation options before entering kiosk mode.
index 6c3a4e268418de2c383ac526b4ed9b4c6e422fdc..022de9b4ef76444ec97137d2243ae204d3100da4 100644 (file)
@@ -310,6 +310,7 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
                                  const mate::Dictionary& options)
     : NativeWindow(web_contents, options),
       is_kiosk_(false),
+      is_visible_on_all_workspaces_(false),
       attention_request_id_(0) {
   int width = 800, height = 600;
   options.Get(switches::kWidth, &width);
@@ -692,6 +693,21 @@ void NativeWindowMac::ShowDefinitionForSelection() {
   rwhv->ShowDefinitionForSelection();
 }
 
+void NativeWindowMac::SetVisibleOnAllWorkspaces(bool visible) {
+  NSUInteger collectionBehavior = [window_ collectionBehavior];
+  is_visible_on_all_workspaces_ = visible;
+  if (visible) {
+    collectionBehavior |= NSWindowCollectionBehaviorCanJoinAllSpaces;
+  } else {
+    collectionBehavior &= ~NSWindowCollectionBehaviorCanJoinAllSpaces;
+  }
+  [window_ setCollectionBehavior:collectionBehavior];
+}
+
+bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
+  return is_visible_on_all_workspaces_;
+}
+
 bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
   if (!draggable_region_)
     return false;
index 8d34180c99177770fe3ec849f31463ed7f81bdd8..0e3941ced9645424d3002743f226c9a35924695f 100644 (file)
@@ -150,6 +150,9 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
       menu_bar_autohide_(false),
       menu_bar_visible_(false),
       menu_bar_alt_pressed_(false),
+#if defined(OS_LINUX)
+      is_visible_on_all_workspaces_(false),
+#endif
 #if defined(OS_WIN)
       is_minimized_(false),
 #endif
@@ -674,6 +677,15 @@ bool NativeWindowViews::IsMenuBarVisible() {
   return menu_bar_visible_;
 }
 
+void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible) {
+  is_visible_on_all_workspaces_ = visible;
+  window_->SetVisibleOnAllWorkspaces(visible);
+}
+
+bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
+  return is_visible_on_all_workspaces_;
+}
+
 gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
   return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
 }
index 24cc9c9f436be61db6bf9d7ef689b10d902a23a1..df5a026009000c3ceac120dfe41b6fbc7b1977b7 100644 (file)
@@ -81,6 +81,11 @@ class NativeWindowViews : public NativeWindow,
   void SetMenuBarVisibility(bool visible) override;
   bool IsMenuBarVisible() override;
 
+#if defined(OS_LINUX)
+  void SetVisibleOnAllWorkspaces(bool visible) override;
+  bool IsVisibleOnAllWorkspaces() override;
+#endif
+
   gfx::AcceleratedWidget GetAcceleratedWidget();
 
   SkRegion* draggable_region() const { return draggable_region_.get(); }
@@ -149,6 +154,10 @@ class NativeWindowViews : public NativeWindow,
   bool menu_bar_visible_;
   bool menu_bar_alt_pressed_;
 
+#if defined(OS_LINUX)
+  bool is_visible_on_all_workspaces_;
+#endif
+
 #if defined(USE_X11)
   scoped_ptr<GlobalMenuBarX11> global_menu_bar_;