Detecting fullscreen on Mac

帅比萌擦擦* 提交于 2019-12-01 11:03:19

To check for full-screen, call CGDisplayIsCaptured(screenID) on each screen.

But I'm not sure if you're checking the right thing. For one thing, I could have one screen captured ("full screen") and a second screen uncaptured, what do you want to do in this case?

Also, does fullscreen really mean anything? If I'm using GarageBand to work on a song, I probably don't want to hear random sounds, regardless of whether or not anything's full screen. Or I could be running a Windows VM full-screen, but still want to be notified of IMs.

not entirely sure how to do this, but the apple docs say:

To track changes in the login session’s presentation mode, you may handle the kEventAppSystemUIModeChanged Carbon event

The two solutions posted so far apply to “real” full-screen, but it’s worth noting that many full-screen apps just put a window over the whole screen (or, as vasi points out, a whole screen). To be accurate, you’ll have to check both.

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'...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!