diff options
author | Rob Taylor <rob.taylor@codethink.co.uk> | 2007-08-22 14:48:11 +0100 |
---|---|---|
committer | Rob Taylor <rob.taylor@codethink.co.uk> | 2007-08-22 15:17:50 +0100 |
commit | 7ba694c385e62e6d668202952969c007ab364792 (patch) | |
tree | 7d96688201df0cbb259cb9e26fdcc9eda559a298 | |
parent | dae3b4dd679d9209afa9447298e8a056ebefc411 (diff) |
fixes for the new idle plugin interface
Cope with start case where idle.timeout is 0. Cope with delayed X connection.
Timeouts are measured from last activity, not last alarm.
-rw-r--r-- | plugins/glue/idle/ohm-plugin-idle.c | 30 | ||||
-rw-r--r-- | plugins/policy/timeouts/timeouts.c | 17 |
2 files changed, 27 insertions, 20 deletions
diff --git a/plugins/glue/idle/ohm-plugin-idle.c b/plugins/glue/idle/ohm-plugin-idle.c index 74aed96..5c6bff4 100644 --- a/plugins/glue/idle/ohm-plugin-idle.c +++ b/plugins/glue/idle/ohm-plugin-idle.c @@ -67,13 +67,15 @@ plugin_connect_idletime (OhmPlugin *plugin) g_signal_connect (idletime, "alarm-expired", G_CALLBACK (ohm_alarm_expired_cb), plugin); - ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout); - ohm_plugin_conf_set_key (plugin, "idle.state", 0); - ret = idletime_alarm_set (idletime, 1, timeout); - if (ret == FALSE) { - g_error ("cannot set alarm"); + ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout); + + if (timeout != 0) { + ret = idletime_alarm_set (idletime, 1, timeout); + if (ret == FALSE) { + g_error ("cannot set alarm"); + } } } @@ -114,12 +116,16 @@ plugin_notify (OhmPlugin *plugin, gint id, gint value) if (value == 1) { plugin_connect_idletime (plugin); } - } else if (id == CONF_IDLE_TIMEOUT_CHANGED ) { - idletime_alarm_set (idletime, 1, value); - } else if (id == CONF_IDLE_STATE_CHANGED ) { - if (value == 0) { - ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout); - idletime_alarm_set (idletime, 1, timeout); + } + if (idletime) { + if (id == CONF_IDLE_TIMEOUT_CHANGED ) { + g_debug("setting new timeout %d", value); + idletime_alarm_set (idletime, 1, value); + } else if (id == CONF_IDLE_STATE_CHANGED ) { + if (value == 0) { + ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout); + idletime_alarm_set (idletime, 1, timeout); + } } } } @@ -142,7 +148,7 @@ OHM_PLUGIN_DESCRIPTION ( OHM_PLUGIN_REQUIRES ("xorg"); -OHM_PLUGIN_PROVIDES ("idle.state"); +OHM_PLUGIN_PROVIDES ("idle.state", "idle.timeout"); OHM_PLUGIN_INTERESTED ( {"xorg.has_xauthority", CONF_XORG_HASXAUTH_CHANGED}, diff --git a/plugins/policy/timeouts/timeouts.c b/plugins/policy/timeouts/timeouts.c index 133dd36..718af5b 100644 --- a/plugins/policy/timeouts/timeouts.c +++ b/plugins/policy/timeouts/timeouts.c @@ -41,29 +41,30 @@ init (OhmPlugin *plugin) static void notify (OhmPlugin *plugin, gint id, gint value) { - gint new_timeout, old_timeout; + gint new_timeout; if (id != CONF_IDLE_STATE_CHANGED) return; switch (value) { case 0: - ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", &new_timeout); + ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", + &new_timeout); ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout); ohm_plugin_conf_set_key (plugin, "timeouts.momentary", 0); ohm_plugin_conf_set_key (plugin, "timeouts.powersave", 0); ohm_plugin_conf_set_key (plugin, "timeouts.powerdown", 0); break; case 1: - ohm_plugin_conf_get_key (plugin, "timeouts.timer_powersave", &new_timeout); - ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", &old_timeout); - ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout-old_timeout); + ohm_plugin_conf_get_key (plugin, "timeouts.timer_powersave", + &new_timeout); + ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout); ohm_plugin_conf_set_key (plugin, "timeouts.momentary", 1); break; case 2: - ohm_plugin_conf_get_key (plugin, "timeouts.timer_powerdown", &new_timeout); - ohm_plugin_conf_get_key (plugin, "timeouts.timer_powersave", &old_timeout); - ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout-old_timeout); + ohm_plugin_conf_get_key (plugin, "timeouts.timer_powerdown", + &new_timeout); + ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout); ohm_plugin_conf_set_key (plugin, "timeouts.powersave", 1); break; case 3: |