11907
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim is the legal property of its developers, whose names are too numerous
|
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
6 * source distribution.
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 */
|
|
23 #include "internal.h"
|
|
24
|
|
25 #ifdef USE_SCREENSAVER
|
|
26 # ifndef _WIN32
|
|
27 # include <X11/Xlib.h>
|
|
28 # include <X11/Xutil.h>
|
|
29 # include <X11/extensions/scrnsaver.h>
|
|
30 # include <gdk/gdkx.h>
|
|
31 # else
|
|
32 # include "idletrack.h"
|
|
33 # endif
|
|
34 #endif /* USE_SCREENSAVER */
|
|
35
|
12272
|
36 #include "idle.h"
|
11907
|
37
|
|
38 /**
|
|
39 * Get the number of seconds the user has been idle. In Unix-world
|
|
40 * this is based on the X Windows usage. In MS Windows this is based
|
|
41 * on keyboard/mouse usage.
|
|
42 *
|
|
43 * In Debian bug #271639, jwz says:
|
|
44 *
|
|
45 * Gaim should simply ask xscreensaver how long the user has been idle:
|
|
46 * % xscreensaver-command -time
|
|
47 * XScreenSaver 4.18: screen blanked since Tue Sep 14 14:10:45 2004
|
|
48 *
|
|
49 * Or you can monitor the _SCREENSAVER_STATUS property on root window #0.
|
|
50 * Element 0 is the status (0, BLANK, LOCK), element 1 is the time_t since
|
|
51 * the last state change, and subsequent elements are which hack is running
|
|
52 * on the various screens:
|
|
53 * % xprop -f _SCREENSAVER_STATUS 32ac -root _SCREENSAVER_STATUS
|
|
54 * _SCREENSAVER_STATUS(INTEGER) = BLANK, 1095196626, 10, 237
|
|
55 *
|
|
56 * See watch() in xscreensaver/driver/xscreensaver-command.c.
|
|
57 *
|
|
58 * @return The number of seconds the user has been idle.
|
|
59 */
|
12278
|
60 #ifdef USE_SCREENSAVER
|
12272
|
61 static time_t
|
|
62 gaim_gtk_get_time_idle()
|
11907
|
63 {
|
12272
|
64 # ifndef _WIN32
|
|
65 /* Query xscreensaver */
|
11907
|
66 static XScreenSaverInfo *mit_info = NULL;
|
|
67 int event_base, error_base;
|
|
68 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) {
|
|
69 if (mit_info == NULL) {
|
|
70 mit_info = XScreenSaverAllocInfo();
|
|
71 }
|
|
72 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info);
|
|
73 return (mit_info->idle) / 1000;
|
|
74 } else
|
|
75 return 0;
|
12272
|
76 # else
|
|
77 /* Query windows */
|
11907
|
78 return (GetTickCount() - wgaim_get_lastactive()) / 1000;
|
12272
|
79 # endif /* _WIN32 */
|
12278
|
80 }
|
11907
|
81 #endif /* USE_SCREENSAVER */
|
|
82
|
12272
|
83 static GaimIdleUiOps ui_ops =
|
11907
|
84 {
|
12278
|
85 #ifdef USE_SCREENSAVER
|
12272
|
86 gaim_gtk_get_time_idle
|
12278
|
87 #else
|
|
88 NULL
|
|
89 #endif /* USE_SCREENSAVER */
|
12272
|
90 };
|
11907
|
91
|
12272
|
92 GaimIdleUiOps *
|
|
93 gaim_gtk_idle_get_ui_ops()
|
11907
|
94 {
|
12272
|
95 return &ui_ops;
|
11907
|
96 }
|