Ticket #463: 463_xss_1.patch

File 463_xss_1.patch, 2.8 KB (added by cli, 13 years ago)

More robust patch for X idle detection

  • configure.ac

     
    549549
    550550AM_CONDITIONAL(BUILD_GRAPHICS_API, [ test "$have_glut" = yes ])
    551551
     552dnl check for X screen saver lib
     553AC_CHECK_LIB([Xss], [XScreenSaverAllocInfo], [have_Xss="yes"], [have_Xss="no"])
     554AC_CHECK_HEADER([X11/extensions/scrnsaver.h], [have_Xss="yes"], [have_Xss="no"])
     555if test "$have_Xss" == no; then
     556    AC_MSG_WARN([libxss missing, disabling X ScreenSaver user idle detection])
     557fi
     558
    552559dnl --------------------------------------------------------------------------------
    553560dnl put double-inclusion protection into config.h
    554561AH_TOP([
     
    791798fi
    792799LIBS=$svlibs
    793800
     801if test "$have_Xss" == yes; then
     802    SAH_CHECK_LIB([Xss],[XScreenSaverAllocInfo],[
     803        AC_DEFINE([HAVE_XSS],[1],[Define to 1 if you have xss library])
     804        CLIENTLIBS="${sah_lib_last} ${CLIENTLIBS}"])
     805    echo DEBUG: CLIENTLIBS=${CLIENTLIBS} >&5
     806fi
     807
    794808SAH_CHECK_LIB([resolv],[res_query],[
    795809    AC_DEFINE([HAVE_RESOLV],[1],[Define to 1 if you have the resolv library])
    796810    CLIENTLIBS="${sah_lib_last} ${CLIENTLIBS}"])
  • client/hostinfo_unix.cpp

     
    149149#define _SC_PAGESIZE _SC_PAGE_SIZE
    150150#endif
    151151
     152#if HAVE_XSS
     153#include <X11/extensions/scrnsaver.h>
     154#endif
     155
    152156// The following is intended to be true both on Linux
    153157// and Debian GNU/kFreeBSD (see trac #521)
    154158//
     
    16791683    }
    16801684    return last_irq < t;
    16811685}
    1682 #endif
    16831686
     1687#if HAVE_XSS
     1688// Ask the X server for user idle time (using XScreenSaver API)
     1689// Returns true if the idle_treshold is smaller than the
     1690// idle time of the user (means: true = user is idle)
     1691bool xss_idle(long idle_treshold) {
     1692        static XScreenSaverInfo* xssInfo = NULL;
     1693        static Display* disp = NULL;
     1694       
     1695        long idle_time = 0;
     1696       
     1697        if(disp != NULL) {
     1698                XScreenSaverQueryInfo(disp, DefaultRootWindow(disp), xssInfo);
     1699                idle_time = xssInfo->idle / 1000; // xssInfo->idle is in ms
     1700        } else {
     1701                disp = XOpenDisplay(NULL);
     1702                // XOpenDisplay may return NULL if there is no running X
     1703                // or DISPLAY points to wrong/invalid display
     1704                if(disp != NULL) {
     1705                        xssInfo = XScreenSaverAllocInfo();
     1706                }
     1707        }
     1708
     1709        return idle_treshold < idle_time;
     1710}
     1711#endif // HAVE_XSS
     1712#endif // LINUX_LIKE_SYSTEM
     1713
    16841714bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) {
    16851715    time_t idle_time = time(0) - (long) (60 * idle_time_to_run);
    16861716
     
    17011731    if (!interrupts_idle(idle_time)) {
    17021732        return false;
    17031733    }
     1734
     1735#if HAVE_XSS
     1736        if (!xss_idle((long)(idle_time_to_run * 60))) {
     1737                return false;
     1738        }
     1739#endif
     1740
    17041741#else
    17051742    // We should find out which of the following are actually relevant
    17061743    // on which systems (if any)