JNA is unable to get system idle time in ubuntu 11.10 version onwards.
public static long getIdleTimeMillis() {
X11.Window win = null;
Xss.XScreenSaverInfo info = null;
X11.Display dpy = null;
final X11 x11 = X11.INSTANCE;
final Xss xss = Xss.INSTANCE;
long idlemillis = 0L;
try {
dpy = x11.XOpenDisplay(null);
win = x11.XDefaultRootWindow(dpy);
info = xss.XScreenSaverAllocInfo();
xss.XScreenSaverQueryInfo(dpy, win, info);
idlemillis = info.idle.longValue();
} finally {
if (info != null)
x11.XFree(info.getPointer());
info = null;
if (dpy != null)
x11.XCloseDisplay(dpy);
dpy = null;
}
return idlemillis;
I am using this code to capture idle time. It is working fine in lower versions of ubuntu. but it is not working in latest versions.
It is not moving from the line
final Xss xss = Xss.INSTANCE;
please suggest me a proper solution.
Copyright Notice:Content Author:「Martin」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14414771/jna-is-unable-to-get-system-idle-time-in-ubuntu-11-10-version-onwards