[hackers] [xssstate] Adding the main C file too. || Christoph Lohmann
commit ea369273fd93c6f5705f4c69be14cc6c88d6184c
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Sun Dec 9 07:10:32 2012 +0100
Adding the main C file too.
diff --git a/xssstate.c b/xssstate.c
new file mode 100644
index 0000000..57536b2
--- /dev/null
+++ b/xssstate.c
_AT_@ -0,0 +1,106 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <libgen.h>
+#include <X11/extensions/scrnsaver.h>
+
+#include "arg.h"
+
+char *argv0;
+
+void
+die(const char *errstr, ...) {
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
+void
+usage(void)
+{
+ die("usage: %s [-istv]
", basename(argv0));
+}
+
+int
+main(int argc, char *argv[]) {
+ XScreenSaverInfo *info;
+ Display *dpy;
+ int base, errbase;
+ Bool showstate, showtill, showidle;
+
+ showstate = false;
+ showtill = false;
+ showidle = false;
+
+ ARGBEGIN {
+ case 'i':
+ showidle = true;
+ break;
+ case 's':
+ showstate = true;
+ break;
+ case 't':
+ showtill = true;
+ break;
+ case 'v':
+ die("xssstate-"VERSION", © 2008-2012 xssstate engineers"
+ ", see LICENSE for details.
");
+ default:
+ usage();
+ } ARGEND;
+
+ if (!showstate && !showtill && !showidle)
+ usage();
+
+ if (!(dpy = XOpenDisplay(0)))
+ die("Cannot open display.
");
+
+ if (!XScreenSaverQueryExtension(dpy, &base, &errbase))
+ die("Screensaver extension not activated.
");
+
+ info = XScreenSaverAllocInfo();
+ XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
+
+ if (showstate) {
+ switch(info->state) {
+ case ScreenSaverOn:
+ printf("on
");
+ break;
+ case ScreenSaverOff:
+ printf("off
");
+ break;
+ case ScreenSaverDisabled:
+ printf("disabled
");
+ break;
+ }
+ } else if (showtill) {
+ switch(info->state) {
+ case ScreenSaverOn:
+ printf("0
");
+ break;
+ case ScreenSaverOff:
+ printf("%ld
", info->til_or_since);
+ break;
+ case ScreenSaverDisabled:
+ printf("-1
");
+ break;
+ }
+ } else if (showidle) {
+ printf("%ld
", info->idle);
+ }
+
+
+ XCloseDisplay(dpy);
+
+ return 0;
+}
+
Received on Sun Dec 09 2012 - 07:12:38 CET
This archive was generated by hypermail 2.3.0
: Sun Dec 09 2012 - 07:24:10 CET