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
32 #include <X11/Xutil.h>
33 #include <X11/extensions/scrnsaver.h>
36 #include "idletrack.h"
38 #endif /* USE_SCREENSAVER */
44 #define IDLEMARK 600 /* 10 minutes! */
46 gint
check_idle(gpointer data
)
48 struct gaim_connection
*gc
= data
;
50 #ifdef USE_SCREENSAVER
52 static XScreenSaverInfo
*mit_info
= NULL
;
57 plugin_event(event_blist_update
);
62 #ifdef USE_SCREENSAVER
63 if (report_idle
== IDLE_SCREENSAVER
) {
65 int event_base
, error_base
;
66 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base
, &error_base
)) {
67 if (mit_info
== NULL
) {
68 mit_info
= XScreenSaverAllocInfo();
70 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info
);
71 idle_time
= (mit_info
->idle
) / 1000;
75 idle_time
= (GetTickCount() - wgaim_get_lastactive()) / 1000;
78 #endif /* USE_SCREENSAVER */
79 idle_time
= t
- gc
->lastsent
;
81 if ((away_options
& OPT_AWAY_AUTO
) && (idle_time
> (60 * auto_away
)) && (!gc
->is_auto_away
)) {
83 debug_printf("making %s away automatically\n", gc
->username
);
84 if (g_slist_length(connections
) == 1)
85 do_away_message(NULL
, default_away
);
86 else if (default_away
)
87 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, default_away
->message
);
89 set_default_away(NULL
, (gpointer
)g_slist_index(away_messages
, default_away
));
92 } else if (gc
->is_auto_away
&& idle_time
< 60 * auto_away
) {
93 if (gc
->is_auto_away
== 2) {
98 if (awaymessage
== NULL
) {
99 debug_printf("removing auto-away message for %s\n", gc
->username
);
100 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, NULL
);
102 if (g_slist_length(connections
) == 1)
105 debug_printf("replacing auto-away with global for %s\n", gc
->username
);
106 serv_set_away(gc
, GAIM_AWAY_CUSTOM
, awaymessage
->message
);
112 /* If we're not reporting idle times to the server, still use Gaim
113 usage for auto-away, but quit here so we don't report to the
115 if (report_idle
== IDLE_NONE
) {
119 if (idle_time
>= IDLEMARK
&& !gc
->is_idle
) {
120 debug_printf("setting %s idle %d seconds\n", gc
->username
, idle_time
);
121 serv_set_idle(gc
, idle_time
);
123 system_log(log_idle
, gc
, NULL
, OPT_LOG_BUDDY_IDLE
| OPT_LOG_MY_SIGNON
);
124 } else if (idle_time
< IDLEMARK
&& gc
->is_idle
) {
125 debug_printf("setting %s unidle\n", gc
->username
);
127 system_log(log_unidle
, gc
, NULL
, OPT_LOG_BUDDY_IDLE
| OPT_LOG_MY_SIGNON
);