views:

321

answers:

3

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 playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but if not, I will play the sound.

How can I detect this? Is there some way to get the foreground window with applescript and look at its dimensions? Or is there some other API call?

Thanks.

+2  A: 

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

cobbal
+7  A: 

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.

vasi
A: 

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.

Ahruman