/* 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);
}
XScreenSaverQueryInfo(dpy, DefaultRootWindow(display), info);
should be like this
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
Edit: Sorry, too slow
]]>@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
$ mplayer <video file>; shutdown -h now
]]>/* 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);
}
sleep 2h; halt
in a terminal as root before starting the movie (or a longer time if the movie is a long one).
]]>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.
]]>Maybe somebody has any other ideas? Thanks.
]]>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!
]]>