0

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.

Martin
  • 1

1 Answers1

0

In fact, this code works only if "libxss1" package is installed on system. Since ubuntu 11.10, libXss.so is not installed by default.

sudo apt-get install libxss1 solve this, but require additional system package installation

chatellier
  • 179
  • 14