Ticket #463: 463_xss.patch

File 463_xss.patch, 1.6 KB (added by cli, 13 years ago)

Patch for idle detection using Xserver

  • client/hostinfo_unix.cpp

     
    149149#define _SC_PAGESIZE _SC_PAGE_SIZE
    150150#endif
    151151
     152#include <X11/extensions/scrnsaver.h> // TODO encaps in ifdefs
     153
    152154// The following is intended to be true both on Linux
    153155// and Debian GNU/kFreeBSD (see trac #521)
    154156//
     
    16281630    }
    16291631    return last_irq < t;
    16301632}
    1631 #endif
    16321633
     1634// Ask the X server for user idle time (using XScreenSaver API)
     1635// Returns true if the idle_treshold is smaller than the
     1636// idle time of the user (means: true = user is idle)
     1637bool xss_idle(long idle_treshold) {
     1638        static XScreenSaverInfo* xssInfo = XScreenSaverAllocInfo();
     1639        static Display* disp = XOpenDisplay(NULL);
     1640        long idle_time = 0;
     1641       
     1642        if(disp != NULL) {
     1643                XScreenSaverQueryInfo(disp, DefaultRootWindow(disp), xssInfo);
     1644                idle_time = xssInfo->idle / 1000; // xssInfo->idle is in ms
     1645        } else {
     1646                msg_printf(NULL, MSG_INFO, "Cannot find default display. DISPLAY set?");
     1647        }
     1648        //msg_printf(NULL, MSG_INFO, "tresh: %ld idle_time: %ld", idle_treshold, idle_time);
     1649        return idle_treshold < idle_time;
     1650}
     1651#endif // LINUX_LIKE_SYSTEM
     1652
    16331653bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) {
    16341654    time_t idle_time = time(0) - (long) (60 * idle_time_to_run);
    16351655
     
    16501670    if (!interrupts_idle(idle_time)) {
    16511671        return false;
    16521672    }
     1673   
     1674    if (!xss_idle((long)(idle_time_to_run * 60))) {
     1675                return false;
     1676        }
    16531677#else
    16541678    // We should find out which of the following are actually relevant
    16551679    // on which systems (if any)