tags:

views:

258

answers:

2

Is it possible in python to tell if a full screen application on linux is running? I have a feeling it might be possible using Xlib but I haven't found a way.

EDIT: By full screen I mean the WHOLE screen nothing else but the application, such as a full-screen game.

+3  A: 

If all Window Managers you're interested in running under support EWMH, the Extended Window Manager Hints standard, there are elegant ways to perform this (speaking to Xlib via ctypes, for example). The _NET_ACTIVE_WINDOW property of the root window (see here) tells you which window is active (if any); the _NET_WM_STATE property of the active window is then a list of atoms describing its state which will include _NET_WM_STATE_FULLSCREEN if that window is fullscreen. (If you have multiple monitors of course a window could be fullscreen on one of them without being active; I believe other cases may exist in which a window may be fullscreen without being active -- I don't think there's any way to cover them all without essentially checking _NET_WM_STATE for every window, though).

Alex Martelli
You use the Xlib RootWindow macro (display and screen as arguments) or DefaultRootWindow (just display as argument); I forget what they expand to in terms of underlying calls, but Xlib's .h files will tell you. Or, with python xlib (handier than ctype for this task, IMHO), it's the `.root` attribute of the `screen` method of the `Display` object.
Alex Martelli
I do not see how I get the _NET_ACTIVE_WINDOW property of it.
DoR
In Python xlib, use `get_property` or `list_properties` method of window objects -- see http://python-xlib.sourceforge.net/doc/html/python-xlib_toc.html and links therefrom. See e.g. http://www.google.com/codesearch/p?hl=en-).
Alex Martelli
The list_properties method never returns the number of _NET_ACTIVE_WINDOW.
DoR
What window manager are you using? if not EWMH-compliant, then it's more of a problem...
Alex Martelli
Metacity, I am pretty sure it is compliant since the creator founded freedesktop.org. Maybe I am just doing it wrong, mind posting a code example?
DoR
+2  A: 

Found a solution:

import Xlib.display

screen = Xlib.display.Display().screen()
root_win = screen.root

num_of_fs = 0
for window in root_win.query_tree()._data['children']:
    window_name = window.get_wm_name()
    width = window.get_geometry()._data["width"]
    height = window.get_geometry()._data["height"]

    if width == screen.width_in_pixels and height == screen.height_in_pixels:
        num_of_fs += 1

print num_of_fs

This prints out the number of fullscreen windows which for me is normally one. When playing a full screen game its 2.

DoR