You are not logged in.
Pages: 1
Topic closed
Hi there,
I want to write a script that shuts down the computer if I don't use X11 keyboard and mouse and no video player is running after 12PM. I hate waking up in the morning with the computer running after falling asleep during a movie.
How can I detect if I'm using X11? Is there any way to check if dpms kicked in or the mouse and keyboard aren't used for some time? Or some screensaver can tell over dbus if it's active or not? (right now i don't use any screensaver, only X11 dpms).
Pidgin has a way of detecting user inactivity based on keyboard and mouse usage, so probably there is a way to do this. Any ideas?
Thanks a lot!
Last edited by silvik (2011-07-04 09:06:19)
Offline
Why not just use the power management options? Like setting the computer to hibernate/suspend after an hour or two. The computer will use far less power, take quicker to resume and turn off at anytime when idle, not just at night. I'm not sure of another way to do it though without xscreensaver, or whatever method you use to set your power settings.
Desktop: Arch Linux | AMD Athlon 64 X2 Dual Core 5000+ | 3GB RAM | GeForce 6800 XT 512MB | 1TB+
Audio Studio: XP SP3 | Intel Pentium 4 3GHz Prescott | 1GB DDR | GeForce 6800 128MB | 120GB
Offline
Except ondemand frequency settings I don't use any power management, it's just a plain openbox desktop with a panel.
Last time I checked resume didn't work. Probably still doesn't. Anyway, it's not really what I'm looking for.
Maybe somebody has any other ideas? Thanks.
Offline
If you know how to program in C, I believe you can use Xorg's xscreensaver API. Do a 'man xscreensaver' for details.
I've never tried to use this, so I'm not exactly sure how it works; I'd have to play around with it some to figure it out.
Offline
FYI, the Pidgin code that does this is in "pidgin/gtkidle.c" in the pidgin source. Hope that helps!
6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.
Offline
Do you really want something this complicated ? If it's just for watching movies, you could consider just typing
sleep 2h; halt
in a terminal as root before starting the movie (or a longer time if the movie is a long one).
Offline
18 lines of C...
/* gcc -o getIdleTime getIdleTime.c -lXss */
#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {
return(1);
}
XScreenSaverInfo *info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
printf("%u", info->idle);
return(0);
}
Last edited by falconindy (2011-07-03 14:09:11)
Offline
sinac might work for you, but for movies I would just use
$ mplayer <video file>; shutdown -h now
Offline
Thanks for all answers!
@falconindy: Probably that's what I need, but I get some errors while compiling (sorry, I'm not a programmer):
silvik@morgana:/build$ gcc -o getIdleTime getIdleTime.c -lXss
getIdleTime.c: In function ‘main’:
getIdleTime.c:13:30: error: ‘display’ undeclared (first use in this function)
getIdleTime.c:13:30: note: each undeclared identifier is reported only once for each function it appears in
Offline
Well this
XScreenSaverQueryInfo(dpy, DefaultRootWindow(display), info);
should be like this
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
Edit: Sorry, too slow
Last edited by Foucault (2011-07-03 14:13:29)
Offline
thanks. problem solved. falconindy's program work great! (output in milliseconds)
Offline
2021 version:
/* https://bbs.archlinux.org/viewtopic.php?pid=956113#p956113 */
/* install libxss-dev, libx11-dev */
/* LANG=C gcc -Wall -Wextra -Werror -o getIdleTime getIdleTime.c -lXss -lX11 */
#include <X11/extensions/scrnsaver.h>
#include <X11/Xlib.h>
#include <stdio.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {
return(1);
}
XScreenSaverInfo *info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
printf("%lu", info->idle);
XFree(info);
XCloseDisplay(dpy);
return(0);
}
Last edited by Topsy (2021-11-03 21:30:39)
Offline
Closing this old solved topic.
Offline
Pages: 1
Topic closed