Reputation: 11840
I'm working on a Cocoa app that has a main window and a preview window. I'd like the preview window to automatically position itself to minimize overlap with other windows — it definitely shouldn't overlap my app's main window, and it should try not to overlap other applications' windows.
How should I do this?
Upvotes: 3
Views: 393
Reputation: 7381
Apple has a sample application called Son of Grab that shows you how to consume all current windows.
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
will give you the current windows. You can interrogate the kCGWindowBounds
value to get the bounds of the returned windows.
Upvotes: 1