Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change to other space (MacOSX) programmatically

I am making a customised window (a NSWindow with NSBorderlessWindowMask) So far I have been able to handle dragging, resizing, cmd+click and even miniaturize with double click if allowed (see here) so my window resembles as much as possible to a normal NSWindow.

However when I drag my window to the corner of my screen the user will expect to move that window to the next space. (In case you have Spaces enabled in "SystemPreferences" > "Expose and Spaces" > "Spaces" > "Enable Spaces")

I wonder how can I change to other space programmatically and move my window there?

like image 462
nacho4d Avatar asked Jun 06 '11 10:06

nacho4d


2 Answers

Unfortunately there's no public API which allows you to do this, but if you're willing to use the Private API it's possible. Take a look at CGSPrivate.h and you'll see you can make a call like this:

CGSConnection connection = _CGSDefaultConnection();
CGSMoveWorkspaceWindowList(connection, &windowNumber, 1, newSpaceNumber);   

Note that using this private API will cause your app to be rejected from Apple's Mac App Store though.

like image 185
BendiLow Avatar answered Oct 31 '22 10:10

BendiLow


Finally I found a solution. I can't change to a certain space programmatically but I can make my window behave like other non NSBorderlessWindowMask if [window setMovableByWindowBackground:YES] is done. That was the final purpose of this question :)

The solution is written (with some detail) here because that question seems to be older (or maybe a duplicate of this question?)

Is there a way to make a custom NSWindow work with Spaces

like image 26
nacho4d Avatar answered Oct 31 '22 09:10

nacho4d