Reputation: 22717
The documentation for CGWindowListCopyWindowInfo
says
Generating the dictionaries for system windows is a relatively expensive operation. As always, you should profile your code and adjust your usage of this function appropriately for your needs.
My question is how can I "adjust" my use of this function? For a code automation process I frequently need to check what window is frontmost among those of document or modal level. That is, I call CGWindowListCopyWindowInfo
, ignore the windows that belong to other processes or have levels that I don't care about, and identify the first window that remains.
If there were a way to ask for information about just the windows owned by my process, say, that would be nice, but I see no way to do that. Or if there were a way to be notified when my windows change. I could watch for Carbon Events when windows are hidden or shown, but of course that is a deprecated technology.
Upvotes: 1
Views: 347
Reputation: 90641
You can use [NSWindow windowNumbersWithOptions:0]
to get the window numbers of just the current application's windows (on the active space) in z-order.
Upvotes: 2