开发者

macos : list windows and detect new windows

开发者 https://www.devze.com 2022-12-13 18:47 出处:网络
I would like to have a list of wi开发者_Python百科ndows which is quite simple but I need as well to :

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消