I would like to be able to keep track of which application is currently focused on my Python X11 display. The goal is to bind it to a timetracking tool so that I can track how much time I spend on being unproductive.
I already found this code at http://thpinfo.com/2007/09/x11-idle-time-and-focused-window-in.html :
import Xlib.display display = Xlib.display.Display() focus = display.get_input_focus() print "WM Class: %s" % ( focus.focus.get_wm_class(), ) print "WM Name: %s" % ( focus.focus.get_wm_name(), )
However, this does not seem to work for me. Apparently, no matter which application is focused, both get_wm_class () and get_wm_name () just return None.
Of course, the solution should work with all of these new distorted window managers, such as Compiz, etc.
python x11 xlib
Soren
source share