X11::IdleTime bug && fix
Kurt Jaeger
pi at c0mplx.org
Sat Jan 13 18:47:21 UTC 2007
Hi!
I've recently tried the perl module
X11::IdleTime
and it seems to always report 4 seconds idle-time to me:
hdog$ sleep 10; ./idle
Your mouse and keyboard have been idle for 4 seconds.
This seems strange. I checked the source and the following diff
fixes a small bug with the sequence the mit_info struct is free()ed
and used (and some usage bug of XScreenSaverQueryInfo()).
Hope this helps.
------------
--- IdleTime.pm.orig Thu Feb 10 17:54:42 2005
+++ IdleTime.pm Sat Jan 13 19:19:35 2007
@@ -6,12 +6,13 @@
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(GetIdleTime);
-$VERSION = '0.01';
+$VERSION = '0.03';
use Inline (
C => 'DATA',
VERSION => '0.03',
NAME => 'X11::IdleTime',
+ INC => '-I/usr/X11R6/include/',
LIBS => '-L/usr/X11R6/lib/ -lX11 -lXext -lXss',
);
@@ -62,12 +63,22 @@
static XScreenSaverInfo *mit_info;
Display *display;
int screen;
+ Bool extavail;
+ XEvent myevent;
+ int event_base, error_base;
mit_info = XScreenSaverAllocInfo();
- if((display=XOpenDisplay(NULL)) == NULL) { return(-1); }
+ if((display=XOpenDisplay(NULL)) == NULL) { return(-2); }
screen = DefaultScreen(display);
+
+ extavail = XScreenSaverQueryExtension(display, &event_base,
+ &error_base);
+ if ( extavail == False ) {
+ return(-1);
+ }
+
XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info);
+ idle_time = (mit_info->idle) / 1000;
XFree(mit_info);
XCloseDisplay(display);
- idle_time = (mit_info->idle) / 1000;
return idle_time;
}
--------------------
--
pi at c0mplx.org +49 171 3101372 13 years to go !
More information about the freebsd-perl
mailing list