diff options
author | Jonathan Bauer | 2019-06-03 13:41:16 +0200 |
---|---|---|
committer | Jonathan Bauer | 2019-06-03 13:41:16 +0200 |
commit | 4ef0764c566390870a8de1a9f1955f0b7a1f7b07 (patch) | |
tree | 024eca9394ce8573e6a12a865774f75210ac8672 /src/x11util.cpp | |
parent | fix indentation (diff) | |
download | slxgreeter-4ef0764c566390870a8de1a9f1955f0b7a1f7b07.tar.gz slxgreeter-4ef0764c566390870a8de1a9f1955f0b7a1f7b07.tar.xz slxgreeter-4ef0764c566390870a8de1a9f1955f0b7a1f7b07.zip |
reset to "chooser" page on inactivity
defaults to 30s unless configuration option "session-chooser-reset-timer" (in seconds) is set
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; +} |