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