annotate src/gtkidle.c @ 13830:0a1132e6eac4

[gaim-migrate @ 16279] SF Patch #1508370 from Sadrul "I had overlooked the changes that were necessary to behave properly when Escape is pressed in the per-account status selectors. This patch amends that." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 19 Jun 2006 04:48:50 +0000
parents 723f5b7ef6a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 /*
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 * gaim
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6 * source distribution.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 * (at your option) any later version.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 * GNU General Public License for more details.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 */
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
23 #include "internal.h"
12410
bc249de5ea02 [gaim-migrate @ 14717]
Richard Laager <rlaager@wiktel.com>
parents: 12278
diff changeset
24 #include "gtkidle.h"
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
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
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
43 #include "idle.h"
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
45 /**
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
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
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
52 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
53 * In Debian bug #271639, jwz says:
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
54 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55 * Gaim should simply ask xscreensaver how long the user has been idle:
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
56 * % xscreensaver-command -time
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
57 * XScreenSaver 4.18: screen blanked since Tue Sep 14 14:10:45 2004
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
59 * Or you can monitor the _SCREENSAVER_STATUS property on root window #0.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
60 * Element 0 is the status (0, BLANK, LOCK), element 1 is the time_t since
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 * the last state change, and subsequent elements are which hack is running
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62 * on the various screens:
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
63 * % xprop -f _SCREENSAVER_STATUS 32ac -root _SCREENSAVER_STATUS
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
64 * _SCREENSAVER_STATUS(INTEGER) = BLANK, 1095196626, 10, 237
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
65 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
66 * See watch() in xscreensaver/driver/xscreensaver-command.c.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
67 *
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
68 * @return The number of seconds the user has been idle.
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
69 */
13323
723f5b7ef6a2 [gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents: 12410
diff changeset
70 #if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT)
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
71 static time_t
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
72 gaim_gtk_get_time_idle()
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
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
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
104 /* Query xscreensaver */
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 static XScreenSaverInfo *mit_info = NULL;
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 int event_base, error_base;
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 if (XScreenSaverQueryExtension(GDK_DISPLAY(), &event_base, &error_base)) {
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 if (mit_info == NULL) {
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109 mit_info = XScreenSaverAllocInfo();
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 }
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 XScreenSaverQueryInfo(GDK_DISPLAY(), GDK_ROOT_WINDOW(), mit_info);
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 return (mit_info->idle) / 1000;
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 } else
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
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
25d7ef365dbf [gaim-migrate @ 14582]
Mark Doliner <mark@kingant.net>
parents: 12272
diff changeset
117 }
13323
723f5b7ef6a2 [gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents: 12410
diff changeset
118 #endif /* USE_SCREENSAVER || HAVE_IOKIT */
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
119
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
120 static GaimIdleUiOps ui_ops =
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
121 {
13323
723f5b7ef6a2 [gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents: 12410
diff changeset
122 #if defined(USE_SCREENSAVER) || defined(HAVE_IOKIT)
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
123 gaim_gtk_get_time_idle
12278
25d7ef365dbf [gaim-migrate @ 14582]
Mark Doliner <mark@kingant.net>
parents: 12272
diff changeset
124 #else
25d7ef365dbf [gaim-migrate @ 14582]
Mark Doliner <mark@kingant.net>
parents: 12272
diff changeset
125 NULL
13323
723f5b7ef6a2 [gaim-migrate @ 15693]
Richard Laager <rlaager@wiktel.com>
parents: 12410
diff changeset
126 #endif /* USE_SCREENSAVER || HAVE_IOKIT */
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
127 };
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
128
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
129 GaimIdleUiOps *
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
130 gaim_gtk_idle_get_ui_ops()
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
131 {
12272
3ef381cdc47e [gaim-migrate @ 14574]
Mark Doliner <mark@kingant.net>
parents: 12252
diff changeset
132 return &ui_ops;
11907
d2db6426c88a [gaim-migrate @ 14198]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
133 }