[PATCH] Add "s query" to print screen saver state and timing.
Nicolas George
george at nsup.org
Sat Jan 7 10:49:48 UTC 2017
The output looks like:
state = 0 (off)
kind = 1 (internal)
until = 557900 (0:09:17.900)
idle = 42100 (0:00:42.100)
event_mask = 0
Signed-off-by: Nicolas George <george at nsup.org>
---
configure.ac | 2 ++
man/xset.man | 2 +-
xset.c | 42 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 44 insertions(+), 2 deletions(-)
Hi. This is a feature that I frequently use in script from a personal
standalone program. I think it may be useful for many other people.
I have tried to follow the instructions on the wiki page
https://www.x.org/wiki/Development/Documentation/SubmittingPatches/
and the surrounding coding style, but I am not very familiar with the
autotools features.
Regards,
--
Nicolas George
diff --git a/configure.ac b/configure.ac
index 77de8f4..8d77ba3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,8 @@ PKG_CHECK_MODULES(SET_XKB, x11,
AC_CHECK_HEADERS([X11/XKBlib.h],,,[#include <X11/Xlib.h>])
CPPFLAGS="$SAVE_CPPFLAGS"],[echo "not found"])
+AC_CHECK_LIB(Xss, XScreenSaverQueryInfo, [], [], [-lX11])
+
AC_ARG_WITH(xf86misc, AS_HELP_STRING([--without-xf86misc],[Disable xf86misc support.]),
[USE_XF86MISC="$withval"], [USE_XF86MISC="yes"])
if test "x$USE_XF86MISC" != "xno" ; then
diff --git a/man/xset.man b/man/xset.man
index e9f1c5e..48544be 100644
--- a/man/xset.man
+++ b/man/xset.man
@@ -61,7 +61,7 @@ xset - user preference utility for X
[r {on|off}] [r rate \fIdelay\fP [\fIrate\fP]]
.br
[s [\fIlength\fP [\fIperiod\fP]]] [s {blank|noblank}]
-[s {expose|noexpose}] [s {on|off}] [s default] [s activate] [s reset]
+[s {expose|noexpose}] [s {on|off}] [s default] [s activate] [s reset] [s query]
.br
[q]
.br
diff --git a/xset.c b/xset.c
index 95da41b..3d1a136 100644
--- a/xset.c
+++ b/xset.c
@@ -37,6 +37,10 @@ in this Software without prior written authorization from The Open Group.
# define MITMISC
#endif
+#ifdef HAVE_LIBXSS
+# define XSS
+#endif
+
#ifdef HAVE_X11_XKBLIB_H
# define XKB
#endif
@@ -69,6 +73,9 @@ in this Software without prior written authorization from The Open Group.
#ifdef DPMSExtension
# include <X11/extensions/dpms.h>
#endif /* DPMSExtension */
+#ifdef XSS
+# include <X11/extensions/scrnsaver.h>
+#endif
#ifdef XF86MISC
# include <X11/extensions/xf86misc.h>
@@ -635,6 +642,39 @@ main(int argc, char *argv[])
} else if (strcmp(arg, "reset") == 0) { /* force it inactive */
XResetScreenSaver(dpy);
i++;
+ } else if (strcmp(arg, "query") == 0) {
+#ifdef XSS
+ XScreenSaverInfo *info;
+ info = XScreenSaverAllocInfo();
+ if (!info)
+ error("out of memory for font screen saver query");
+ XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
+ printf("state = %d (%s)\n",
+ info->state,
+ info->state == ScreenSaverOff ? "off" :
+ info->state == ScreenSaverOn ? "on" :
+ info->state == ScreenSaverDisabled ? "disabled" : "unknown");
+ printf("kind = %d (%s)\n",
+ info->kind,
+ info->kind == ScreenSaverBlanked ? "blanked" :
+ info->kind == ScreenSaverInternal ? "internal" :
+ info->kind == ScreenSaverExternal ? "external" : "unknown");
+ printf("until = %ld (%ld:%02ld:%02ld.%03ld)\n", info->til_or_since,
+ info->til_or_since / 3600000,
+ (info->til_or_since / 60000) % 60,
+ (info->til_or_since / 1000) % 60,
+ info->til_or_since % 1000);
+ printf("idle = %ld (%ld:%02ld:%02ld.%03ld)\n", info->idle,
+ info->idle / 3600000,
+ (info->idle / 60000) % 60,
+ (info->idle / 1000) % 60,
+ info->idle % 1000);
+ printf("event_mask = %lX\n", info->eventMask);
+ XFree(info);
+#else
+ error(" xset was not built with MIT-SCREEN-SAVER Extension support\n");
+#endif
+ i++;
} else if (*arg >= '0' && *arg <= '9') { /* Set as user wishes. */
set_saver(dpy, TIMEOUT, atoi(arg));
i++;
@@ -1653,7 +1693,7 @@ usage(const char *fmt, ...)
" For screen-saver control:\n"
"\t s [timeout [cycle]] s default s on\n"
"\t s blank s noblank s off\n"
- "\t s expose s noexpose\n"
+ "\t s expose s noexpose s query\n"
"\t s activate s reset\n"
" For status information: q\n"
" To print version: -version\n"
--
2.11.0
More information about the xorg-devel
mailing list