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