shoumikhin
shoumikhin

Reputation: 1345

How to access windows hierarchy for my application on Mac?

I mean all the windows which belong to my application (process). I need to get something like (NSWindow *) for all of them. Notice, some windows were created by third-party plug-ins and are not accessible by [NSApp windows]. Yes, I know, Quartz Window Services can return all the windows by PID. But how can I get NSWindow by CGWindowID then? Thanks!

Upvotes: 1

Views: 3001

Answers (2)

shoumikhin
shoumikhin

Reputation: 1345

Usually NSWindowList() will give window ids. Also there're Quartz Window Services to help.

  • To get NSWindow* (Cocoa) there's [NSApp windowWithWindowNumber: (NSInteger)windowID] method.
  • To get WindowRef (Carbon) there's HIWindowFromCGWindowID() function.

If both of the above do not work, that means the window was created with CoreGraphics Private API. Its definition is available thanks to reverse engineering.

Concerning X11 windows on Mac, they are created with Xplugin library (by Xquartz) which is closed source and also uses CoreGraphics Private API.

Upvotes: 2

JWWalker
JWWalker

Reputation: 22717

Try NSWindowList to get window numbers, and then -[NSApplication windowWithWindowNumber:] to get NSWindows.

Upvotes: 3

Related Questions