Compare commits

...

10 Commits

Author SHA1 Message Date
orbea 5d8e9b49ce config.mk: Add LIBDIR
Signed-off-by: Christoph Lohmann <20h@r-36.net>
2022-09-24 10:56:12 +02:00
Christoph Lohmann 7cbc05ec64 Update arg.h to be without the out of bound bug. 2016-02-27 23:19:12 +01:00
Christoph Lohmann be0fb159e4 Update the year. 2016-02-27 23:18:54 +01:00
Phil Pirozhkov f58232beb2 Pass parameters over to cmd, e.g.:
xsidle.sh ls -l /usr

Signed-off-by: Christoph Lohmann <20h@r-36.net>
2014-10-14 18:43:24 +02:00
Christoph Lohmann cd05e2ae0c Making the license fetishists happy. 2013-06-23 21:08:33 +02:00
Christoph Lohmann 01947a896e 1.1 release. 2013-05-07 16:53:36 +02:00
Petr Šabata 8308a0086f Use correct format strings
Both idle and til_or_since are defined as unsigned longs.

Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-05-07 16:53:19 +02:00
Christoph Lohmann 7d3a822d38 Adding the manpage too. Thanks woddf2! 2013-02-01 13:10:14 +01:00
Christoph Lohmann ea369273fd Adding the main C file too. 2012-12-09 07:10:32 +01:00
Christoph Lohmann c30b12c8e9 Adding an example script for slock. 2012-12-08 22:41:48 +01:00
8 changed files with 233 additions and 27 deletions

View File

@ -1,7 +1,7 @@
MIT/X Consortium License
© 2008 Kai Hendry <hendry@webconverger.com>
© 2012 Christoph Lohmann <20h@r-36.net>
© 2012-2016 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"),

View File

@ -30,7 +30,7 @@ clean:
dist: clean
@echo creating dist tarball
@mkdir -p xssstate-${VERSION}
@cp -R LICENSE Makefile config.mk \
@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

34
README Normal file
View File

@ -0,0 +1,34 @@
Xssstate
========
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!

39
arg.h
View File

@ -3,53 +3,46 @@
* by 20h
*/
#ifndef __ARG_H__
#define __ARG_H__
#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] == '-';\
argv[0] && argv[0][0] == '-'\
&& argv[0][1];\
argc--, argv++) {\
char _argc;\
char **_argv;\
int brk;\
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;\
for (brk_ = 0, argv[0]++, argv_ = argv;\
argv[0][0] && !brk_;\
argv[0]++) {\
if (_argv != argv)\
if (argv_ != argv)\
break;\
_argc = argv[0][0];\
switch (_argc)
argc_ = argv[0][0];\
switch (argc_)
#define ARGEND }\
USED(_argc);\
}\
USED(argv);\
USED(argc);
}
#define ARGC() _argc
#define ARGC() argc_
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
((x), abort(), (char *)0) :\
(brk = 1, (argv[0][1] != '\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')?\
(brk_ = 1, (argv[0][1] != '\0')?\
(&argv[0][1]) :\
(argc--, argv++, argv[0])))
#endif

View File

@ -1,15 +1,16 @@
# xssstate version
VERSION = 1.0
VERSION = 1.1
# Customize below to fit your system
# paths
PREFIX = /usr/local
LIBDIR = ${PREFIX}/lib
MANPREFIX = ${PREFIX}/share/man
# includes and libs
INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc -lX11 -lXss
LIBS = -L${LIBDIR} -lc -lX11 -lXss
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\"

28
xsidle.sh Executable file
View File

@ -0,0 +1,28 @@
#!/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="$@"
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

44
xssstate.1 Normal file
View File

@ -0,0 +1,44 @@
.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.

106
xssstate.c Normal file
View File

@ -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]\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-2016 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;
}