diff --git a/client/client_state.C b/client/client_state.C index 241e92a441..5b1a45d630 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -328,7 +328,9 @@ int CLIENT_STATE::net_sleep(double x) { bool CLIENT_STATE::do_something() { int actions = 0, reason, retval; SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_POLL); - +#ifndef _WIN32 + check_idle(); +#endif check_suspend_activities(reason); if (reason) { if (!activities_suspended) { diff --git a/client/client_state.h b/client/client_state.h index d5e30e2730..31bace7b6b 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -230,6 +230,9 @@ private: int resume_network(); void install_global_prefs(); void show_global_prefs_source(bool); +#ifndef _WIN32 + void check_idle(); +#endif // --------------- cs_scheduler.C: public: diff --git a/client/cs_prefs.C b/client/cs_prefs.C index 2753197eb4..6b111ddc56 100644 --- a/client/cs_prefs.C +++ b/client/cs_prefs.C @@ -25,6 +25,15 @@ #include "stdafx.h" #endif +#ifndef _WIN32 +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#endif + #include "util.h" #include "filesys.h" #include "file_names.h" @@ -92,6 +101,22 @@ inline bool now_between_two_hours(int start_hour, int end_hour) { } } +#ifndef _WIN32 +// returns true iff device was last accessed before t +// or if an error occurred looking at the device. +inline bool device_idle(time_t t, char *device) { + struct stat sbuf; + return stat(device, &sbuf) || (sbuf.st_atime < t); +} + +void CLIENT_STATE::check_idle() { + time_t idle_time = + time(NULL) - (long) (60 * global_prefs.idle_time_to_run); + user_idle = device_idle(idle_time, "/dev/kbd") + && device_idle(idle_time, "/dev/mouse"); +} +#endif + // See if (on the basis of user run request and prefs) // we should suspend activities. //