How can I detect / observe when a third party app starts a full screen process?

I would like to create a companion app for gamers, and in order to create additional functionality, I would like to observe / timing of certain actions of third party games, or rather, when the game actually starts a full screen process.

For example: my application is a system tray application, the game has a "launcher" application with lobby and menu screens. Once the game launches an additional process, usually OS X will switch permissions (optional) and my app will be notified in some way. Then I can start the timer. As soon as a game match ends, or the process is closed, or the game is no longer full screen, my app gets a second notification and I can stop the timer.

Are there official Apple APIs that provide some way of observing / polling for an app entering full screen mode and / or launching additional windows that I can reliably count as the actual game screen?

+3


source to share


2 answers


I doubt you will find a complete end-to-end solution. There are many ways for applications to achieve full screen, and most of them do not communicate this fact.

A full screen application can change presentationOptions

of NSApplication

to hide the Dock panel and menus. Another application can use key-value observation to observe a property of the application object currentSystemPresentationOptions

that will reflect the current system status.

A full-screen app can capture displays (although Apple does not recommend this technique). You can try to detect this by calling CGDisplayIsCaptured()

, although it has been deprecated since 10.9 without replacement. Perhaps if you register the callback with CGDisplayRegisterReconfigurationCallback()

, you will get called when something grabs the display. However, capturing the display is a kind of warning that other processes are not noticing such changes, perhaps not. In this case, you will have to interrogate. You can also query the current display mode; changing the mode is the main reason the game grabs the display in the first place.



A full screen game can also simply create a borderless window the size of the screen and set its window level in front of the Dock and menus (and other application windows). This is not really a notification about it. You can detect it using the API CGWindowList

, but you have to poll. For example, you can invoke CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID)

and iterate over dictionaries that look for screen size and at the window level above kCGStatusWindowLevel

.

(You might be able to use the Accessibility API to get notified when the closest window changes, so you only need to poll when this happens.)

+1


source


You cannot watch the notification if there is none. So first you need to know if the app you want to watch is actually sending a notification that you can watch. You cannot "connect" to other applications without their intended consent.



0


source







All Articles