macos : list windows and detect new windows
I would like to have a list of wi开发者_Python百科ndows which is quite simple but I need as well to :
be notified when a new window appears
be notified when an existing window dissapears
detect when positon / size of windows change
Do you have any ideas for this?
Thanks in advance
The answer in this post should be quite helpful: How can my app detect a change to another app's window?
If you want to just get windows for your own application you can use
int pid = [[NSProcessInfo processInfo] processIdentifier];
Using this information, you could write a class that monitors this information and posts changes to a NSNotificationCenter or calls methods on its delegate.
The Son of Grab sample provides code to list windows.
You could poll CGWindowListCreate() timer based, but I suppose there are more elegant solutions.
Maybe you can use NSDistributedNotificationCenter to get global NSWindow Notifications. (Did not try that myself - just a starting point)
精彩评论