=== modified file 'Makefile.am'
--- Makefile.am	
+++ Makefile.am	
@@ -1,5 +1,5 @@
 
-SUBDIRS=src po help
+SUBDIRS= libguniqueapp src po help
 
 DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper
 
=== modified file 'configure.in'
--- configure.in	
+++ configure.in	
@@ -83,6 +83,33 @@ else
    using_xft2=no
 fi
 
+
+GTK_RECCOMENDED=2.12.0
+DBUS_GLIB_REQUIRED=0.33
+
+if $PKG_CONFIG --atleast-version $GTK_RECCOMENDED gtk+-2.0; then
+   have_recent_gtk=yes
+else
+   have_recent_gtk=no
+   AC_DEFINE(OLDER_GTK_VERSION, , [Building with GTK+ older than 2.12]) 
+fi
+
+if $PKG_CONFIG --atleast-version $DBUS_GLIB_REQUIRED dbus-glib-1; then
+   have_dbus=yes
+   PKG_CHECK_MODULES(DBUS, dbus-glib-1 >= $DBUS_GLIB_REQUIRED)
+   AC_SUBST(DBUS_CFLAGS)
+   AC_SUBST(DBUS_LIBS)
+   AC_DEFINE(HAVE_DBUS, , [Building with DBus support]) 
+   AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool)
+else
+   have_dbus=no
+fi
+
+AM_CONDITIONAL([HAVE_DBUS], [test $have_dbus = yes])
+
+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+
+
 GNOME_DOC_INIT
 
 AC_CONFIG_FILES([
@@ -90,6 +117,7 @@ Makefile
 gnome-terminal.desktop.in
 src/Makefile
 src/skey/Makefile
+libguniqueapp/Makefile
 help/Makefile
 help/bg/Makefile
 help/ro/Makefile
=== modified file 'src/Makefile.am'
--- src/Makefile.am	
+++ src/Makefile.am	
@@ -13,7 +13,8 @@ INCLUDES=@TERM_CFLAGS@ \
 	-DTERM_SYSCONFDIR=\"$(sysconfdir)\" \
 	-DTERM_PKGDATADIR=\"$(pkgdatadir)\" \
 	-DGDK_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED	\
-	-DSN_API_NOT_YET_FROZEN
+	-DSN_API_NOT_YET_FROZEN \
+	-I../libguniqueapp
 #	-DGTK_DISABLE_DEPRECATED 
 #	-DGNOME_DISABLE_DEPRECATED 
 
@@ -52,7 +53,11 @@ gnome_terminal_SOURCES=				\
 	simple-x-font-selector.h		\
 	$(EGGFILES)
 
-gnome_terminal_LDADD= $(EFENCE) @TERM_LIBS@ skey/libskey.la
+gnome_terminal_LDADD= $(EFENCE) @TERM_LIBS@ skey/libskey.la ../libguniqueapp/libguniqueapp.la
+
+if HAVE_DBUS
+gnome_terminal_LDADD += @DBUS_LIBS@
+endif
 
 gladedir   = $(pkgdatadir)/glade
 glade_DATA = gnome-terminal.glade2
=== modified file 'src/terminal-window.c'
--- src/terminal-window.c	
+++ src/terminal-window.c	
@@ -74,7 +74,6 @@ struct _TerminalWindowPrivate
   void *old_geometry_widget; /* only used for pointer value as it may be freed */
   GConfClient *conf;
   guint notify_id;
-  char *startup_id;
   guint menubar_visible : 1;
   guint use_default_menubar_visibility : 1;
   guint use_mnemonics : 1;   /* config key value */
@@ -235,8 +234,6 @@ static gboolean find_larger_zoom_factor 
 static gboolean find_smaller_zoom_factor (double  current,
                                           double *found);
 
-static void terminal_window_show (GtkWidget *widget);
-
 static gboolean confirm_close_window (TerminalWindow *window);
 
 static gpointer parent_class;
@@ -1124,7 +1121,7 @@ terminal_window_class_init (TerminalWind
   
   object_class->finalize = terminal_window_finalize;
   gtk_object_class->destroy = terminal_window_destroy;
-  widget_class->show = terminal_window_show;
+  //widget_class->show = terminal_window_show;
 }
 
 static void
@@ -1143,8 +1140,6 @@ terminal_window_finalize (GObject *objec
   
   if (window->priv->icon)
     g_object_unref (G_OBJECT (window->priv->icon));
-
-  g_free (window->priv->startup_id);
   
   g_free (window->priv);
   
@@ -1199,70 +1194,6 @@ sn_error_trap_pop (SnDisplay *display,
   gdk_error_trap_pop ();
 }
 
-static void
-terminal_window_show (GtkWidget *widget)
-{
-  TerminalWindow *window;
-  SnDisplay *sn_display;
-  SnLauncheeContext *context;
-  GdkScreen *screen;
-  GdkDisplay *display;
-  
-  window = TERMINAL_WINDOW (widget);
-
-  if (!GTK_WIDGET_REALIZED (widget))
-    gtk_widget_realize (widget);
-  
-  context = NULL;
-  sn_display = NULL;
-  if (window->priv->startup_id != NULL)
-    {
-      /* Set up window for launch notification */
-      /* FIXME In principle all transient children of this
-       * window should get the same startup_id
-       */
-      
-      screen = gtk_window_get_screen (GTK_WINDOW (window));
-      display = gdk_screen_get_display (screen);
-      
-      sn_display = sn_display_new (gdk_x11_display_get_xdisplay (display),
-                                   sn_error_trap_push,
-                                   sn_error_trap_pop);
-      
-      context = sn_launchee_context_new (sn_display,
-                                         gdk_screen_get_number (screen),
-                                         window->priv->startup_id);
-
-      /* Handle the setup for the window if the startup_id is valid; I
-       * don't think it can hurt to do this even if it was invalid,
-       * but why do the extra work...
-       */
-      if (strncmp (sn_launchee_context_get_startup_id (context), "_TIME", 5) != 0)
-        sn_launchee_context_setup_window (context,
-                                          GDK_WINDOW_XWINDOW (widget->window));
-
-      /* Now, set the _NET_WM_USER_TIME for the new window to the timestamp
-       * that caused the window to be launched.
-       */
-      if (sn_launchee_context_get_id_has_timestamp (context))
-        {
-          gulong timestamp;
-
-          timestamp = sn_launchee_context_get_timestamp (context);
-          gdk_x11_window_set_user_time (widget->window, timestamp);
-        }
-    }
-  
-  GTK_WIDGET_CLASS (parent_class)->show (widget);
-
-  if (context != NULL)
-    {
-      sn_launchee_context_complete (context);
-      sn_launchee_context_unref (context);
-      sn_display_unref (sn_display);
-    }
-}
-
 void terminal_window_realized_callback (GtkWidget *window,
                                         gpointer   user_data)
 {
@@ -2937,11 +2868,3 @@ terminal_window_reread_profile_list (Ter
   fill_in_config_picker_submenu (window);
   fill_in_new_term_submenus (window);
 }
-
-void
-terminal_window_set_startup_id (TerminalWindow *window,
-                                const char     *startup_id)
-{
-  g_free (window->priv->startup_id);
-  window->priv->startup_id = g_strdup (startup_id);
-}
=== modified file 'src/terminal.c'
--- src/terminal.c	
+++ src/terminal.c	
@@ -30,14 +30,11 @@
 #include "profile-editor.h"
 #include "encoding.h"
 #include <gconf/gconf-client.h>
-#include <bonobo-activation/bonobo-activation-activate.h>
-#include <bonobo-activation/bonobo-activation-register.h>
-#include <bonobo/bonobo-exception.h>
-#include <bonobo/bonobo-listener.h>
 #include <libgnome/gnome-program.h>
 #include <libgnome/gnome-help.h>
 #include <libgnomeui/gnome-ui-init.h>
 #include <libgnomeui/gnome-client.h>
+#include <guniqueapp.h>
 #include <popt.h>
 #include <string.h>
 #include <stdlib.h>
@@ -83,6 +80,7 @@ struct _TerminalApp
 
 static GConfClient *conf = NULL;
 static TerminalApp *app = NULL;
+static GUniqueApp *uniqueapp = NULL;
 static gboolean terminal_factory_disabled = FALSE;
 static gboolean initialization_complete = FALSE;
 static GSList *pending_new_terminal_events = NULL;
@@ -131,7 +129,7 @@ static gboolean save_yourself_callback (
                                         gboolean            fast,
                                         void               *data);
 
-static gboolean terminal_invoke_factory (int argc, char **argv);
+static gboolean terminal_invoke_factory (gchar* startup_id, char **argv);
 static void option_parsing_results_free (OptionParsingResults *results);
 
 
@@ -1514,57 +1512,6 @@ insert_args (int        *argc,
   argv[*argc] = NULL;
 }
 
-/* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
- * we have no DESKTOP_STARTUP_ID (with its accompanying timestamp).
- */
-static Time
-slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
-{
-  Window xwindow;
-  XEvent event;
-
-  {
-    XSetWindowAttributes attrs;
-    Atom atom_name;
-    Atom atom_type;
-    char *name;
-
-    attrs.override_redirect = True;
-    attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
-
-    xwindow =
-      XCreateWindow (xdisplay,
-		     RootWindow (xdisplay, 0),
-		     -100, -100, 1, 1,
-		     0,
-		     CopyFromParent,
-		     CopyFromParent,
-		     CopyFromParent,
-		     CWOverrideRedirect | CWEventMask,
-		     &attrs);
-
-    atom_name = XInternAtom (xdisplay, "WM_NAME", TRUE);
-    g_assert (atom_name != None);
-    atom_type = XInternAtom (xdisplay, "STRING", TRUE);
-    g_assert (atom_type != None);
-
-    name = "Fake Window";
-    XChangeProperty (xdisplay, 
-		     xwindow, atom_name,
-		     atom_type,
-		     8, PropModeReplace, (unsigned char *)name, strlen (name));
-  }
-
-  XWindowEvent (xdisplay,
-		xwindow,
-		PropertyChangeMask,
-		&event);
-
-  XDestroyWindow(xdisplay, xwindow);
-
-  return event.xproperty.time;
-}
-
 int
 main (int argc, char **argv)
 {
@@ -1574,7 +1521,7 @@ main (int argc, char **argv)
   int argc_copy;
   char **argv_copy;
   const char **args;
-  const char *startup_id;
+  gchar *startup_id = NULL;
   const char *display_name;
   GdkDisplay *display;
   GnomeModuleRequirement reqs[] = {
@@ -1612,29 +1559,13 @@ main (int argc, char **argv)
   argv_copy [i] = NULL;
 
   results = option_parsing_results_init (&argc, argv);
-  startup_id = g_getenv ("DESKTOP_STARTUP_ID");
-  if (startup_id != NULL && *startup_id != '\0')
-    {
-      results->startup_id = g_strdup (startup_id);
-      putenv ("DESKTOP_STARTUP_ID=");
-    }
-  
-  gtk_window_set_auto_startup_notification (FALSE); /* we'll do it ourselves due
-                                                     * to complicated factory setup
-                                                     */
   
+#ifdef OLDER_GTK_VERSION
+  startup_id = g_getenv ("DESKTOP_STARTUP_ID");
+#endif
+      
   gtk_init (&argc, &argv);
 
-  /* Do this here so that gdk_display is initialized */
-  if (results->startup_id == NULL)
-    {
-      /* Create a fake one containing a timestamp that we can use */
-      Time timestamp;
-      timestamp = slowly_and_stupidly_obtain_timestamp (gdk_display);
-      results->startup_id = g_strdup_printf ("_TIME%lu",
-                                             timestamp);
-    }
-
   g_set_application_name (_("Terminal"));
   
   display = gdk_display_get_default ();
@@ -1680,13 +1611,6 @@ main (int argc, char **argv)
   if (!terminal_factory_disabled)
     {
       char *cwd;
-      
-      if (results->startup_id != NULL)
-        {
-          /* we allocated argv_copy with extra space so we could do this */
-          insert_args (&argc_copy, argv_copy,
-                       "--startup-id", results->startup_id);
-        }
 
       /* Forward our display to the child */
       insert_args (&argc_copy, argv_copy,
@@ -1698,7 +1622,7 @@ main (int argc, char **argv)
                    "--default-working-directory", cwd);
       g_free (cwd);
 
-      if (terminal_invoke_factory (argc_copy, argv_copy))
+      if (terminal_invoke_factory (startup_id, argv_copy))
         {
           g_strfreev (argv_copy);
           option_parsing_results_free (results);
@@ -1929,7 +1853,7 @@ terminal_app_new_terminal (TerminalApp  
         }
 
       if (startup_id != NULL)
-        terminal_window_set_startup_id (window, startup_id);
+        gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
       
       if (role == NULL)
         terminal_util_set_unique_role (GTK_WINDOW (window), "gnome-terminal");
@@ -3752,124 +3676,60 @@ handle_new_terminal_events (void)
  * given arguments.
  */
 static void
-terminal_new_event (BonoboListener    *listener,
-		    const char        *event_name, 
-		    const CORBA_any   *any,
-		    CORBA_Environment *ev,
-		    gpointer           user_data)
-{
-  CORBA_sequence_CORBA_string *args;
-  char **tmp_argv;
-  int tmp_argc;
-  int i;
+terminal_new_event (GUniqueApp *app,
+                    GUniqueAppCommand command,
+                    gchar* data,
+                    gchar* startup_id,
+                    guint workspace,
+                    gpointer user_data)
+{
   NewTerminalEvent *event;
+  gint i;
   
-  if (strcmp (event_name, "new_terminal"))
-    {
-      g_warning ("Unknown event '%s' on terminal",
-		 event_name);
-      return;
-    }
-
-  args = any->_value;
+  /* A light hack to blend with existing infrastructure */
+  gchar** argv = g_strsplit (data, "\v", 0);
+  gint argc_copy = g_strv_length (argv);
   
-  tmp_argv = g_new0 (char*, args->_length + 1);
-  i = 0;
-  while (i < args->_length)
-    {
-      tmp_argv[i] = g_strdup (((const char**)args->_buffer)[i]);
-      ++i;
-    }
-  tmp_argv[i] = NULL;
-  tmp_argc = i;
+  gchar** argv_copy = g_new0 (char *, argc_copy + 3);
+  
+  for (i = 0; i < argc_copy; i++)
+    argv_copy [i] = g_strdup (argv [i]);
+  argv_copy [i] = NULL;
+  
+  g_strfreev (argv);
+  
+  insert_args (&argc_copy, argv_copy, "--startup-id", startup_id);
 
   event = g_new0 (NewTerminalEvent, 1);
-  event->argc = tmp_argc;
-  event->argv = tmp_argv;
+  event->argc = argc_copy;
+  event->argv = argv_copy;
 
   pending_new_terminal_events = g_slist_append (pending_new_terminal_events,
                                                 event);
-
   if (initialization_complete)
     handle_new_terminal_events ();
 }
 
-#define ACT_IID "OAFIID:GNOME_Terminal_Factory"
-
-static Bonobo_RegistrationResult
-terminal_register_as_factory (void)
-{
-  char *per_display_iid;
-  BonoboListener *listener;
-  Bonobo_RegistrationResult result;
-
-  listener = bonobo_listener_new (terminal_new_event, NULL);
-
-  per_display_iid = bonobo_activation_make_registration_id (
-    ACT_IID, DisplayString (gdk_display));
-
-  result = bonobo_activation_active_server_register (
-    per_display_iid, BONOBO_OBJREF (listener));
-
-  if (result != Bonobo_ACTIVATION_REG_SUCCESS)
-    bonobo_object_unref (BONOBO_OBJECT (listener));
-
-  g_free (per_display_iid);
-
-  return result;
-}
-
 static gboolean
-terminal_invoke_factory (int argc, char **argv)
+terminal_invoke_factory (gchar* startup_id, char **argv)
 {
-  Bonobo_Listener listener;
-
-  switch (terminal_register_as_factory ())
-    {
-      case Bonobo_ACTIVATION_REG_SUCCESS:
-	/* we were the first terminal to register */
-	return FALSE;
-      case Bonobo_ACTIVATION_REG_NOT_LISTED:
-	g_printerr (_("It appears that you do not have gnome-terminal.server installed in a valid location. Factory mode disabled.\n"));
-        return FALSE;
-      case Bonobo_ACTIVATION_REG_ERROR:
-        g_printerr (_("Error registering terminal with the activation service; factory mode disabled.\n"));
-        return FALSE;
-      case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
-        /* lets use it then */
-        break;
-    }
-
-  listener = bonobo_activation_activate_from_id (
-    ACT_IID, Bonobo_ACTIVATION_FLAG_EXISTING_ONLY, NULL, NULL);
-
-  if (listener != CORBA_OBJECT_NIL)
+  uniqueapp = g_unique_app_get_with_startup_id ("gnome-terminal", startup_id);
+  
+  if (g_unique_app_is_running (uniqueapp))
     {
-      int i;
-      CORBA_any any;
-      CORBA_sequence_CORBA_string args;
-      CORBA_Environment ev;
-
-      CORBA_exception_init (&ev);
-
-      any._type = TC_CORBA_sequence_CORBA_string;
-      any._value = &args;
-
-      args._length = argc;
-      args._buffer = g_newa (CORBA_char *, args._length);
-
-      for (i = 0; i < args._length; i++)
-        args._buffer [i] = argv [i];
+      gchar* data = g_strjoinv ("\v", argv);
+      g_unique_app_custom_message (uniqueapp, data);
+      g_free (data);
       
-      Bonobo_Listener_event (listener, "new_terminal", &any, &ev);
-      CORBA_Object_release (listener, &ev);
-      if (!BONOBO_EX (&ev))
-        return TRUE;
-
-      CORBA_exception_free (&ev);
+#ifdef OLDER_GTK_VERSION
+      gdk_notify_startup_complete (); 
+#endif
+      g_object_unref (uniqueapp);
+      
+      return TRUE;
     }
-  else
-    g_printerr (_("Failed to retrieve terminal server from activation server\n"));
+    
+  g_signal_connect (G_OBJECT (uniqueapp), "message", (GCallback) terminal_new_event, NULL);
 
   return FALSE;
 }
