Created
December 1, 2025 09:10
-
-
Save sulincix/8a281248e4815078bf92ea0123d2339a to your computer and use it in GitHub Desktop.
Python X11 idle time
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # https://github.com/g0hl1n/xprintidle/blob/master/xprintidle.c | |
| import ctypes | |
| class XScreenSaverInfo( ctypes.Structure ): | |
| _fields_ = [("window", ctypes.c_ulong), | |
| ("state", ctypes.c_int), | |
| ("kind", ctypes.c_int), | |
| ("since", ctypes.c_ulong), | |
| ("idle", ctypes.c_ulong), | |
| ("event_mask", ctypes.c_ulong)] | |
| def get_idle_time(display=None): | |
| xlib = ctypes.cdll.LoadLibrary("libX11.so.6") | |
| xss = ctypes.cdll.LoadLibrary("libXss.so.1") | |
| display = xlib.XOpenDisplay(bytes(display, 'ascii')) | |
| xss.XScreenSaverAllocInfo.restype = ctypes.POINTER(XScreenSaverInfo) | |
| xssinfo = xss.XScreenSaverAllocInfo() | |
| xss.XScreenSaverQueryInfo(display, xlib.XDefaultRootWindow(display), xssinfo) | |
| return xssinfo.contents.idle | |
| if __name__ == "__main__": | |
| import os | |
| print(get_idle_time(os.environ["DISPLAY"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment