Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically open NSWindow in another Desktop (Space)

In my OSX Project I want to:

  • identify the Desktop (one of the expose Spaces) where a NSWindow resides;

  • open a NSWindow in a determined Space, not only on current Space.

Is there a way to do these simple tasks?

Exploring the documentation (NSWindowController, NSWindow, NSScreen) I can't find anything regarding multiple Desktop Management.

Thanks in advance!

like image 628
Andrea Ippolito Avatar asked Feb 17 '16 15:02

Andrea Ippolito


1 Answers

You'd think there would be some API for working with Spaces, but there really isn't. You can use CGWindowListCopyWindowInfo to determine which Space a particular window is on, but there's no easy way to open a particular window on a specific space.

There is private API to move windows between spaces, of course. Whether you want to use this in your application depends on your needs - you couldn't use it on a Mac App Store application, obviously.

Found a copy-of-a-copy of the reverse-engineered header I was looking for: https://gist.github.com/rjw57/5495406

like image 182
Mark Bessey Avatar answered Nov 07 '22 21:11

Mark Bessey