Author: Arjan van de Ven * Make GAIM remember that X has the screensaver extension when it does; this avoids keeping X alive all the time because it's being asked stuff * Make the 5 second "Am I idle for 10 minutes" timer only fire at the time points that are interesting, so after 10 minutes or any other configured time; and not every 5 seconds. This code also would keep X active every 5 seconds which prevents X from going into idle mode. gtk/gtkidle.c | 5 ++++- libgaim/idle.c | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff -purN gaim-2.0.0beta6/libgaim.org/idle.c gaim-2.0.0beta6/libgaim/idle.c --- gaim-2.0.0beta6/libgaim.org/idle.c 2007-01-18 20:28:24.000000000 -0800 +++ gaim-2.0.0beta6/libgaim/idle.c 2007-04-13 16:44:31.000000000 -0700 @@ -92,6 +92,8 @@ set_account_unidle(GaimAccount *account) gaim_presence_set_idle(presence, FALSE, 0); } + +static gint time_until_next_idle_event; /* * This function should be called when you think your idle state * may have changed. Maybe you're over the 10-minute mark and @@ -110,14 +112,17 @@ set_account_unidle(GaimAccount *account) * 2. Set or unset your auto-away message. * 3. Report your current idle time to the IM server. */ + static gint -check_idleness() +check_idleness(void) { time_t time_idle; gboolean auto_away; const gchar *idle_reporting; gboolean report_idle; GList *l; + gint away_seconds = 0; + static int no_away = 0; gaim_signal_emit(gaim_blist_get_handle(), "update-idle"); @@ -153,15 +158,28 @@ check_idleness() time_idle = time(NULL) - last_active_time; } + time_until_next_idle_event = IDLEMARK- time_idle; /* reasonable start upperbound */ + + if (auto_away || !no_away) + away_seconds = 60 * gaim_prefs_get_int("/core/away/mins_before_away"); + if (auto_away && - (time_idle > (60 * gaim_prefs_get_int("/core/away/mins_before_away")))) + (time_idle > away_seconds )) { gaim_savedstatus_set_idleaway(TRUE); + no_away = 0; + if (time_idle < away_seconds && (away_seconds - time_idle) < time_until_next_idle_event) + time_until_next_idle_event = away_seconds - time_idle; } - else if (time_idle < 60 * gaim_prefs_get_int("/core/away/mins_before_away")) + else if (!no_away && time_idle < away_seconds) { gaim_savedstatus_set_idleaway(FALSE); + no_away = 1; + if (time_idle < away_seconds && (away_seconds - time_idle) < time_until_next_idle_event) + time_until_next_idle_event = away_seconds - time_idle; } + + /* Idle reporting stuff */ if (report_idle && (time_idle >= IDLEMARK)) @@ -177,10 +195,26 @@ check_idleness() while (idled_accts != NULL) set_account_unidle(idled_accts->data); } + + if (time_until_next_idle_event < 0) + time_until_next_idle_event = IDLEMARK; return TRUE; } + +/* + * Check idle and set the timer to fire at the next idle-worth event + */ +static gint +check_idleness_timer() +{ + check_idleness(); + + idle_timer = gaim_timeout_add(1000*(time_until_next_idle_event+1) , check_idleness_timer, NULL); + return FALSE; +} + static void im_msg_sent_cb(GaimAccount *account, const char *receiver, const char *message, void *data) diff -purN gaim-2.0.0beta6/gtk.org/gtkidle.c gaim-2.0.0beta6/gtk/gtkidle.c --- gaim-2.0.0beta6/gtk.org/gtkidle.c 2007-01-18 20:28:04.000000000 -0800 +++ gaim-2.0.0beta6/gtk/gtkidle.c 2007-04-13 15:12:55.000000000 -0700 @@ -103,8 +103,11 @@ gaim_gtk_get_time_idle() /* Query xscreensaver */ static XScreenSaverInfo *mit_info = NULL; + static int has_extension = -1; int event_base, error_base; - if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) { + if (has_extension == -1) + has_extension = XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base); + if (has_extension) { if (mit_info == NULL) { mit_info = XScreenSaverAllocInfo(); }