4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifdef USE_SCREENSAVER
31 #include <X11/Xutil.h>
32 #include <X11/extensions/scrnsaver.h>
34 #endif /* USE_SCREENSAVER */
41 gint
check_idle(gpointer data
)
43 struct gaim_connection
*gc
= data
;
45 #ifdef USE_SCREENSAVER
46 static XScreenSaverInfo
*mit_info
= NULL
;
50 /* Not idle, really... :) */
53 plugin_event(event_blist_update
, 0, 0, 0, 0);
58 #ifdef USE_SCREENSAVER
59 if (report_idle
== IDLE_SCREENSAVER
) {
60 int event_base
, error_base
;
61 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base
, &error_base
)) {
62 if (mit_info
== NULL
) {
63 mit_info
= XScreenSaverAllocInfo();
65 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info
);
66 idle_time
= (mit_info
->idle
) / 1000;
70 #endif /* USE_SCREENSAVER */
71 idle_time
= t
- gc
->lastsent
;
73 if ((away_options
& OPT_AWAY_AUTO
) && (idle_time
> (60 * auto_away
)) && (!gc
->is_auto_away
)) {
75 debug_printf("making %s away automatically\n", gc
->username
);
76 if (g_slist_length(connections
) == 1)
77 do_away_message(NULL
, default_away
);
78 else if (default_away
)
79 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, default_away
->message
);
81 set_default_away(NULL
, (gpointer
)g_slist_index(away_messages
, default_away
));
84 } else if (gc
->is_auto_away
&& idle_time
< 60 * auto_away
) {
85 if (gc
->is_auto_away
== 2) {
90 if (awaymessage
== NULL
) {
91 debug_printf("removing auto-away message for %s\n", gc
->username
);
92 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, NULL
);
94 if (g_slist_length(connections
) == 1)
97 debug_printf("replacing auto-away with global for %s\n", gc
->username
);
98 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, awaymessage
->message
);
104 /* If we're not reporting idle times to the server, still use Gaim
105 usage for auto-away, but quit here so we don't report to the
107 if (report_idle
== IDLE_NONE
) {
111 if (idle_time
> 600 && !gc
->is_idle
) { /* 10 minutes! */
112 debug_printf("setting %s idle %d seconds\n", gc
->username
, idle_time
);
113 serv_set_idle(gc
, idle_time
);
115 system_log(log_idle
, gc
, NULL
, OPT_LOG_BUDDY_IDLE
| OPT_LOG_MY_SIGNON
);
116 } else if (idle_time
< 600 && gc
->is_idle
) {
117 debug_printf("setting %s unidle\n", gc
->username
);
119 system_log(log_unidle
, gc
, NULL
, OPT_LOG_BUDDY_IDLE
| OPT_LOG_MY_SIGNON
);