Compare commits
10 Commits
f91e73ae45
...
5d8e9b49ce
| Author | SHA1 | Date |
|---|---|---|
|
|
5d8e9b49ce | |
|
|
7cbc05ec64 | |
|
|
be0fb159e4 | |
|
|
f58232beb2 | |
|
|
cd05e2ae0c | |
|
|
01947a896e | |
|
|
8308a0086f | |
|
|
7d3a822d38 | |
|
|
ea369273fd | |
|
|
c30b12c8e9 |
2
LICENSE
2
LICENSE
|
|
@ -1,7 +1,7 @@
|
||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
© 2008 Kai Hendry <hendry@webconverger.com>
|
© 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
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -30,7 +30,7 @@ clean:
|
||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
@echo creating dist tarball
|
||||||
@mkdir -p xssstate-${VERSION}
|
@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}
|
xssstate.1 arg.h ${SRC} xssstate-${VERSION}
|
||||||
@tar -cf xssstate-${VERSION}.tar xssstate-${VERSION}
|
@tar -cf xssstate-${VERSION}.tar xssstate-${VERSION}
|
||||||
@gzip xssstate-${VERSION}.tar
|
@gzip xssstate-${VERSION}.tar
|
||||||
|
|
|
||||||
|
|
@ -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
39
arg.h
|
|
@ -3,53 +3,46 @@
|
||||||
* by 20h
|
* by 20h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __ARG_H__
|
#ifndef ARG_H__
|
||||||
#define __ARG_H__
|
#define ARG_H__
|
||||||
|
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
|
|
||||||
#define USED(x) ((void)(x))
|
|
||||||
|
|
||||||
/* use main(int argc, char *argv[]) */
|
/* use main(int argc, char *argv[]) */
|
||||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
||||||
argv[0] && argv[0][1]\
|
argv[0] && argv[0][0] == '-'\
|
||||||
&& argv[0][0] == '-';\
|
&& argv[0][1];\
|
||||||
argc--, argv++) {\
|
argc--, argv++) {\
|
||||||
char _argc;\
|
char argc_;\
|
||||||
char **_argv;\
|
char **argv_;\
|
||||||
int brk;\
|
int brk_;\
|
||||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||||
argv++;\
|
argv++;\
|
||||||
argc--;\
|
argc--;\
|
||||||
break;\
|
break;\
|
||||||
}\
|
}\
|
||||||
for (brk = 0, argv[0]++, _argv = argv;\
|
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
||||||
argv[0][0] && !brk;\
|
argv[0][0] && !brk_;\
|
||||||
argv[0]++) {\
|
argv[0]++) {\
|
||||||
if (_argv != argv)\
|
if (argv_ != argv)\
|
||||||
break;\
|
break;\
|
||||||
_argc = argv[0][0];\
|
argc_ = argv[0][0];\
|
||||||
switch (_argc)
|
switch (argc_)
|
||||||
|
|
||||||
#define ARGEND }\
|
#define ARGEND }\
|
||||||
USED(_argc);\
|
}
|
||||||
}\
|
|
||||||
USED(argv);\
|
|
||||||
USED(argc);
|
|
||||||
|
|
||||||
#define ARGC() _argc
|
#define ARGC() argc_
|
||||||
|
|
||||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||||
((x), abort(), (char *)0) :\
|
((x), abort(), (char *)0) :\
|
||||||
(brk = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||||
(char *)0 :\
|
(char *)0 :\
|
||||||
(brk = 1, (argv[0][1] != '\0')?\
|
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||||
(&argv[0][1]) :\
|
(&argv[0][1]) :\
|
||||||
(argc--, argv++, argv[0])))
|
(argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
# xssstate version
|
# xssstate version
|
||||||
VERSION = 1.0
|
VERSION = 1.1
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
|
LIBDIR = ${PREFIX}/lib
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
MANPREFIX = ${PREFIX}/share/man
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
INCS = -I. -I/usr/include
|
INCS = -I. -I/usr/include
|
||||||
LIBS = -L/usr/lib -lc -lX11 -lXss
|
LIBS = -L${LIBDIR} -lc -lX11 -lXss
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -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.
|
||||||
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue