package X11::IdleTime; use strict; use warnings; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; @ISA = qw(Exporter); @EXPORT = qw(GetIdleTime); $VERSION = '0.08'; use Inline ( C => 'DATA', VERSION => '0.08', NAME => 'X11::IdleTime', LIBS => '-L/usr/X11R6/lib/ -lX11 -lXext -lXss', ); 1; __DATA__ =pod =head1 NAME X11::IdleTime - Get the idle time of X11 =head1 SYNOPSIS use X11::IdleTime; $idle = GetIdleTime(); print "Your mouse and keyboard have been idle for $idle seconds.\n"; =head1 DESCRIPTION The X11::IdleTime module is useful for checking how long the user has been idle. =head1 AUTHOR Adam Wendt (http://blog.thelsdj.org/) =head1 COPYRIGHT Copyright 2003-2008 Adam Wendt This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut __C__ #include #include #include #include #include #include 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; }