In between midnight summer nights and dark winter days

Spaces.. Spaces.. Spaces.. Tue, Nov 13 2007 16:47

One of the new features introduced in Mac OS X 10.5 Leopard was Spaces, a virtual desktop manager for Mac OS X. Unfortunately, it has a number of problems, including a complete lack of consistency when it comes to determining which space you will end up on when switching between applications with windows on multiple spaces.

As an example, try the following (from my bug report to Apple, rdar://5596671):

  1. Make sure that Spaces is enabled.
  2. Make sure that only the Finder is running, and that no windows are open in the Finder.
  3. Open Text Edit. A new document should be created on the current space (Space 1).
  4. Create a second document.
  5. Move the second document to the next space (Space 2). Note that the second document is TextEdit's frontmost window.
  6. While in Space 2, click in the Finder.
  7. Using Command-Tab, switch back to TextEdit.

When switching back to TextEdit, I would expect that the last document that was open gets focus. What actually happens is that Spaces decides that now is a good time to switch back to space 1. When this happens hundreds of times every day, it soon gets very annoying. I'm not the only one who thinks so either; Henry Story has his take and Dave Dribin also shares his views. John Gruber then summarized by saing: "In short, Spaces seems designed for app partitioning, not task partitioning."

So this is the reason I put together my new application called Spaces.. Spaces.. Spaces.. (or TripleS for short). To make it work, I had to reverse engineer the Dock, figure out how it switches spaces and figure out how to make the most annoying aspect of the above behaviour disappear. My initial idea was to patch the CGSSetWorkspace function, but that didn't work very well as the Dock maintains quite a bit of state outside the window server (one crucial bit is which workspace is the current workspace). Instead, I decided to move one level up, and prevent the entire workspace switch from ever happening. This turned out to be quite successful, but the downside is that it ties the TripleS binary to a very specific version of Mac OS X (the current build, 10.5.0/9A581).

With the target to patch identified, I needed a way of determining when to inhibit workspace-switches. My desired behaviour was to prevent the Dock from switching space whenever I had just Command-Tab'd to a different application. After some digging, I discovered that I could override the __CPSSetFrontProcessWithOptions function to discover when the Dock changed the front process. Then I could simply note down the current time, and later when the patch to the Dock's workspace-switch function is called calculate the delta. If that delta is below some threshold (currently 0.2 seconds), the workspace switch inhibited.

I have made the code for Spaces.. Spaces.. Spaces.. available under the BSD license, if you're interested in taking a look. I'm indebted to the work of several others, including Jonathan 'Wolf' Rentzsch for his work developing mach_star, as well as Infinite Labs for their work in making mach_star work on Leopard.



Previous: FolderGlance, Leopard and the More... menu Next: Thread creation using pthread_create() on Leopard

About me
My name is Daniel Stødle. I live in Tromsø, Norway, at 69.66° North. By day, I work as a researcher at the Northern Research Institute in Norway; by night, I run my company SCSC. I do most of my development on and for Mac OS X. My research is geared towards interaction with and visualization of geospatial data. Read more on my personal page.

Software

Contact me
E-mail: daniel@scsc.no

Recent posts


2011
Jul 28: Running iTunes in a debugger (gdb)
Jul 25: The /Volumes/MobileBackups directory
Jul 20: FolderGlance 3.0.1 supports Lion
Mar 03: Quick tip: Speeding up Xcode compilations
Mar 02: FolderGlance 3.0
Jan 07: Making Universal Back Button work on 10.6.5 and later

2010
Sep 03: Creating pthreads in C++ using pointers to member functions
May 31: Quickly open URLs in Terminal
May 31: Snow Leopard and automatically submitted Crash Reports
May 27: Universal Back Button released for Mac OS X
May 22: The 22 Megapixel Laptop
Feb 09: FolderGlance on MacUpdate Promo

2009
Sep 28: FolderGlance 2.5.3 is out
Sep 21: FolderGlance 2.5.1 adds features and fixes bugs
Sep 16: FolderGlance 2.5 released!
Sep 10: Intriguing: Snow Leopard ships with the iPhone's multi-touch API built-in
Sep 03: FolderGlance and Snow Leopard
Mar 15: Fixing Keynote '08 and '09 to work with the Scripting Bridge
Feb 26: A website in an image
Feb 09: Display wall multi-touch

2008
Feb 19: Spaces.. Spaces.. Spaces.. retires
Feb 08: How-to: Reverse engineering the Dock to fix Spaces
Jan 25: Interacting with wall-sized displays

2007
Dec 20: Interesting Finder bug
Dec 06: Developing applications for the iPod touch (and the iPhone)
Nov 15: Spaces.. Spaces.. Spaces.. and 10.5.1
Nov 15: Thread creation using pthread_create() on Leopard
Nov 13: Spaces.. Spaces.. Spaces..
Nov 07: FolderGlance, Leopard and the More... menu
Nov 06: FolderGlance and Screen Sieve now also on Leopard!
Sep 16: Mysterious window server hangs

Archive
2007
2008
2009
2010
2011

RSS feed
RSS

Links
SCSC
Blog frontpage