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
|
|
30 #include <stdio.h>
|
|
31 #include <stdlib.h>
|
|
32 #include <unistd.h>
|
|
33 #include <string.h>
|
|
34
|
|
35
|
|
36
|
|
37
|
|
38 #include <gtk/gtk.h>
|
|
39 #include <gdk/gdkprivate.h>
|
|
40 #include <gdk/gdkx.h>
|
|
41 #include "gaim.h"
|
|
42
|
|
43 #ifndef _WIN32
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48 #include <X11/Xlib.h>
|
|
49 #include <X11/Xatom.h>
|
|
50
|
|
51
|
|
52 static const char *progname = "gaim";
|
|
53 static const char *expected_mozilla_version = "1.1";
|
|
54
|
|
55 #define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
|
|
56 #define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
|
|
57 #define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND"
|
|
58 #define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
|
|
59
|
|
60 static GdkAtom XA_MOZILLA_VERSION = 0;
|
|
61 static GdkAtom XA_MOZILLA_LOCK = 0;
|
|
62 static GdkAtom XA_MOZILLA_COMMAND = 0;
|
|
63 static GdkAtom XA_MOZILLA_RESPONSE = 0;
|
|
64
|
|
65
|
|
66 static int netscape_lock;
|
|
67
|
|
68
|
|
69 static Window
|
|
70 VirtualRootWindowOfScreen(screen)
|
|
71 Screen *screen;
|
|
72 {
|
|
73 static Screen *save_screen = (Screen *)0;
|
|
74 static Window root = (Window)0;
|
|
75
|
|
76 if (screen != save_screen) {
|
|
77 Display *dpy = DisplayOfScreen(screen);
|
|
78 Atom __SWM_VROOT = None;
|
79
|
79 unsigned int i;
|
1
|
80 Window rootReturn, parentReturn, *children;
|
|
81 unsigned int numChildren;
|
|
82
|
|
83 root = RootWindowOfScreen(screen);
|
|
84
|
|
85 /* go look for a virtual root */
|
|
86 __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
|
|
87 if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
|
|
88 &children, &numChildren)) {
|
|
89 for (i = 0; i < numChildren; i++) {
|
|
90 Atom actual_type;
|
|
91 int actual_format;
|
|
92 unsigned long nitems, bytesafter;
|
|
93 Window *newRoot = (Window *)0;
|
|
94
|
|
95 if (XGetWindowProperty(dpy, children[i],
|
|
96 __SWM_VROOT, 0, 1, False, XA_WINDOW,
|
|
97 &actual_type, &actual_format,
|
|
98 &nitems, &bytesafter,
|
|
99 (unsigned char **) &newRoot) == Success
|
|
100 && newRoot) {
|
|
101 root = *newRoot;
|
|
102 break;
|
|
103 }
|
|
104 }
|
|
105 if (children)
|
|
106 XFree((char *)children);
|
|
107 }
|
|
108
|
|
109 save_screen = screen;
|
|
110 }
|
|
111
|
|
112 return root;
|
|
113 }
|
|
114
|
|
115 /* The following code is Copyright (C) 1989 X Consortium */
|
|
116
|
|
117 static Window TryChildren();
|
|
118
|
|
119 /* Find a window with WM_STATE, else return win itself, as per ICCCM */
|
|
120
|
|
121 static Window GClientWindow (dpy, win)
|
|
122 Display *dpy;
|
|
123 Window win;
|
|
124 {
|
|
125 Atom WM_STATE;
|
|
126 Atom type = None;
|
|
127 int format;
|
|
128 unsigned long nitems, after;
|
|
129 unsigned char *data;
|
|
130 Window inf;
|
|
131
|
|
132 WM_STATE = XInternAtom(dpy, "WM_STATE", True);
|
|
133 if (!WM_STATE)
|
|
134 return win;
|
|
135 XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
|
|
136 &type, &format, &nitems, &after, &data);
|
|
137 if (type)
|
26
|
138 {
|
|
139 XFree(data);
|
|
140 return win;
|
|
141 }
|
|
142
|
1
|
143 inf = TryChildren(dpy, win, WM_STATE);
|
|
144 if (!inf)
|
|
145 inf = win;
|
26
|
146
|
|
147 XFree(data);
|
|
148
|
1
|
149 return inf;
|
|
150 }
|
|
151
|
|
152 static
|
|
153 Window TryChildren (dpy, win, WM_STATE)
|
|
154 Display *dpy;
|
|
155 Window win;
|
|
156 Atom WM_STATE;
|
|
157 {
|
|
158 Window root, parent;
|
|
159 Window *children;
|
|
160 unsigned int nchildren;
|
|
161 unsigned int i;
|
|
162 Atom type = None;
|
|
163 int format;
|
|
164 unsigned long nitems, after;
|
|
165 unsigned char *data;
|
|
166 Window inf = 0;
|
|
167
|
|
168 if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren))
|
|
169 return 0;
|
|
170 for (i = 0; !inf && (i < nchildren); i++) {
|
|
171 XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False,
|
|
172 AnyPropertyType, &type, &format, &nitems,
|
|
173 &after, &data);
|
|
174 if (type)
|
|
175 inf = children[i];
|
26
|
176
|
|
177 XFree(data);
|
1
|
178 }
|
|
179 for (i = 0; !inf && (i < nchildren); i++)
|
|
180 inf = TryChildren(dpy, children[i], WM_STATE);
|
|
181 if (children) XFree((char *)children);
|
|
182 return inf;
|
|
183 }
|
|
184
|
|
185 /* END X Consortium code */
|
|
186
|
|
187
|
|
188
|
|
189 static void mozilla_remote_init_atoms()
|
|
190 {
|
|
191 if (!XA_MOZILLA_VERSION)
|
|
192 XA_MOZILLA_VERSION = gdk_atom_intern(MOZILLA_VERSION_PROP, 0);
|
|
193 if (!XA_MOZILLA_LOCK)
|
|
194 XA_MOZILLA_LOCK = gdk_atom_intern(MOZILLA_LOCK_PROP, 0);
|
|
195 if (! XA_MOZILLA_COMMAND)
|
|
196 XA_MOZILLA_COMMAND = gdk_atom_intern(MOZILLA_COMMAND_PROP, 0);
|
|
197 if (! XA_MOZILLA_RESPONSE)
|
|
198 XA_MOZILLA_RESPONSE = gdk_atom_intern(MOZILLA_RESPONSE_PROP, 0);
|
|
199 }
|
|
200
|
|
201 static GdkWindow *mozilla_remote_find_window()
|
|
202 {
|
|
203 int i;
|
|
204 Window root = VirtualRootWindowOfScreen(DefaultScreenOfDisplay(gdk_display));
|
|
205 Window root2, parent, *kids;
|
|
206 unsigned int nkids;
|
|
207 Window result = 0;
|
|
208 Window tenative = 0;
|
|
209 unsigned char *tenative_version = 0;
|
|
210
|
|
211 if (!XQueryTree (gdk_display, root, &root2, &parent, &kids, &nkids))
|
|
212 {
|
|
213 sprintf (debug_buff, "%s: XQueryTree failed on display %s\n", progname,
|
|
214 DisplayString (gdk_display));
|
|
215 debug_print(debug_buff);
|
|
216 return NULL;
|
|
217 }
|
|
218
|
|
219 /* root != root2 is possible with virtual root WMs. */
|
|
220
|
|
221 if (!(kids && nkids)) {
|
|
222 sprintf (debug_buff, "%s: root window has no children on display %s\n",
|
|
223 progname, DisplayString (gdk_display));
|
26
|
224 debug_print(debug_buff);
|
1
|
225 return NULL;
|
|
226 }
|
|
227
|
|
228 for (i = nkids-1; i >= 0; i--)
|
|
229 {
|
|
230 Atom type;
|
|
231 int format;
|
|
232 unsigned long nitems, bytesafter;
|
|
233 unsigned char *version = 0;
|
|
234 Window w = GClientWindow (gdk_display, kids[i]);
|
|
235 int status = XGetWindowProperty (gdk_display, w, XA_MOZILLA_VERSION,
|
|
236 0, (65536 / sizeof (long)),
|
|
237 False, XA_STRING,
|
|
238 &type, &format, &nitems, &bytesafter,
|
|
239 &version);
|
26
|
240
|
1
|
241 if (! version)
|
|
242 continue;
|
26
|
243
|
1
|
244 if (strcmp ((char *) version, expected_mozilla_version) &&
|
|
245 !tenative)
|
|
246 {
|
|
247 tenative = w;
|
|
248 tenative_version = version;
|
|
249 continue;
|
|
250 }
|
26
|
251 XFree(version);
|
1
|
252 if (status == Success && type != None)
|
|
253 {
|
|
254 result = w;
|
|
255 break;
|
|
256 }
|
|
257 }
|
|
258
|
26
|
259 XFree(kids);
|
|
260
|
1
|
261 if (result && tenative)
|
|
262 {
|
|
263 sprintf (debug_buff,
|
|
264 "%s: warning: both version %s (0x%x) and version\n"
|
|
265 "\t%s (0x%x) are running. Using version %s.\n",
|
|
266 progname, tenative_version, (unsigned int) tenative,
|
|
267 expected_mozilla_version, (unsigned int) result,
|
|
268 expected_mozilla_version);
|
|
269 debug_print(debug_buff);
|
26
|
270 XFree(tenative_version);
|
1
|
271 return gdk_window_foreign_new(result);
|
|
272 }
|
|
273 else if (tenative)
|
|
274 {
|
|
275 sprintf (debug_buff,
|
|
276 "%s: warning: expected version %s but found version\n"
|
|
277 "\t%s (0x%x) instead.\n",
|
|
278 progname, expected_mozilla_version,
|
|
279 tenative_version, (unsigned int) tenative);
|
|
280 debug_print(debug_buff);
|
26
|
281 XFree(tenative_version);
|
1
|
282 return gdk_window_foreign_new(tenative);
|
|
283 }
|
|
284 else if (result)
|
|
285 {
|
|
286 return gdk_window_foreign_new(result);
|
|
287 }
|
|
288 else
|
|
289 {
|
|
290 sprintf (debug_buff, "%s: not running on display %s\n", progname,
|
|
291 DisplayString (gdk_display));
|
|
292 debug_print(debug_buff);
|
|
293 return NULL;
|
|
294 }
|
|
295 }
|
|
296
|
|
297
|
|
298 static char *lock_data = 0;
|
|
299
|
|
300 static void mozilla_remote_obtain_lock (GdkWindow *window)
|
|
301 {
|
|
302 Bool locked = False;
|
|
303
|
|
304 if (!lock_data) {
|
|
305 lock_data = (char *)g_malloc (255);
|
|
306 sprintf (lock_data, "pid%d@", getpid ());
|
|
307 if (gethostname (lock_data + strlen (lock_data), 100)) {
|
|
308 return;
|
|
309 }
|
|
310 }
|
|
311
|
|
312 do {
|
|
313 int result;
|
|
314 GdkAtom actual_type;
|
|
315 gint actual_format;
|
|
316 gint nitems;
|
|
317 unsigned char *data = 0;
|
|
318
|
|
319 result = gdk_property_get (window, XA_MOZILLA_LOCK,
|
|
320 XA_STRING, 0,
|
|
321 (65536 / sizeof (long)), 0,
|
|
322 &actual_type, &actual_format,
|
|
323 &nitems, &data);
|
|
324 if (result != Success || actual_type == None)
|
|
325 {
|
|
326 /* It's not now locked - lock it. */
|
|
327 sprintf (debug_buff, "%s: (writing " MOZILLA_LOCK_PROP
|
|
328 " \"%s\" to 0x%x)\n",
|
|
329 progname, lock_data, (unsigned int) window);
|
|
330 debug_print(debug_buff);
|
|
331
|
|
332 gdk_property_change(window, XA_MOZILLA_LOCK, XA_STRING,
|
|
333 8, PropModeReplace,
|
|
334 (unsigned char *) lock_data,
|
|
335 strlen (lock_data));
|
|
336 locked = True;
|
|
337 }
|
|
338
|
|
339 if (!locked) {
|
|
340 /* Then just fuck it. */
|
|
341 if (data)
|
|
342 g_free(data);
|
|
343 return;
|
|
344 }
|
|
345 if (data)
|
|
346 g_free(data);
|
|
347 } while (!locked);
|
|
348 }
|
|
349
|
|
350
|
|
351 static void mozilla_remote_free_lock (GdkWindow *window)
|
|
352 {
|
|
353 int result = 0;
|
|
354 GdkAtom actual_type;
|
|
355 gint actual_format;
|
|
356 gint nitems;
|
|
357 unsigned char *data = 0;
|
|
358
|
|
359 sprintf (debug_buff, "%s: (deleting " MOZILLA_LOCK_PROP
|
|
360 " \"%s\" from 0x%x)\n",
|
|
361 progname, lock_data, (unsigned int) window);
|
|
362 debug_print(debug_buff);
|
|
363
|
|
364 result = gdk_property_get(window, XA_MOZILLA_LOCK, XA_STRING,
|
|
365 0, (65536 / sizeof (long)),
|
|
366 1, &actual_type, &actual_format,
|
|
367 &nitems, &data);
|
|
368 if (result != Success)
|
|
369 {
|
|
370 sprintf (debug_buff, "%s: unable to read and delete " MOZILLA_LOCK_PROP
|
|
371 " property\n",
|
|
372 progname);
|
|
373 debug_print(debug_buff);
|
|
374 return;
|
|
375 }
|
|
376 else if (!data || !*data)
|
|
377 {
|
|
378 sprintf (debug_buff, "%s: invalid data on " MOZILLA_LOCK_PROP
|
|
379 " of window 0x%x.\n",
|
|
380 progname, (unsigned int) window);
|
|
381 debug_print(debug_buff);
|
|
382 return;
|
|
383 }
|
|
384 else if (strcmp ((char *) data, lock_data))
|
|
385 {
|
|
386 sprintf (debug_buff, "%s: " MOZILLA_LOCK_PROP
|
|
387 " was stolen! Expected \"%s\", saw \"%s\"!\n",
|
|
388 progname, lock_data, data);
|
|
389 debug_print(debug_buff);
|
|
390 return;
|
|
391 }
|
|
392
|
|
393 if (data)
|
|
394 g_free(data);
|
|
395 }
|
|
396
|
|
397
|
|
398 static int
|
|
399 mozilla_remote_command (GdkWindow *window, const char *command,
|
|
400 Bool raise_p)
|
|
401 {
|
|
402 int result = 0;
|
|
403 Bool done = False;
|
|
404 char *new_command = 0;
|
|
405
|
|
406 /* The -noraise option is implemented by passing a "noraise" argument
|
|
407 to each command to which it should apply.
|
|
408 */
|
|
409 if (!raise_p)
|
|
410 {
|
|
411 char *close;
|
79
|
412 new_command = g_malloc (strlen (command) + 20);
|
1
|
413 strcpy (new_command, command);
|
|
414 close = strrchr (new_command, ')');
|
|
415 if (close)
|
|
416 strcpy (close, ", noraise)");
|
|
417 else
|
|
418 strcat (new_command, "(noraise)");
|
|
419 command = new_command;
|
|
420 }
|
|
421
|
|
422 sprintf (debug_buff, "%s: (writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
|
|
423 progname, command, (unsigned int) window);
|
|
424 debug_print(debug_buff);
|
|
425
|
|
426 gdk_property_change(window, XA_MOZILLA_COMMAND, XA_STRING, 8,
|
|
427 GDK_PROP_MODE_REPLACE, (unsigned char *) command,
|
|
428 strlen (command));
|
|
429
|
|
430 while (!done) {
|
|
431 GdkEvent *event;
|
|
432
|
|
433 event = gdk_event_get();
|
|
434
|
|
435 if (!event)
|
|
436 continue;
|
|
437
|
|
438 if (event->any.window != window) {
|
|
439 gtk_main_do_event(event);
|
|
440 continue;
|
|
441 }
|
|
442
|
|
443 if (event->type == GDK_DESTROY &&
|
|
444 event->any.window == window) {
|
|
445
|
|
446 /* Print to warn user...*/
|
|
447 sprintf (debug_buff, "%s: window 0x%x was destroyed.\n",
|
|
448 progname, (unsigned int) window);
|
|
449 debug_print(debug_buff);
|
|
450 result = 6;
|
|
451 goto DONE;
|
|
452 } else if (event->type == GDK_PROPERTY_NOTIFY &&
|
|
453 event->property.state == GDK_PROPERTY_NEW_VALUE &&
|
|
454 event->property.window == window &&
|
|
455 event->property.atom == XA_MOZILLA_RESPONSE) {
|
|
456 GdkAtom actual_type;
|
|
457 gint actual_format, nitems;
|
|
458 unsigned char *data = 0;
|
|
459
|
|
460 result = gdk_property_get (window, XA_MOZILLA_RESPONSE,
|
|
461 XA_STRING, 0,
|
|
462 (65536 / sizeof (long)),
|
|
463 1,
|
|
464 &actual_type, &actual_format,
|
|
465 &nitems, &data);
|
|
466
|
|
467
|
|
468 if (result == Success && data && *data) {
|
|
469 sprintf (debug_buff, "%s: (server sent " MOZILLA_RESPONSE_PROP
|
|
470 " \"%s\" to 0x%x.)\n",
|
|
471 progname, data, (unsigned int) window);
|
|
472 debug_print(debug_buff);
|
|
473 }
|
|
474
|
|
475 if (result != Success) {
|
|
476 sprintf (debug_buff, "%s: failed reading " MOZILLA_RESPONSE_PROP
|
|
477 " from window 0x%0x.\n",
|
|
478 progname, (unsigned int) window);
|
|
479 debug_print(debug_buff);
|
|
480 result = 6;
|
|
481 done = True;
|
|
482 } else if (!data || strlen((char *) data) < 5) {
|
|
483 sprintf (debug_buff, "%s: invalid data on " MOZILLA_RESPONSE_PROP
|
|
484 " property of window 0x%0x.\n",
|
|
485 progname, (unsigned int) window);
|
|
486 debug_print(debug_buff);
|
|
487 result = 6;
|
|
488 done = True;
|
|
489 } else if (*data == '1') { /* positive preliminary reply */
|
|
490 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
491 debug_print(debug_buff);
|
|
492 /* keep going */
|
|
493 done = False;
|
|
494 } else if (!strncmp ((char *)data, "200", 3)) {
|
|
495 result = 0;
|
|
496 done = True;
|
|
497 } else if (*data == '2') {
|
|
498 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
499 debug_print(debug_buff);
|
|
500 result = 0;
|
|
501 done = True;
|
|
502 } else if (*data == '3') {
|
|
503 sprintf (debug_buff, "%s: internal error: "
|
|
504 "server wants more information? (%s)\n",
|
|
505 progname, data);
|
|
506 debug_print(debug_buff);
|
|
507 result = 3;
|
|
508 done = True;
|
|
509 } else if (*data == '4' || *data == '5') {
|
|
510 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
511 debug_print(debug_buff);
|
|
512 result = (*data - '0');
|
|
513 done = True;
|
|
514 } else {
|
|
515 sprintf (debug_buff,
|
|
516 "%s: unrecognised " MOZILLA_RESPONSE_PROP
|
|
517 " from window 0x%x: %s\n",
|
|
518 progname, (unsigned int) window, data);
|
|
519 debug_print(debug_buff);
|
|
520 result = 6;
|
|
521 done = True;
|
|
522 }
|
|
523
|
|
524 if (data)
|
|
525 g_free(data);
|
|
526 }
|
|
527 else if (event->type == GDK_PROPERTY_NOTIFY &&
|
|
528 event->property.window == window &&
|
|
529 event->property.state == GDK_PROPERTY_DELETE &&
|
|
530 event->property.atom == XA_MOZILLA_COMMAND) {
|
|
531 sprintf (debug_buff, "%s: (server 0x%x has accepted "
|
|
532 MOZILLA_COMMAND_PROP ".)\n",
|
|
533 progname, (unsigned int) window);
|
|
534 debug_print(debug_buff);
|
|
535 }
|
|
536 gdk_event_free(event);
|
|
537 }
|
|
538
|
|
539 DONE:
|
|
540
|
|
541 if (new_command)
|
|
542 g_free (new_command);
|
|
543
|
|
544 return result;
|
|
545 }
|
|
546
|
|
547
|
|
548 gint check_netscape(char *msg)
|
|
549 {
|
|
550 int status;
|
|
551 GdkWindow *window;
|
|
552
|
|
553 mozilla_remote_init_atoms ();
|
|
554 window = mozilla_remote_find_window();
|
|
555
|
|
556 if (window) {
|
|
557
|
|
558 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
|
|
559 (PropertyChangeMask|StructureNotifyMask));
|
|
560
|
|
561
|
|
562 mozilla_remote_obtain_lock(window);
|
|
563
|
|
564 status = mozilla_remote_command(window, msg, False);
|
|
565
|
|
566 if (status != 6)
|
|
567 mozilla_remote_free_lock(window);
|
|
568
|
|
569 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
570
|
|
571 netscape_lock = 0;
|
|
572
|
|
573 g_free(msg);
|
|
574 return FALSE;
|
|
575 } else
|
|
576 return TRUE;
|
|
577 }
|
|
578
|
|
579
|
|
580 static void netscape_command(char *command)
|
|
581 {
|
|
582 int status;
|
|
583 pid_t pid;
|
|
584 GdkWindow *window;
|
|
585
|
|
586 if (netscape_lock)
|
|
587 return;
|
|
588
|
|
589 netscape_lock = 1;
|
|
590
|
|
591
|
|
592
|
|
593 mozilla_remote_init_atoms();
|
|
594 window = mozilla_remote_find_window();
|
|
595
|
|
596 if (window) {
|
|
597
|
|
598 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
|
|
599 (PropertyChangeMask|StructureNotifyMask));
|
|
600
|
|
601 mozilla_remote_obtain_lock(window);
|
|
602
|
|
603 status = mozilla_remote_command(window, command, False);
|
|
604
|
|
605 if (status != 6)
|
|
606 mozilla_remote_free_lock(window);
|
|
607
|
|
608 netscape_lock = 0;
|
|
609
|
26
|
610 gdk_window_destroy (window);
|
1
|
611 } else {
|
|
612 pid = fork();
|
|
613 if (pid == 0) {
|
|
614 char *args[2];
|
|
615 int e;
|
|
616
|
|
617 args[0] = g_strdup("netscape");
|
|
618 args[1] = NULL;
|
|
619 e = execvp(args[0], args);
|
79
|
620 printf("Hello%d\n", getppid());
|
1
|
621
|
|
622 _exit(0);
|
|
623 } else {
|
|
624 char *tmp = g_strdup(command);
|
|
625 gtk_timeout_add(200, (GtkFunction)check_netscape, tmp);
|
|
626 }
|
|
627 }
|
|
628
|
|
629 }
|
|
630
|
|
631 void open_url(GtkWidget *w, char *url) {
|
|
632 if (web_browser == BROWSER_NETSCAPE) {
|
|
633 char *command = g_malloc(1024);
|
|
634
|
|
635 g_snprintf(command, 1024, "OpenURL(%s)", url);
|
|
636
|
|
637 netscape_command(command);
|
|
638 g_free(command);
|
|
639 } else if (web_browser == BROWSER_KFM) {
|
|
640 pid_t pid;
|
|
641
|
|
642 pid = fork();
|
|
643
|
|
644 if (pid == 0) {
|
|
645 char *args[4];
|
|
646
|
|
647 args[0] = g_strdup("kfmclient");
|
|
648 args[1] = g_strdup("openURL");
|
|
649 args[2] = url;;
|
|
650 args[3] = NULL;
|
|
651
|
|
652 execvp(args[0], args);
|
|
653 _exit(0);
|
|
654 } else {
|
|
655 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
656 }
|
|
657 } else if (web_browser == BROWSER_MANUAL) {
|
|
658 pid_t pid;
|
|
659
|
|
660 pid = fork();
|
|
661
|
|
662 if (pid == 0) {
|
|
663 char *args[4];
|
|
664
|
|
665 char command[1024];
|
|
666
|
|
667 g_snprintf(command, sizeof(command), web_command, url);
|
|
668
|
|
669 args[0] = "sh";
|
|
670 args[1] = "-c";
|
|
671 args[2] = command;
|
|
672 args[3] = NULL;
|
|
673
|
|
674 execvp(args[0], args);
|
|
675
|
|
676 _exit(0);
|
|
677 } else {
|
|
678 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
679 }
|
|
680 } else if (web_browser == BROWSER_INTERNAL) {
|
|
681 g_show_info(url);
|
|
682 }
|
|
683 }
|
|
684
|
|
685 void add_bookmark(GtkWidget *w, char *url) {
|
|
686 if (web_browser == BROWSER_NETSCAPE) {
|
|
687 char *command = g_malloc(1024);
|
|
688
|
|
689 g_snprintf(command, 1024, "AddBookmark(%s)", url);
|
|
690
|
|
691 netscape_command(command);
|
|
692 g_free(command);
|
|
693 }
|
|
694 }
|
|
695
|
|
696 void open_url_nw(GtkWidget *w, char *url) {
|
|
697 if (web_browser == BROWSER_NETSCAPE) {
|
|
698 char *command = g_malloc(1024);
|
|
699
|
|
700 g_snprintf(command, 1024, "OpenURL(%s, new-window)", url);
|
|
701
|
|
702 netscape_command(command);
|
|
703 g_free(command);
|
|
704 }
|
|
705 }
|
|
706
|
|
707 #else
|
|
708
|
|
709 /* Sooner or later, I shall support Windows clicking! */
|
|
710
|
|
711 void add_bookmark(GtkWidget *w, char *url) { }
|
|
712 void open_url_nw(GtkWidget *w, char *url) { }
|
|
713 void open_url(GtkWidget *w, char *url) { }
|
|
714
|
|
715
|
|
716 #endif _WIN32
|