Mercurial > pidgin.yaz
annotate src/gtkidle.c @ 14034:0839a7b71325
[gaim-migrate @ 16636]
Make Yahoo! packet parsing not allocate stuff twice. Who wrote this??
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 05 Aug 2006 05:42:28 +0000 |
parents | 723f5b7ef6a2 |
children |
rev | line source |
---|---|
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" | |
12410
bc249de5ea02
[gaim-migrate @ 14717]
Richard Laager <rlaager@wiktel.com>
parents:
12278
diff
changeset
|
24 #include "gtkidle.h" |
11907 | 25 |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
26 #ifdef HAVE_IOKIT |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
27 # include <CoreFoundation/CoreFoundation.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
28 # include <IOKit/IOKitLib.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
29 #else |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
30 # ifdef USE_SCREENSAVER |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
31 # ifdef _WIN32 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
32 # include "idletrack.h" |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
33 # else |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
34 /* We're on X11 and not MacOS X with IOKit. */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
35 # include <X11/Xlib.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
36 # include <X11/Xutil.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
37 # include <X11/extensions/scrnsaver.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
38 # include <gdk/gdkx.h> |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
39 # endif /* !_WIN32 */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
40 # endif /* USE_SCREENSAVER */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
41 #endif /* !HAVE_IOKIT */ |
11907 | 42 |
12272 | 43 #include "idle.h" |
11907 | 44 |
45 /** | |
46 * Get the number of seconds the user has been idle. In Unix-world | |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
47 * this is based on the X Windows usage. In MS Windows this is |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
48 * based on keyboard/mouse usage information obtained from the OS. |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
49 * In MacOS X, this is based on keyboard/mouse usage information |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
50 * obtained from the OS, if configure detected IOKit. Otherwise, |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
51 * MacOS X is handled as a case of X Windows. |
11907 | 52 * |
53 * In Debian bug #271639, jwz says: | |
54 * | |
55 * Gaim should simply ask xscreensaver how long the user has been idle: | |
56 * % xscreensaver-command -time | |
57 * XScreenSaver 4.18: screen blanked since Tue Sep 14 14:10:45 2004 | |
58 * | |
59 * Or you can monitor the _SCREENSAVER_STATUS property on root window #0. | |
60 * Element 0 is the status (0, BLANK, LOCK), element 1 is the time_t since | |
61 * the last state change, and subsequent elements are which hack is running | |
62 * on the various screens: | |
63 * % xprop -f _SCREENSAVER_STATUS 32ac -root _SCREENSAVER_STATUS | |
64 * _SCREENSAVER_STATUS(INTEGER) = BLANK, 1095196626, 10, 237 | |
65 * | |
66 * See watch() in xscreensaver/driver/xscreensaver-command.c. | |
67 * | |
68 * @return The number of seconds the user has been idle. | |
69 */ | |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
70 #if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT) |
12272 | 71 static time_t |
72 gaim_gtk_get_time_idle() | |
11907 | 73 { |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
74 # ifdef HAVE_IOKIT |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
75 /* Query the IOKit API */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
76 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
77 static io_service_t macIOsrvc = NULL; |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
78 CFTypeRef property; |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
79 uint64_t idle_time = 0; /* nanoseconds */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
80 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
81 if (macIOsrvc == NULL) |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
82 { |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
83 mach_port_t master; |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
84 IOMasterPort(MACH_PORT_NULL, &master); |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
85 macIOsrvc = IOServiceGetMatchingService(master, |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
86 IOServiceMatching("IOHIDSystem")); |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
87 } |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
88 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
89 property = IORegistryEntryCreateCFProperty(macIOsrvc, CFSTR("HIDIdleTime"), |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
90 kCFAllocatorDefault, 0); |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
91 CFNumberGetValue((CFNumberRef)property, |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
92 kCFNumberSInt64Type, &idle_time); |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
93 CFRelease(property); |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
94 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
95 /* convert nanoseconds to seconds */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
96 return idle_time / 1000000000; |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
97 # else |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
98 # ifdef _WIN32 |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
99 /* Query Windows */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
100 return (GetTickCount() - wgaim_get_lastactive()) / 1000; |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
101 # else |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
102 /* We're on X11 and not MacOS X with IOKit. */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
103 |
12272 | 104 /* Query xscreensaver */ |
11907 | 105 static XScreenSaverInfo *mit_info = NULL; |
106 int event_base, error_base; | |
107 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) { | |
108 if (mit_info == NULL) { | |
109 mit_info = XScreenSaverAllocInfo(); | |
110 } | |
111 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info); | |
112 return (mit_info->idle) / 1000; | |
113 } else | |
114 return 0; | |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
115 # endif /* !_WIN32 */ |
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
116 # endif /* !HAVE_IOKIT */ |
12278 | 117 } |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
118 #endif /* USE_SCREENSAVER || HAVE_IOKIT */ |
11907 | 119 |
12272 | 120 static GaimIdleUiOps ui_ops = |
11907 | 121 { |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
122 #if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT) |
12272 | 123 gaim_gtk_get_time_idle |
12278 | 124 #else |
125 NULL | |
13323
723f5b7ef6a2
[gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents:
12410
diff
changeset
|
126 #endif /* USE_SCREENSAVER || HAVE_IOKIT */ |
12272 | 127 }; |
11907 | 128 |
12272 | 129 GaimIdleUiOps * |
130 gaim_gtk_idle_get_ui_ops() | |
11907 | 131 { |
12272 | 132 return &ui_ops; |
11907 | 133 } |