Author: Georgy Berdyshev * Changed the patch to apply with Pidgin * DATE: 15th May 2007 This patch is based on Gaim 2.0.0 Beta6 patch: =============================================== http://www.linuxpowertop.org/patches/gaim-2.0.patch 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. diff -purN pidgin-2.0.0-orig/libpurple/idle.c pidgin-2.0.0/libpurple/idle.c --- pidgin-2.0.0-orig/libpurple/idle.c 2007-04-26 07:35:54.000000000 +0200 +++ pidgin-2.0.0/libpurple/idle.c 2007-05-15 20:19:04.000000000 +0200 @@ -92,6 +92,8 @@ set_account_unidle(PurpleAccount *accoun purple_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 @@ -111,7 +113,7 @@ set_account_unidle(PurpleAccount *accoun * 3. Report your current idle time to the IM server. */ static gint -check_idleness() +check_idleness(void) { time_t time_idle; gboolean auto_away; @@ -119,6 +121,9 @@ check_idleness() gboolean report_idle; GList *l; + gint away_seconds=0; + static int no_away=0; + purple_signal_emit(purple_blist_get_handle(), "update-idle"); idle_reporting = purple_prefs_get_string("/purple/away/idle_reporting"); @@ -153,14 +158,28 @@ check_idleness() time_idle = time(NULL) - last_active_time; } - if (auto_away && - (time_idle > (60 * purple_prefs_get_int("/purple/away/mins_before_away")))) + + time_until_next_idle_event=IDLEMARK - time_idle; /* reasonable start upperbound */ + + if(auto_away || !no_away) + away_seconds=60 * purple_prefs_get_int("/purple/away/mins_before_away"); + + + if (auto_away && (time_idle > away_seconds)) { purple_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 * purple_prefs_get_int("/purple/away/mins_before_away")) + else if (!no_away && time_idle < away_seconds) { purple_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 */ @@ -178,9 +197,28 @@ check_idleness() 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=purple_timeout_add(1000 * (time_until_next_idle_event + 1), check_idleness_timer, NULL); + + return FALSE; +} + + static void im_msg_sent_cb(PurpleAccount *account, const char *receiver, const char *message, void *data) diff -purN pidgin-2.0.0-orig/pidgin/gtkidle.c pidgin-2.0.0/pidgin/gtkidle.c --- pidgin-2.0.0-orig/pidgin/gtkidle.c 2007-04-30 05:14:26.000000000 +0200 +++ pidgin-2.0.0/pidgin/gtkidle.c 2007-05-15 20:18:59.000000000 +0200 @@ -103,8 +103,15 @@ pidgin_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(); }