views:

48

answers:

2

Hello,

I would like to have a list of windows 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

A: 

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)

weichsel
pooling is what I want to avoid. I've checked notifications but didn't find something usefull.
AP
+1  A: 

The answer in this post should be quite helpful: http://stackoverflow.com/questions/853833/how-can-my-app-detect-a-change-to-another-apps-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.

Ryan
I have to test but it sounds really interesting.
AP
The thread mentioned makes use of the Accessibility API of Mac OS X. Be aware of that the user has to switch on "Enable access for assistive devices." in System Preferences.
weichsel