diff options
Diffstat (limited to 'src/x11util.cpp')
-rw-r--r-- | src/x11util.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/x11util.cpp b/src/x11util.cpp index d2c1229..ce9192c 100644 --- a/src/x11util.cpp +++ b/src/x11util.cpp @@ -3,6 +3,7 @@ extern "C" { #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/XKBlib.h> + #include <X11/extensions/scrnsaver.h> } #include <cstring> #include <cstdlib> @@ -71,3 +72,29 @@ unsigned int getKeyMask(Display *dpy) XkbGetIndicatorState(dpy, XkbUseCoreKbd, &n); return n; } + +extern "C" +unsigned long getIdleTime(Display *dpy) +{ + if (dpy == nullptr) + return 0; + int event_basep, error_basep; + XScreenSaverInfo *ssi = nullptr; + if (!XScreenSaverQueryExtension(dpy, &event_basep, &error_basep)) { + fprintf(stderr, "Screen saver extension not supported\n"); + return 0; + } + ssi = XScreenSaverAllocInfo(); + if (ssi == nullptr) { + fprintf(stderr, "Couldn't allocate screen saver info\n"); + } + + if (!XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), ssi)) { + fprintf(stderr, "Couldn't query screen saver info\n"); + return 0; + } + unsigned long idleTime = ssi->idle; + if (ssi != nullptr) + XFree(ssi); + return idleTime; +} |