From 836434f1f05c201d413f0fcf94e8ba0b23641920 Mon Sep 17 00:00:00 2001 From: Richard Hestilow Date: Mon, 21 Jan 2002 22:44:12 +0000 Subject: [PATCH] Use nautilus as the shell if it is already running. 2002-01-21 Richard Hestilow * main.c: Use nautilus as the shell if it is already running. --- control-center/ChangeLog | 4 +++ control-center/main.c | 72 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/control-center/ChangeLog b/control-center/ChangeLog index a2331711f..b4f30ac77 100644 --- a/control-center/ChangeLog +++ b/control-center/ChangeLog @@ -1,3 +1,7 @@ +2002-01-21 Richard Hestilow + + * main.c: Use nautilus as the shell if it is already running. + 2002-01-17 Jakub Steiner * control-center.png: fix the antialiasing diff --git a/control-center/main.c b/control-center/main.c index 140ce3ef6..83a9515e6 100644 --- a/control-center/main.c +++ b/control-center/main.c @@ -29,10 +29,77 @@ #include #include #include +#include +#include +#include #include "capplet-dir.h" #include "capplet-dir-view.h" +static gboolean +is_nautilus_running (void) +{ + Atom window_id_atom; + Window nautilus_xid; + Atom actual_type; + int actual_format; + unsigned long nitems, bytes_after; + unsigned char *data; + int retval; + Atom wmclass_atom; + gboolean running; + gint error; + + window_id_atom = XInternAtom (GDK_DISPLAY (), + "NAUTILUS_DESKTOP_WINDOW_ID", True); + + if (window_id_atom == None) return FALSE; + + retval = XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (), + window_id_atom, 0, 1, False, XA_WINDOW, + &actual_type, &actual_format, &nitems, + &bytes_after, &data); + + if (data != NULL) { + nautilus_xid = *(Window *) data; + XFree (data); + } else { + return FALSE; + } + + if (actual_type != XA_WINDOW) return FALSE; + if (actual_format != 32) return FALSE; + + wmclass_atom = XInternAtom (GDK_DISPLAY (), "WM_CLASS", False); + + gdk_error_trap_push (); + + retval = XGetWindowProperty (GDK_DISPLAY (), nautilus_xid, + wmclass_atom, 0, 24, False, XA_STRING, + &actual_type, &actual_format, &nitems, + &bytes_after, &data); + + error = gdk_error_trap_pop (); + + if (error == BadWindow) return FALSE; + + if (actual_type == XA_STRING && + nitems == 24 && + bytes_after == 0 && + actual_format == 8 && + data != NULL && + !strcmp (data, "desktop_window") && + !strcmp (data + strlen (data) + 1, "Nautilus")) + running = TRUE; + else + running = FALSE; + + if (data != NULL) + XFree (data); + + return running; +} + int main (int argc, char **argv) { @@ -48,8 +115,9 @@ main (int argc, char **argv) GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR, NULL); - gconf_init (argc, argv, NULL); - + if (is_nautilus_running ()) + execlp ("nautilus", "nautilus", "preferences:///", NULL); + gnomecc_init (); dir = get_root_capplet_dir (); if (dir == NULL)