xssstate-1.1/000077500000000000000000000000001214221256000132245ustar00rootroot00000000000000xssstate-1.1/LICENSE000066400000000000000000000021621214221256000142320ustar00rootroot00000000000000MIT/X Consortium License © 2008 Kai Hendry © 2012 Christoph Lohmann <20h@r-36.net> 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. xssstate-1.1/Makefile000066400000000000000000000026701214221256000146710ustar00rootroot00000000000000# See LICENSE file for copyright and license details. include config.mk SRC = xssstate.c OBJ = ${SRC:.c=.o} all: options xssstate options: @echo xssstate build options: @echo "CFLAGS = ${CFLAGS}" @echo "LDFLAGS = ${LDFLAGS}" @echo "CC = ${CC}" .c.o: @echo CC $< @${CC} -c ${CFLAGS} $< ${OBJ}: config.mk xssstate: xssstate.o @echo CC -o $@ @${CC} -o $@ xssstate.o ${LDFLAGS} clean: @echo cleaning @rm -f xssstate ${OBJ} xssstate-${VERSION}.tar.gz dist: clean @echo creating dist tarball @mkdir -p xssstate-${VERSION} @cp -R LICENSE README Makefile config.mk xsidle.sh \ xssstate.1 arg.h ${SRC} xssstate-${VERSION} @tar -cf xssstate-${VERSION}.tar xssstate-${VERSION} @gzip xssstate-${VERSION}.tar @rm -rf xssstate-${VERSION} install: all @echo installing executable file to ${DESTDIR}${PREFIX}/bin @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f xssstate ${DESTDIR}${PREFIX}/bin @chmod 755 ${DESTDIR}${PREFIX}/bin/xssstate @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < xssstate.1 > ${DESTDIR}${MANPREFIX}/man1/xssstate.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/xssstate.1 uninstall: @echo removing executable file from ${DESTDIR}${PREFIX}/bin @rm -f ${DESTDIR}${PREFIX}/bin/xssstate @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 @rm -f ${DESTDIR}${MANPREFIX}/man1/xssstate.1 .PHONY: all options clean dist install uninstall xssstate-1.1/README000066400000000000000000000014201214221256000141010ustar00rootroot00000000000000Xssstate ======== This is a simple utility to get the state of the X screensaver exten‐ sion. These states include the idle time, the screensaver state and the time how long to wait until the screensaver should be active. The values for the states in X can be changed using xset(1). Turn off the screensaver: % xset s 0 Turn on the screensaver after 60 seconds inactivity: % xset s 60 Force the screensaver to be active: % xset s blank For more options, see xset(1). Example script -------------- In xsidle.sh is an example script how to use this for a background ser‐ vice that will control your screensaver. This can be used to invoke slock(1) using following command: % xsidle.sh slock & This should be useful in your $HOME/.xinitrc file. Have fun! xssstate-1.1/arg.h000066400000000000000000000021031214221256000141420ustar00rootroot00000000000000/* * Copy me if you can. * by 20h */ #ifndef __ARG_H__ #define __ARG_H__ extern char *argv0; #define USED(x) ((void)(x)) /* use main(int argc, char *argv[]) */ #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ argv[0] && argv[0][1]\ && argv[0][0] == '-';\ argc--, argv++) {\ char _argc;\ char **_argv;\ int brk;\ if (argv[0][1] == '-' && argv[0][2] == '\0') {\ argv++;\ argc--;\ break;\ }\ for (brk = 0, argv[0]++, _argv = argv;\ argv[0][0] && !brk;\ argv[0]++) {\ if (_argv != argv)\ break;\ _argc = argv[0][0];\ switch (_argc) #define ARGEND }\ USED(_argc);\ }\ USED(argv);\ USED(argc); #define ARGC() _argc #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ ((x), abort(), (char *)0) :\ (brk = 1, (argv[0][1] != '\0')?\ (&argv[0][1]) :\ (argc--, argv++, argv[0]))) #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ (char *)0 :\ (brk = 1, (argv[0][1] != '\0')?\ (&argv[0][1]) :\ (argc--, argv++, argv[0]))) #endif xssstate-1.1/config.mk000066400000000000000000000007031214221256000150220ustar00rootroot00000000000000# xssstate version VERSION = 1.1 # Customize below to fit your system # paths PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man # includes and libs INCS = -I. -I/usr/include LIBS = -L/usr/lib -lc -lX11 -lXss # flags CPPFLAGS = -DVERSION=\"${VERSION}\" CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} LDFLAGS = -g ${LIBS} # Solaris #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" #LDFLAGS = ${LIBS} # compiler and linker CC = cc xssstate-1.1/xsidle.sh000077500000000000000000000005501214221256000150530ustar00rootroot00000000000000#!/bin/sh # # Use xset s $time to control the timeout when this will run. # if [ $# -lt 1 ]; then printf "usage: %s cmd\n" "$(basename $0)" 2>&1 exit 1 fi cmd="$1" while true do if [ $(xssstate -s) != "disabled" ]; then tosleep=$(($(xssstate -t) / 1000)) if [ $tosleep -le 0 ]; then $cmd else sleep $tosleep fi else sleep 10 fi done xssstate-1.1/xssstate.1000066400000000000000000000016061214221256000151670ustar00rootroot00000000000000.TH XSSSTATE 1 xssstate\-VERSION .SH NAME xssstate \- display X screensaver state .SH SYNOPSIS .B xssstate .RB [ \-i ] .RB [ \-s ] .RB [ \-t ] .RB [ \-v ] .SH DESCRIPTION .B xssstate will display the state of the X screensaver extension. See below what can be gathered. .SH OPTIONS .TP .B \-i show the idle time of X11, in milliseconds. .TP .B \-s show the current state of the X screensaver. There is .B "on" for the screensaver being active at the moment, .B "off" for the screensaver being off and .B "disabled" for the screensaver being disabled. .TP .B \-t will show the time that needs to be waited until the screensaver should be activated, in milliseconds. .TP .B \-v show version information .SH AUTHORS See the LICENSE file for the authors. .SH LICENSE See the LICENSE file for the terms of redistribution. .SH SEE ALSO .BR slock (1) .BR xlock (1) .BR xss (1) .SH BUGS Please report them. xssstate-1.1/xssstate.c000066400000000000000000000033721214221256000152530ustar00rootroot00000000000000/* * See LICENSE file for copyright and license details. */ #include #include #include #include #include #include #include #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]\n", 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.\n"); default: usage(); } ARGEND; if (!showstate && !showtill && !showidle) usage(); if (!(dpy = XOpenDisplay(0))) die("Cannot open display.\n"); if (!XScreenSaverQueryExtension(dpy, &base, &errbase)) die("Screensaver extension not activated.\n"); info = XScreenSaverAllocInfo(); XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info); if (showstate) { switch(info->state) { case ScreenSaverOn: printf("on\n"); break; case ScreenSaverOff: printf("off\n"); break; case ScreenSaverDisabled: printf("disabled\n"); break; } } else if (showtill) { switch(info->state) { case ScreenSaverOn: printf("0\n"); break; case ScreenSaverOff: printf("%lu\n", info->til_or_since); break; case ScreenSaverDisabled: printf("-1\n"); break; } } else if (showidle) { printf("%lu\n", info->idle); } XCloseDisplay(dpy); return 0; }