Mac OS X Lion: Detect if another application is running in full screen mode?

后端 未结 4 1995
暗喜
暗喜 2021-01-01 16:09

In a Cocoa app, is there a way to tell if another application currently is in full screen mode?

My application is configured to show up on all Spaces and listens for

4条回答
  •  情书的邮戳
    2021-01-01 16:56

    Use notifications. For example:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(willEnterFull:)
                                                 name:NSWindowWillEnterFullScreenNotification
                                               object:nil];
    

    Actually, you'll probably want to use NSDistributedNotificationCenter instead, since it goes across processes.

    You're adding your object as an observer, so that when something else posts a notification that it will enter full screen, your object will receive that notification.

    The selector is the message/method you want called by the notification process.

    The name parameter is the actual name of the notification. These are standard, unless you were to create a custom notification for something you would be using.

    The object parameter is for specifying which object you want to receive notifications from. Since you want to know when ANY app is going full screen, you'd want to leave this nil.

    Remember to remove your object as an observer before it's deallocated!

提交回复
热议问题