Change to other space (MacOSX) programmatically

时光总嘲笑我的痴心妄想 提交于 2019-11-27 20:47:30

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6250864/change-to-other-space-macosx-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!