Mercurial > pidgin
annotate src/browser.c @ 5864:417b1001d2b1
[gaim-migrate @ 6295]
Rewrote the pounce API again. Now it's even MORE core/UI-split, and will
allow for loading/saving.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 14 Jun 2003 11:14:49 +0000 |
parents | b7319c094153 |
children | 059d95c67cda |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * some code: (most in this file) | |
7 * Copyright (C) 1996 Netscape Communications Corporation, all rights reserved. | |
8 * Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 * This code is mainly taken from Netscape's sample implementation of | |
25 * their protocol. Nifty. | |
26 * | |
27 */ | |
28 | |
29 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
30 #ifdef HAVE_CONFIG_H |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2077
diff
changeset
|
31 #include <config.h> |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
32 #endif |
3630 | 33 #ifdef _WIN32 |
34 #include <gdk/gdkwin32.h> | |
35 #else | |
36 #include <unistd.h> | |
4428 | 37 #ifndef HOST_NAME_MAX |
38 #define HOST_NAME_MAX 255 | |
39 #endif | |
3630 | 40 #include <gdk/gdkx.h> |
41 #endif | |
1 | 42 #include <stdio.h> |
43 #include <stdlib.h> | |
44 #include <string.h> | |
45 | |
46 | |
47 | |
48 | |
49 #include <gtk/gtk.h> | |
50 #include <gdk/gdkprivate.h> | |
51 #include "gaim.h" | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
52 #include "notify.h" |
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5515
diff
changeset
|
53 #include "prefs.h" |
1 | 54 |
55 #ifndef _WIN32 | |
56 | |
57 | |
58 | |
59 | |
60 #include <X11/Xlib.h> | |
61 #include <X11/Xatom.h> | |
62 | |
63 | |
64 static const char *progname = "gaim"; | |
65 static const char *expected_mozilla_version = "1.1"; | |
66 | |
67 #define MOZILLA_VERSION_PROP "_MOZILLA_VERSION" | |
68 #define MOZILLA_LOCK_PROP "_MOZILLA_LOCK" | |
69 #define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND" | |
70 #define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE" | |
71 | |
3466 | 72 static GdkAtom GDKA_MOZILLA_VERSION = 0; |
73 static GdkAtom GDKA_MOZILLA_LOCK = 0; | |
74 static GdkAtom GDKA_MOZILLA_COMMAND = 0; | |
75 static GdkAtom GDKA_MOZILLA_RESPONSE = 0; | |
1 | 76 |
4428 | 77 static char *window_check_mozilla_version(Window); |
78 static const char *get_lock_data(); | |
79 static GdkFilterReturn netscape_response_cb(XEvent *, GdkEvent *, GdkWindow *); | |
80 static gboolean netscape_command(const char *); | |
1 | 81 |
82 static int netscape_lock; | |
83 | |
84 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
85 static Window VirtualRootWindowOfScreen(screen) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
86 Screen *screen; |
1 | 87 { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
88 static Screen *save_screen = (Screen *) 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
89 static Window root = (Window) 0; |
1 | 90 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
91 if (screen != save_screen) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
92 Display *dpy = DisplayOfScreen(screen); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
93 Atom __SWM_VROOT = None; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
94 unsigned int i; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
95 Window rootReturn, parentReturn, *children; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
96 unsigned int numChildren; |
1 | 97 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
98 root = RootWindowOfScreen(screen); |
1 | 99 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
100 /* go look for a virtual root */ |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
101 __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
102 if (XQueryTree(dpy, root, &rootReturn, &parentReturn, &children, &numChildren)) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
103 for (i = 0; i < numChildren; i++) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
104 Atom actual_type; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
105 int actual_format; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
106 unsigned long nitems, bytesafter; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
107 Window *newRoot = (Window *) 0; |
1 | 108 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
109 if (XGetWindowProperty(dpy, children[i], |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
110 __SWM_VROOT, 0, 1, False, XA_WINDOW, |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
111 &actual_type, &actual_format, |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
112 &nitems, &bytesafter, |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2099
diff
changeset
|
113 (unsigned char **)&newRoot) == Success |
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2099
diff
changeset
|
114 && newRoot) { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
115 root = *newRoot; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
116 break; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
117 } |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
118 } |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
119 if (children) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
120 XFree((char *)children); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
121 } |
1 | 122 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
123 save_screen = screen; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
124 } |
1 | 125 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
126 return root; |
1 | 127 } |
128 | |
129 /* The following code is Copyright (C) 1989 X Consortium */ | |
130 | |
131 static Window TryChildren(); | |
132 | |
133 /* Find a window with WM_STATE, else return win itself, as per ICCCM */ | |
134 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
135 static Window GClientWindow(dpy, win) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
136 Display *dpy; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
137 Window win; |
1 | 138 { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
139 Atom WM_STATE; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
140 Atom type = None; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
141 int format; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
142 unsigned long nitems, after; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
143 unsigned char *data; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
144 Window inf; |
1 | 145 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
146 WM_STATE = XInternAtom(dpy, "WM_STATE", True); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
147 if (!WM_STATE) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
148 return win; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
149 XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType, |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
150 &type, &format, &nitems, &after, &data); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
151 if (type) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
152 XFree(data); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
153 return win; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
154 } |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
155 |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
156 inf = TryChildren(dpy, win, WM_STATE); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
157 if (!inf) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
158 inf = win; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
159 |
26 | 160 XFree(data); |
161 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
162 return inf; |
1 | 163 } |
164 | |
165 static | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
166 Window TryChildren(dpy, win, WM_STATE) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
167 Display *dpy; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
168 Window win; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
169 Atom WM_STATE; |
1 | 170 { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
171 Window root, parent; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
172 Window *children; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
173 unsigned int nchildren; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
174 unsigned int i; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
175 Atom type = None; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
176 int format; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
177 unsigned long nitems, after; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
178 unsigned char *data; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
179 Window inf = 0; |
1 | 180 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
181 if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren)) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
182 return 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
183 for (i = 0; !inf && (i < nchildren); i++) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
184 XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False, |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
185 AnyPropertyType, &type, &format, &nitems, &after, &data); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
186 if (type) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
187 inf = children[i]; |
26 | 188 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
189 XFree(data); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
190 } |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
191 for (i = 0; !inf && (i < nchildren); i++) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
192 inf = TryChildren(dpy, children[i], WM_STATE); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
193 if (children) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
194 XFree((char *)children); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
195 return inf; |
1 | 196 } |
197 | |
198 /* END X Consortium code */ | |
199 | |
200 | |
201 | |
202 static void mozilla_remote_init_atoms() | |
203 { | |
3466 | 204 if (!GDKA_MOZILLA_VERSION) |
205 GDKA_MOZILLA_VERSION = gdk_atom_intern(MOZILLA_VERSION_PROP, 0); | |
206 if (!GDKA_MOZILLA_LOCK) | |
207 GDKA_MOZILLA_LOCK = gdk_atom_intern(MOZILLA_LOCK_PROP, 0); | |
208 if (!GDKA_MOZILLA_COMMAND) | |
209 GDKA_MOZILLA_COMMAND = gdk_atom_intern(MOZILLA_COMMAND_PROP, 0); | |
210 if (!GDKA_MOZILLA_RESPONSE) | |
211 GDKA_MOZILLA_RESPONSE = gdk_atom_intern(MOZILLA_RESPONSE_PROP, 0); | |
1 | 212 } |
213 | |
4428 | 214 static char *window_check_mozilla_version(Window window) { |
215 | |
216 Atom type; | |
217 int format; | |
218 unsigned long nitems, bytesafter; | |
219 unsigned char *version = 0; | |
220 gchar *retval = NULL; | |
221 | |
222 if (XGetWindowProperty(gdk_display, window, | |
223 gdk_x11_atom_to_xatom(GDKA_MOZILLA_VERSION), | |
224 0, (65536 / sizeof(long)), | |
225 False, XA_STRING, | |
226 &type, &format, &nitems, &bytesafter, | |
227 &version) != Success) { | |
228 return NULL; | |
229 } | |
230 | |
231 if (!version) { | |
232 return NULL; | |
233 } | |
234 | |
235 retval = g_strdup(version); | |
236 XFree(version); | |
237 | |
238 return retval; | |
239 } | |
240 | |
1 | 241 static GdkWindow *mozilla_remote_find_window() |
242 { | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
243 int i; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
244 Window root = VirtualRootWindowOfScreen(DefaultScreenOfDisplay(gdk_display)); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
245 Window root2, parent, *kids; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
246 unsigned int nkids; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
247 Window result = 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
248 Window tenative = 0; |
4428 | 249 unsigned char *tenative_version = 0, *version = 0; |
250 static GdkWindow *remote_window = NULL; | |
251 | |
252 if (remote_window != NULL) { | |
253 version = window_check_mozilla_version(GDK_WINDOW_XID(remote_window)); | |
254 | |
255 if (version != NULL) { | |
256 g_free(version); | |
257 return remote_window; | |
258 } | |
259 g_free(version); | |
260 | |
261 gdk_window_destroy(remote_window); | |
262 remote_window = NULL; | |
263 } | |
1 | 264 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
265 if (!XQueryTree(gdk_display, root, &root2, &parent, &kids, &nkids)) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
266 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
267 "%s: XQueryTree failed on display %s\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
268 progname, DisplayString(gdk_display)); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
269 return NULL; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
270 } |
1 | 271 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
272 /* root != root2 is possible with virtual root WMs. */ |
1 | 273 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
274 if (!(kids && nkids)) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
275 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
276 "%s: root window has no children on display %s\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
277 progname, DisplayString(gdk_display)); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
278 return NULL; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
279 } |
1 | 280 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
281 for (i = nkids - 1; i >= 0; i--) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
282 Window w = GClientWindow(gdk_display, kids[i]); |
4428 | 283 |
284 version = window_check_mozilla_version(w); | |
26 | 285 |
4428 | 286 if (version == NULL) { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
287 continue; |
4428 | 288 } |
26 | 289 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
290 if (strcmp((char *)version, expected_mozilla_version) && !tenative) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
291 tenative = w; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
292 tenative_version = version; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
293 continue; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
294 } |
4428 | 295 |
296 g_free(version); | |
297 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
298 result = w; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
299 break; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
300 } |
1 | 301 |
26 | 302 XFree(kids); |
303 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
304 if (result && tenative) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
305 gaim_debug(GAIM_DEBUG_WARNING, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
306 "%s: both version %s (0x%x) and version %s (%0x%x) " |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
307 "are running. Using version %s.\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
308 progname, tenative_version, (unsigned int)tenative, |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
309 expected_mozilla_version, (unsigned int)result, |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
310 expected_mozilla_version); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
311 XFree(tenative_version); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
312 return gdk_window_foreign_new(result); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
313 } else if (tenative) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
314 gaim_debug(GAIM_DEBUG_WARNING, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
315 "%s: expected version %s but found version %s (0x%x) " |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
316 "instead.\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
317 progname, expected_mozilla_version, |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
318 tenative_version, (unsigned int)tenative); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
319 XFree(tenative_version); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
320 return gdk_window_foreign_new(tenative); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
321 } else if (result) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
322 return gdk_window_foreign_new(result); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
323 } else { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
324 gaim_debug(GAIM_DEBUG_ERROR, "%s: not running on display %s\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
325 progname, DisplayString(gdk_display)); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
326 return NULL; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
327 } |
1 | 328 } |
329 | |
330 | |
4428 | 331 static const char *get_lock_data() { |
332 static char *lock_data = NULL; | |
1 | 333 |
4428 | 334 if (lock_data == NULL) { |
335 char hostname[HOST_NAME_MAX + 1] = {0}; | |
336 | |
337 if (gethostname(hostname, HOST_NAME_MAX + 1) == 0) { | |
338 lock_data = g_strdup_printf("pid%d@%s", getpid(), hostname); | |
339 } else { | |
340 lock_data = g_strdup_printf("pid%d", getpid()); | |
1 | 341 } |
342 } | |
343 | |
4428 | 344 return lock_data; |
345 } | |
346 | |
5435 | 347 #if 0 |
4551 | 348 static void mozilla_remote_obtain_lock(GdkWindow * window) |
4428 | 349 { |
350 gboolean locked = False; | |
351 const char *lock_data = get_lock_data(); | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
352 GdkAtom actual_type; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
353 gint actual_format; |
1 | 354 gint nitems; |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
355 unsigned char *data = 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
356 |
4428 | 357 gdk_x11_grab_server(); |
358 if (!gdk_property_get(window, GDKA_MOZILLA_LOCK, | |
3466 | 359 gdk_x11_xatom_to_atom (XA_STRING), 0, |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
360 (65536 / sizeof(long)), 0, |
4428 | 361 &actual_type, &actual_format, &nitems, &data)) { |
362 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
363 /* It's not now locked - lock it. */ |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
364 gaim_debug(GAIM_DEBUG_MISC, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
365 "%s: writing " MOZILLA_LOCK_PROP " \"%s\" to 0x%x\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
366 progname, lock_data, (unsigned int)window); |
1 | 367 |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
368 gdk_property_change(window, GDKA_MOZILLA_LOCK, |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
369 gdk_x11_xatom_to_atom (XA_STRING), |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
370 8, PropModeReplace, |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
371 (unsigned char *)lock_data, strlen(lock_data)); |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
372 locked = True; |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
373 } |
1 | 374 |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
375 if (data) |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
376 g_free(data); |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
377 |
4428 | 378 gdk_x11_ungrab_server(); |
1 | 379 } |
5435 | 380 #endif |
1 | 381 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
382 static void mozilla_remote_free_lock(GdkWindow * window) |
1 | 383 { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
384 int result = 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
385 GdkAtom actual_type; |
4428 | 386 gint actual_format; |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
387 gint nitems; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
388 unsigned char *data = 0; |
4428 | 389 const char *lock_data = get_lock_data(); |
1 | 390 |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
391 gaim_debug(GAIM_DEBUG_MISC, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
392 "%s: deleting " MOZILLA_LOCK_PROP " \"%s\" from 0x%x\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
393 progname, lock_data, (unsigned int)window); |
1 | 394 |
3466 | 395 result = gdk_property_get(window, GDKA_MOZILLA_LOCK, |
396 gdk_x11_xatom_to_atom (XA_STRING), | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
397 0, (65536 / sizeof(long)), |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
398 1, &actual_type, &actual_format, &nitems, &data); |
4428 | 399 |
400 if (result != TRUE) { | |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
401 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
402 "%s: Unable to read and delete " MOZILLA_LOCK_PROP |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
403 " property\n", progname); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
404 return; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
405 } else if (!data || !*data) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
406 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
407 "%s: Invalid data on " MOZILLA_LOCK_PROP |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
408 " of wnidow 0x%x\n", progname, (unsigned int)window); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
409 return; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
410 } else if (strcmp((char *)data, lock_data)) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
411 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
412 "%s: " MOZILLA_LOCK_PROP " was stolen! Expected \"%s\", " |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
413 "saw \"%s\"!\n", progname, lock_data, data); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
414 return; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
415 } |
1 | 416 |
4428 | 417 XFree(data); |
1 | 418 } |
419 | |
4428 | 420 static GdkFilterReturn netscape_response_cb(XEvent *event, GdkEvent *translated, GdkWindow *window) |
421 { | |
422 Atom actual_type, mozilla_response; | |
423 Window xid; | |
424 int actual_format; | |
425 unsigned long nitems, bytes_after; | |
426 unsigned char *data = 0; | |
1 | 427 |
4428 | 428 if (window == NULL || GDK_WINDOW_OBJECT(window)->destroyed) { |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
429 gaim_notify_error(NULL, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
430 _("Communication with the browser failed. " |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
431 "Please close all windows and try again."), NULL); |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
432 gaim_debug(GAIM_DEBUG_WARNING, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
433 "netscape_response_cb called with NULL window.\n"); |
4428 | 434 return GDK_FILTER_CONTINUE; |
435 } | |
436 | |
437 mozilla_response = gdk_x11_atom_to_xatom(GDKA_MOZILLA_RESPONSE); | |
438 xid = GDK_WINDOW_XID(window); | |
439 | |
440 /* If the event isn't what we want then let gtk handle it */ | |
441 if (event->xany.type != PropertyNotify || | |
442 event->xproperty.state != PropertyNewValue || | |
443 event->xproperty.window != xid || | |
444 event->xproperty.atom != mozilla_response) { | |
445 return GDK_FILTER_CONTINUE; | |
446 } | |
447 | |
448 if (XGetWindowProperty (gdk_display, xid, mozilla_response, | |
449 0, (65536 / sizeof (long)), | |
450 True, | |
451 XA_STRING, | |
452 &actual_type, &actual_format, | |
453 &nitems, &bytes_after, | |
454 &data) != Success | |
455 || data == NULL || (data[0] != '1' && data[0] != '2')) { | |
456 | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
457 gaim_notify_error(NULL, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
458 _("Communication with the browser failed. " |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
459 "Please close all windows and try again."), NULL); |
4428 | 460 } |
461 | |
462 if (data[0] == '1') { | |
463 /* Netscape isn't ready yet */ | |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
464 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
465 "Remote Netscape window isn't ready yet.\n"); |
4428 | 466 return GDK_FILTER_REMOVE; |
467 } | |
468 | |
469 if (data[0] == '2') { | |
470 /* Yay! It worked */ | |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
471 gaim_debug(GAIM_DEBUG_INFO, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
472 "Successfully sent command to remote Netscape window.\n"); |
4428 | 473 } |
474 | |
475 gdk_window_remove_filter(window, (GdkFilterFunc) netscape_response_cb, window); | |
476 mozilla_remote_free_lock(window); | |
477 netscape_lock = 0; | |
478 return GDK_FILTER_REMOVE; | |
479 } | |
480 | |
481 static void mozilla_remote_command(GdkWindow * window, const char *command, Bool raise_p) | |
1 | 482 { |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
483 char *new_command = 0; |
1 | 484 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
485 /* The -noraise option is implemented by passing a "noraise" argument |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
486 to each command to which it should apply. |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
487 */ |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
488 if (!raise_p) { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
489 char *close; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
490 new_command = g_malloc(strlen(command) + 20); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
491 strcpy(new_command, command); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
492 close = strrchr(new_command, ')'); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
493 if (close) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
494 strcpy(close, ", noraise)"); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
495 else |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
496 strcat(new_command, "(noraise)"); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
497 command = new_command; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
498 } |
1 | 499 |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
500 gaim_debug(GAIM_DEBUG_MISC, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
501 "%s: Writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x\n", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
502 progname, command, (unsigned int)window); |
1 | 503 |
3466 | 504 gdk_property_change(window, GDKA_MOZILLA_COMMAND, |
505 gdk_x11_xatom_to_atom (XA_STRING), | |
506 8, GDK_PROP_MODE_REPLACE, (unsigned char *)command, strlen(command)); | |
1 | 507 |
4431 | 508 gdk_window_add_filter(window, (GdkFilterFunc) netscape_response_cb, window); |
509 } | |
4430 | 510 |
4431 | 511 static gboolean netscape_command(const char *command) |
512 { | |
513 GdkWindow *window = NULL; | |
514 | |
515 if (netscape_lock) { | |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
516 gaim_debug(GAIM_DEBUG_WARNING, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
517 "netscape_command() is currently in use.\n"); |
4431 | 518 return FALSE; |
4430 | 519 } |
520 | |
4431 | 521 netscape_lock = 1; |
1 | 522 |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
523 mozilla_remote_init_atoms(); |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
524 window = mozilla_remote_find_window(); |
1 | 525 |
4431 | 526 if (window == NULL || (GDK_WINDOW_OBJECT(window)->destroyed == TRUE)) { |
5213
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
527 gaim_debug(GAIM_DEBUG_ERROR, "browser", |
1cf4eb75e3ee
[gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents:
4885
diff
changeset
|
528 "Remote window absent or unsuitable.\n"); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
529 netscape_lock = 0; |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
530 return FALSE; |
1 | 531 } |
532 | |
4431 | 533 mozilla_remote_command(window, command, False); |
534 | |
535 netscape_lock = 0; | |
536 return TRUE; | |
1 | 537 } |
538 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
539 void open_url(GtkWidget *w, char *url) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
540 { |
4431 | 541 char *command = NULL; |
542 GError *error = NULL; | |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
543 const char *web_browser; |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
544 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
545 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); |
4551 | 546 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
547 if (!strcmp(web_browser, "netscape")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
548 char *args = NULL; |
4551 | 549 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
550 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
551 args = g_strdup_printf("OpenURL(%s, new-window)", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
552 else |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
553 args = g_strdup_printf("OpenURL(%s)", url); |
4431 | 554 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
555 if (netscape_command(args)) { |
4431 | 556 g_free(args); |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
557 return; |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
558 } |
4431 | 559 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
560 /* if netscape is running ... |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
561 command = g_strdup_printf("netscape -remote %s", args); */ |
4551 | 562 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
563 command = g_strdup_printf("netscape \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
564 g_free(args); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
565 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
566 else if (!strcmp(web_browser, "opera")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
567 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
568 command = g_strdup_printf("opera -newwindow \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
569 else |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
570 command = g_strdup_printf("opera \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
571 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
572 else if (!strcmp(web_browser, "kfmclient")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
573 command = g_strdup_printf("kfmclient openURL \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
574 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
575 else if (!strcmp(web_browser, "galeon")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
576 if (gaim_prefs_get_bool("/gaim/gtk/browsers/new_window")) |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
577 command = g_strdup_printf("galeon -w \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
578 else |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
579 command = g_strdup_printf("galeon \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
580 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
581 else if (!strcmp(web_browser, "mozilla")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
582 command = g_strdup_printf("mozilla \"%s\"", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
583 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
584 else if (!strcmp(web_browser, "custom")) { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
585 const char *web_command; |
4431 | 586 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
587 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
588 web_command = gaim_prefs_get_string("/gaim/gtk/browsers/command"); |
4431 | 589 |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
590 if (web_command == NULL || *web_command == '\0') { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
591 gaim_notify_error(NULL, NULL, |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
592 _("Unable to launch your browser because " |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
593 "the 'Manual' browser command has been " |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
594 "chosen, but no command has been set."), |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
595 NULL); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
596 return; |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
597 } |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
598 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
599 if (strstr(web_command, "%s")) |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
600 command = gaim_strreplace(web_command, "%s", url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
601 else { |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
602 /* There is no "%s" in the browser command. Assume the user |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
603 * wanted the URL tacked on to the end of the command. */ |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
604 command = g_strdup_printf("%s %s", web_command, url); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
605 } |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
606 } |
4431 | 607 |
608 if (g_spawn_command_line_async(command, &error) == FALSE) { | |
609 char *tmp = g_strdup_printf(_("There was an error launching your chosen browser: %s"), error->message); | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
610 gaim_notify_error(NULL, NULL, tmp, NULL); |
4431 | 611 g_free(tmp); |
612 g_error_free(error); | |
613 } | |
614 | |
615 g_free(command); | |
1 | 616 } |
617 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
618 void add_bookmark(GtkWidget *w, char *url) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
619 { |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
620 const char *web_browser; |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
621 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
622 web_browser = gaim_prefs_get_string("/gaim/gtk/browsers/browser"); |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
623 |
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
624 if (!strcmp(web_browser, "netscape")) { |
4431 | 625 char *command = g_strdup_printf("AddBookmark(%s)", url); |
1 | 626 |
627 netscape_command(command); | |
628 g_free(command); | |
629 } | |
630 } | |
631 | |
5560
b7319c094153
[gaim-migrate @ 5961]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
632 #else /* _WIN32 */ |
1 | 633 |
634 /* Sooner or later, I shall support Windows clicking! */ | |
635 | |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
636 void add_bookmark(GtkWidget *w, char *url) |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
637 { |
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
638 } |
3630 | 639 void open_url(GtkWidget *w, char *url) |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
640 { |
3630 | 641 ShellExecute(NULL, NULL, url, NULL, ".\\", 0); |
1250
b5783215b245
[gaim-migrate @ 1260]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1181
diff
changeset
|
642 } |
1 | 643 |
2372
2927c2c26fe6
[gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2099
diff
changeset
|
644 #endif /* _WIN32 */ |