diff --git a/client/client_state.cpp b/client/client_state.cpp index 88bf779355f..39c1e1e3afb 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -1019,18 +1019,30 @@ bool CLIENT_STATE::poll_slow_events() { } #endif - bool old_user_active = user_active; + // there are 2 reasons to get idle state: + // if needed for computing prefs, + // or (on Mac) we were started by screensaver + // + bool get_idle_state = global_prefs.need_idle_state; +#ifdef __APPLE__ + if (started_by_screensaver) get_idle_state = true; +#endif + long idle_time; + if (get_idle_state) { + bool old_user_active = user_active; #ifdef ANDROID - user_active = device_status.user_active; + user_active = device_status.user_active; #else - long idle_time = host_info.user_idle_time(check_all_logins); - user_active = idle_time < global_prefs.idle_time_to_run * 60; + idle_time = host_info.user_idle_time(check_all_logins); + user_active = idle_time < global_prefs.idle_time_to_run * 60; #endif - - if (user_active != old_user_active) { - set_n_usable_cpus(); - // if niu_max_ncpus_pct pref is set, # usable CPUs may change - request_schedule_cpus(user_active?"Not idle":"Idle"); + if (user_active != old_user_active) { + set_n_usable_cpus(); + // if niu_max_ncpus_pct pref is set, # usable CPUs may change + request_schedule_cpus(user_active?"Not idle":"Idle"); + } + } else { + user_active = false; // shouldn't matter what it is } #if 0 diff --git a/client/cs_prefs.cpp b/client/cs_prefs.cpp index 48e8cf0a77d..377a49828df 100644 --- a/client/cs_prefs.cpp +++ b/client/cs_prefs.cpp @@ -675,6 +675,9 @@ void CLIENT_STATE::read_global_prefs( file_xfers->set_bandwidth_limits(true); file_xfers->set_bandwidth_limits(false); #endif + + bool have_gpu = coprocs.n_rsc > 1; + global_prefs.need_idle_state = global_prefs.get_need_idle_state(have_gpu); print_global_prefs(); request_schedule_cpus("Prefs update"); request_work_fetch("Prefs update"); @@ -815,6 +818,11 @@ void CLIENT_STATE::print_global_prefs() { allowed_disk_usage(total_disk_usage)/GIGA ); #endif + if (!global_prefs.need_idle_state) { + msg_printf(NULL, MSG_INFO, + "- Preferences don't depend on whether computer is in use" + ); + } msg_printf(NULL, MSG_INFO, "- (to change preferences, visit a project web site or select 'Options / Computing preferences...' in the Manager)" ); diff --git a/lib/prefs.h b/lib/prefs.h index 6dca2f5bfe2..5248694d42b 100644 --- a/lib/prefs.h +++ b/lib/prefs.h @@ -197,6 +197,8 @@ struct GLOBAL_PREFS { bool host_specific; // an account manager can set this; if set, don't propagate bool override_file_present; + bool need_idle_state; + // whether idle state makes any difference GLOBAL_PREFS(); void defaults(); @@ -214,6 +216,17 @@ struct GLOBAL_PREFS { return cpu_scheduling_period_minutes*60; } static double parse_mod_time(const char*); + bool get_need_idle_state(bool have_gpu) { + // is any pref set that causes different behavior if user is active? + // + if (!run_if_user_active) return true; + if (have_gpu && !run_gpu_if_user_active) return true; + if (suspend_if_no_recent_input) return true; + if (niu_cpu_usage_limit && niu_cpu_usage_limit != cpu_usage_limit) return true; + if (niu_max_ncpus_pct && niu_max_ncpus_pct != max_ncpus_pct) return true; + if (niu_suspend_cpu_usage && niu_suspend_cpu_usage != suspend_cpu_usage) return true; + return false; + } }; #endif