commit 1c3f1d6be9f2817b92facfe9b7f3daeaf53757d9
Author: Cem Keylan <cem@ckyln.com>
Date: Mon, 29 Jun 2020 12:50:00 +0300
initial commit
Diffstat:
6 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,2 @@
+sxss
+config.h
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2020 Cem Keylan
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,27 @@
+# See LICENSE for copyright information
+PREFIX = /usr/local
+BINDIR = ${PREFIX}/bin
+
+LIBS = -lXss -lX11 -lc
+CC = cc
+
+all: sxss
+
+sxss: config.h sxss.c
+ ${CC} ${CFLAGS} ${LDFLAGS} -o sxss sxss.c ${LIBS}
+
+config.h: config.def.h
+ cp config.def.h config.h
+
+clean:
+ ${RM} sxss
+
+install: all
+ mkdir -p ${DESTDIR}${BINDIR}
+ cp sxss ${DESTDIR}${BINDIR}/sxss
+ chmod 755 ${DESTDIR}${BINDIR}/sxss
+
+uninstall:
+ ${RM} ${DESTDIR}${BINDIR}/sxss
+
+.PHONY: all clean install uninstall
diff --git a/README.txt b/README.txt
@@ -0,0 +1,36 @@
+simple X screensaver
+================================================================================
+
+A simple screensaver inspired by xssstate[1].
+
+
+Dependencies
+--------------------------------------------------------------------------------
+
+- libX11
+- libXScrnSaver
+
+
+Installation
+--------------------------------------------------------------------------------
+
+Configuration is done through 'config.h'. You will need to set the program to be
+run when the screensaver is activated. It doesn't need to be the full path, but
+it must be in your PATH variable if that's the case.
+
+After editing config.h, compile and install.
+
+ $ make
+ $ make install
+
+
+Usage
+--------------------------------------------------------------------------------
+
+sxss doesn't accept any arguments. You can simply add it to your '.xinitrc' (or
+what have you) the following line.
+
+ sxss &
+
+
+[1]: https://git.suckless.org/xssstate
diff --git a/config.def.h b/config.def.h
@@ -0,0 +1 @@
+static char *const screensaver[] = { "/usr/bin/slock", NULL };
diff --git a/sxss.c b/sxss.c
@@ -0,0 +1,55 @@
+/*
+ * simple X screensaver
+ */
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <X11/extensions/scrnsaver.h>
+
+#include "config.h"
+
+static void spawn(char *const argv[]) {
+ switch (fork()) {
+ case 0:
+ execvp(argv[0], argv);
+ perror("execvp");
+ _exit(1);
+ case -1:
+ perror("fork");
+ }
+}
+
+
+int main(int argc, char *argv[]) {
+ XScreenSaverInfo *info;
+ Display *dpy;
+ int base, errbase;
+
+ if(!(dpy = XOpenDisplay(0))) {
+ printf("Cannot open display.\n");
+ exit(1);
+ }
+
+ if (!XScreenSaverQueryExtension(dpy, &base, &errbase)) {
+ printf("Screensaver extension not activated.\n");
+ exit(1);
+ }
+
+ while(1) {
+
+ info = XScreenSaverAllocInfo();
+ XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
+
+ switch(info->state) {
+ case ScreenSaverDisabled:
+ sleep(10);
+ break;
+ case ScreenSaverOn:
+ break;
+ case ScreenSaverOff:
+ if (info->til_or_since < 1000) spawn(screensaver);
+ break;
+ }
+ sleep(1);
+ }
+}