| X11-IdleTime documentation | Contained in the X11-IdleTime distribution. |
X11::IdleTime - Get the idle time of X11
use X11::IdleTime; $idle = GetIdleTime(); print "Your mouse and keyboard have been idle for $idle seconds.\n";
The X11::IdleTime module is useful for checking how long the user has been idle.
Adam Wendt <adam@ipwebdev.com> (http://ipwebdev.com/weblog/)
Copyright 2003-2007 Adam Wendt <thelsdj@gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| X11-IdleTime documentation | Contained in the X11-IdleTime distribution. |
package X11::IdleTime; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter); @EXPORT = qw(GetIdleTime); $VERSION = '0.05'; use Inline ( C => 'DATA', VERSION => '0.05', NAME => 'X11::IdleTime', LIBS => '-L/usr/X11R6/lib/ -lX11 -lXext -lXss', ); 1; __DATA__
__C__ #include <time.h> #include <stdio.h> #include <unistd.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/extensions/scrnsaver.h> int GetIdleTime () { time_t idle_time; static XScreenSaverInfo *mit_info; Display *display; int screen; mit_info = XScreenSaverAllocInfo(); if((display=XOpenDisplay(NULL)) == NULL) { return(-1); } screen = DefaultScreen(display); XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info); idle_time = (mit_info->idle) / 1000; XFree(mit_info); XCloseDisplay(display); return idle_time; }