Bug 890125 - Part 2 - Convert the OSX Spaces handling to accept string-type workspace IDs. r=mstange,nika
authorMike de Boer <mdeboer@mozilla.com>
Mon, 06 Apr 2020 12:56:38 +0000
changeset 589448 17b15e227d3bd91ab5d8421c491e4d63b25f2c49
parent 589447 6e71761c1018daaac5f86f61edac4ad6ed869a2e
child 589449 6e2c1facb7e062e41844c94fbb086058bf7cceba
push id2335
push userffxbld-merge
push dateMon, 25 May 2020 13:47:24 +0000
treeherdermozilla-release@69ca1d06f46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, nika
bugs890125
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 890125 - Part 2 - Convert the OSX Spaces handling to accept string-type workspace IDs. r=mstange,nika Differential Revision: https://phabricator.services.mozilla.com/D67823
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -239,18 +239,18 @@ class nsCocoaWindow final : public nsBas
   virtual LayoutDeviceIntSize ClientToWindowSize(const LayoutDeviceIntSize& aClientSize) override;
 
   virtual void* GetNativeData(uint32_t aDataType) override;
 
   virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, int32_t* aY) override;
   virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
   virtual void Move(double aX, double aY) override;
   virtual void SetSizeMode(nsSizeMode aMode) override;
-  virtual int32_t GetWorkspaceID() override;
-  virtual void MoveToWorkspace(int32_t workspaceID) override;
+  virtual void GetWorkspaceID(nsAString& workspaceID) override;
+  virtual void MoveToWorkspace(const nsAString& workspaceID) override;
   virtual void SuppressAnimation(bool aSuppress) override;
   virtual void HideWindowChrome(bool aShouldHide) override;
 
   void WillEnterFullScreen(bool aFullScreen);
   void EnteredFullScreen(bool aFullScreen, bool aNativeMode = true);
   virtual bool PrepareForFullscreenTransition(nsISupports** aData) override;
   virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage, uint16_t aDuration,
                                            nsISupports* aData, nsIRunnable* aCallback) override;
@@ -343,16 +343,17 @@ class nsCocoaWindow final : public nsBas
 
   nsresult CreateNativeWindow(const NSRect& aRect, nsBorderStyle aBorderStyle,
                               bool aRectIsFrameRect);
   nsresult CreatePopupContentView(const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData);
   void DestroyNativeWindow();
   void AdjustWindowShadow();
   void SetWindowBackgroundBlur();
   void UpdateBounds();
+  int32_t GetWorkspaceID();
 
   void DoResize(double aX, double aY, double aWidth, double aHeight, bool aRepaint,
                 bool aConstrainToCurrentScreen);
 
   inline bool ShouldToggleNativeFullscreen(bool aFullScreen, bool aUseSystemTransition);
   void UpdateFullscreenState(bool aFullScreen, bool aNativeMode);
   nsresult DoMakeFullScreen(bool aFullScreen, bool aUseSystemTransition);
 
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -1259,19 +1259,29 @@ static CGSRemoveWindowsFromSpacesFunc Ge
   static bool lookedUpFunc = false;
   if (!lookedUpFunc) {
     func = (CGSRemoveWindowsFromSpacesFunc)dlsym(RTLD_DEFAULT, "CGSRemoveWindowsFromSpaces");
     lookedUpFunc = true;
   }
   return func;
 }
 
+void nsCocoaWindow::GetWorkspaceID(nsAString& workspaceID) {
+  workspaceID.Truncate();
+  int32_t sid = GetWorkspaceID();
+  if (sid != 0) {
+    workspaceID.AppendInt(sid);
+  }
+}
+
 int32_t nsCocoaWindow::GetWorkspaceID() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
+  // Mac OSX space IDs start at '1' (default space), so '0' means 'unknown',
+  // effectively.
   CGSSpaceID sid = 0;
 
   if (!nsCocoaFeatures::OnElCapitanOrLater()) {
     return sid;
   }
 
   CGSCopySpacesForWindowsFunc CopySpacesForWindows = GetCGSCopySpacesForWindowsFunc();
   if (!CopySpacesForWindows) {
@@ -1295,23 +1305,29 @@ int32_t nsCocoaWindow::GetWorkspaceID() 
     }
   }
 
   return sid;
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-void nsCocoaWindow::MoveToWorkspace(int32_t workspaceID) {
+void nsCocoaWindow::MoveToWorkspace(const nsAString& workspaceIDStr) {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!nsCocoaFeatures::OnElCapitanOrLater()) {
     return;
   }
 
+  nsresult rv = NS_OK;
+  int32_t workspaceID = workspaceIDStr.ToInteger(&rv);
+  if (NS_FAILED(rv)) {
+    return;
+  }
+
   CGSConnection cid = _CGSDefaultConnection();
   int32_t currentSpace = GetWorkspaceID();
   // If an empty workspace ID is passed in (not valid on OSX), or when the
   // window is already on this workspace, we don't need to do anything.
   if (!workspaceID || workspaceID == currentSpace) {
     return;
   }