1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import ctypes
20 import ctypes.util
21
23 _fields_ = [
24 ('window', ctypes.c_ulong),
25 ('state', ctypes.c_int),
26 ('kind', ctypes.c_int),
27 ('til_or_since', ctypes.c_ulong),
28 ('idle', ctypes.c_ulong),
29 ('eventMask', ctypes.c_ulong)
30 ]
31 XScreenSaverInfo_p = ctypes.POINTER(XScreenSaverInfo)
32
33 display_p = ctypes.c_void_p
34 xid = ctypes.c_ulong
35 c_int_p = ctypes.POINTER(ctypes.c_int)
36
37 try:
38 libX11path = ctypes.util.find_library('X11')
39 if libX11path == None:
40 raise OSError('libX11 could not be found.')
41 libX11 = ctypes.cdll.LoadLibrary(libX11path)
42 libX11.XOpenDisplay.restype = display_p
43 libX11.XOpenDisplay.argtypes = ctypes.c_char_p,
44 libX11.XDefaultRootWindow.restype = xid
45 libX11.XDefaultRootWindow.argtypes = display_p,
46
47 libXsspath = ctypes.util.find_library('Xss')
48 if libXsspath == None:
49 raise OSError('libXss could not be found.')
50 libXss = ctypes.cdll.LoadLibrary(libXsspath)
51 libXss.XScreenSaverQueryExtension.argtypes = display_p, c_int_p, c_int_p
52 libXss.XScreenSaverAllocInfo.restype = XScreenSaverInfo_p
53 libXss.XScreenSaverQueryInfo.argtypes = (display_p, xid, XScreenSaverInfo_p)
54
55 dpy_p = libX11.XOpenDisplay(None)
56 if dpy_p == None:
57 raise OSError('Could not open X Display.')
58
59 _event_basep = ctypes.c_int()
60 _error_basep = ctypes.c_int()
61 if libXss.XScreenSaverQueryExtension(dpy_p, ctypes.byref(_event_basep),
62 ctypes.byref(_error_basep)) == 0:
63 raise OSError('XScreenSaver Extension not available on display.')
64
65 xss_info_p = libXss.XScreenSaverAllocInfo()
66 if xss_info_p == None:
67 raise OSError('XScreenSaverAllocInfo: Out of Memory.')
68
69 rootwindow = libX11.XDefaultRootWindow(dpy_p)
70 xss_available = True
71 except OSError, e:
72
73 xss_available = False
74
86
93
94 if __name__ == '__main__':
95 import time
96 time.sleep(2.1)
97 print getIdleSec()
98 close()
99 print getIdleSec()
100