Bug 890125 - Part 2 - Convert the OSX Spaces handling to accept string-type workspace IDs. r=mstange,nika
authorMike de Boer <mdeboer@mozilla.com>
Tue, 07 Apr 2020 11:02:10 +0000
changeset 590014 36e331c78398676385233cb06a6b4d670b83dd8e
parent 590013 bd936bfc3a0f4c7ba2008de16d91aaba7626d1d9
child 590015 70b5f44adb00c8e3c099a8e87c4718d141c737fa
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
milestone77.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
@@ -1262,19 +1262,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) {
@@ -1298,23 +1308,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;
   }