smokris
smokris

Reputation: 11840

How to position a Cocoa window to minimize overlap with other windows?

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

Answers (1)

Fruity Geek
Fruity Geek

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

Related Questions