Detecting fullscreen on Mac

后端 未结 4 1344
梦谈多话
梦谈多话 2021-01-22 18:53

I am writing an IM client for Mac (in Python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playin

4条回答
  •  清酒与你
    2021-01-22 19:48

    In Mountain Lion (and probably earlier), you can track the presence of the menu bar by monitoring the distributed notifications com.apple.HIToolbox.hideMenuBarShown and com.apple.HIToolbox.hideMenuBarShown. No menu bar usually == fullscreen mode. This works across apps, so you can tell when, say, VLC goes fullscreen, or when someone switches to iCal in fullscreen mode.

    To do this, register for these two notifications:

    [[NSDistributedNotificationCenter defaultCenter] addObserver:self
            selector:@selector(windowDidEnterFullScreen:)
            name:@"com.apple.HIToolbox.hideMenuBarShown"
            object:nil];
    
    [[NSDistributedNotificationCenter defaultCenter] addObserver:self
           selector:@selector(windowDidExitFullScreen:)
           name:@"com.apple.HIToolbox.frontMenuBarShown"
           object:nil];
    

    then create your own selectors to handle those cases. frontMenuBarShown fires all the time, so to catch a real return from fullscreen, watch for the first 'didExit' that follows a 'didEnter'...

提交回复
热议问题