From 3b6325916f4163c359f33dcf30c5c981386421d4 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 14 Feb 2011 23:29:03 +0000 Subject: [PATCH] - client, linux: use X server for idle detection if available svn path=/trunk/boinc/; revision=23035 --- checkin_notes | 7 +++++++ client/hostinfo_unix.cpp | 39 ++++++++++++++++++++++++++++++++++++++- configure.ac | 14 ++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/checkin_notes b/checkin_notes index 6ce7267e7a..d292cb69b3 100644 --- a/checkin_notes +++ b/checkin_notes @@ -743,3 +743,10 @@ David 14 Feb 2011 html/user/ sample_index.php main.css + +David 14 Feb 2011 + - client, linux: use X server for idle detection if available + + configure.ac + client/ + hostinfo_unix.cpp diff --git a/client/hostinfo_unix.cpp b/client/hostinfo_unix.cpp index 64c437a364..e6d6a5ad2f 100644 --- a/client/hostinfo_unix.cpp +++ b/client/hostinfo_unix.cpp @@ -149,6 +149,10 @@ mach_port_t gEventHandle = NULL; #define _SC_PAGESIZE _SC_PAGE_SIZE #endif +#if HAVE_XSS +#include +#endif + // The following is intended to be true both on Linux // and Debian GNU/kFreeBSD (see trac #521) // @@ -1679,7 +1683,33 @@ bool interrupts_idle(time_t t) { } return last_irq < t; } -#endif + +#if HAVE_XSS +// Ask the X server for user idle time (using XScreenSaver API) +// Returns true if the idle_treshold is smaller than the +// idle time of the user (means: true = user is idle) +bool xss_idle(long idle_treshold) { + static XScreenSaverInfo* xssInfo = NULL; + static Display* disp = NULL; + + long idle_time = 0; + + if(disp != NULL) { + XScreenSaverQueryInfo(disp, DefaultRootWindow(disp), xssInfo); + idle_time = xssInfo->idle / 1000; // xssInfo->idle is in ms + } else { + disp = XOpenDisplay(NULL); + // XOpenDisplay may return NULL if there is no running X + // or DISPLAY points to wrong/invalid display + if(disp != NULL) { + xssInfo = XScreenSaverAllocInfo(); + } + } + + return idle_treshold < idle_time; +} +#endif // HAVE_XSS +#endif // LINUX_LIKE_SYSTEM bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { time_t idle_time = time(0) - (long) (60 * idle_time_to_run); @@ -1701,6 +1731,13 @@ bool HOST_INFO::users_idle(bool check_all_logins, double idle_time_to_run) { if (!interrupts_idle(idle_time)) { return false; } + +#if HAVE_XSS + if (!xss_idle((long)(idle_time_to_run * 60))) { + return false; + } +#endif + #else // We should find out which of the following are actually relevant // on which systems (if any) diff --git a/configure.ac b/configure.ac index b86ec1b118..e2e87b070c 100644 --- a/configure.ac +++ b/configure.ac @@ -549,6 +549,13 @@ fi AM_CONDITIONAL(BUILD_GRAPHICS_API, [ test "$have_glut" = yes ]) +dnl check for X screen saver lib +AC_CHECK_LIB([Xss], [XScreenSaverAllocInfo], [have_Xss="yes"], [have_Xss="no"]) +AC_CHECK_HEADER([X11/extensions/scrnsaver.h], [have_Xss="yes"], [have_Xss="no"]) +if test "$have_Xss" == no; then + AC_MSG_WARN([libxss missing, disabling X ScreenSaver user idle detection]) +fi + dnl -------------------------------------------------------------------------------- dnl put double-inclusion protection into config.h AH_TOP([ @@ -791,6 +798,13 @@ if test "${ac_cv_func_res_init}" != "yes" ; then fi LIBS=$svlibs +if test "$have_Xss" == yes; then + SAH_CHECK_LIB([Xss],[XScreenSaverAllocInfo],[ + AC_DEFINE([HAVE_XSS],[1],[Define to 1 if you have xss library]) + CLIENTLIBS="${sah_lib_last} ${CLIENTLIBS}"]) + echo DEBUG: CLIENTLIBS=${CLIENTLIBS} >&5 +fi + SAH_CHECK_LIB([resolv],[res_query],[ AC_DEFINE([HAVE_RESOLV],[1],[Define to 1 if you have the resolv library]) CLIENTLIBS="${sah_lib_last} ${CLIENTLIBS}"])