Created
February 21, 2012 23:21
-
-
Save jamesadney/1879754 to your computer and use it in GitHub Desktop.
X11 Idle Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import os | |
class XScreenSaverInfo( ctypes.Structure): | |
""" typedef struct { ... } XScreenSaverInfo; """ | |
_fields_ = [('window', ctypes.c_ulong), # screen saver window | |
('state', ctypes.c_int), # off,on,disabled | |
('kind', ctypes.c_int), # blanked,internal,external | |
('since', ctypes.c_ulong), # milliseconds | |
('idle', ctypes.c_ulong), # milliseconds | |
('event_mask', ctypes.c_ulong)] # events | |
xlib = ctypes.cdll.LoadLibrary('libX11.so') | |
display = xlib.XOpenDisplay(os.environ['DISPLAY']) | |
xss = ctypes.cdll.LoadLibrary('libXss.so.1') | |
xss.XScreenSaverAllocInfo.restype = ctypes.POINTER(XScreenSaverInfo) | |
xssinfo = xss.XScreenSaverAllocInfo() | |
xss.XScreenSaverQueryInfo(display, xlib.XDefaultRootWindow(display), xssinfo) | |
print "idle: %d ms" % xssinfo.contents.idle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment