3

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

AP.
  • 5,205
  • 7
  • 50
  • 94

2 Answers2

1

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.

Community
  • 1
  • 1
Ryan
  • 2,460
  • 1
  • 21
  • 22
  • I have to test but it sounds really interesting. – AP. Dec 13 '09 at 20:28
  • 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. – Thomas Zoechling Dec 13 '09 at 21:50
0

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)

Thomas Zoechling
  • 34,177
  • 3
  • 81
  • 112
  • pooling is what I want to avoid. I've checked notifications but didn't find something usefull. – AP. Dec 13 '09 at 19:07