### Eclipse Workspace Patch 1.0
#P at-spi
Index: registryd/Makefile.am
===================================================================
--- registryd/Makefile.am	(revision 1184)
+++ registryd/Makefile.am	(working copy)
@@ -22,12 +22,33 @@
 	registry.h		\
 	ucs2keysym.c
 
-LDADD = $(top_builddir)/libspi/libspi.la $(X_LIBS) $(XTST_LIBS) $(XEVIE_LIBS) $(REGISTRYD_LIBS) 
+LDADD = $(top_builddir)/libspi/libspi.la $(X_LIBS) $(SM_LIBS) $(XTST_LIBS) $(XEVIE_LIBS) $(REGISTRYD_LIBS) 
 
 serverinfodir = $(libdir)/bonobo/servers
 serverinfo_DATA = Accessibility_Registry.server
 
+default_sessiondir = $(sysconfdir)/xdg/autostart
+default_session_in_in_files = 				\
+	at-spi-registryd.desktop.in.in
+default_session_in_files = $(default_session_in_in_files:.desktop.in.in=.desktop.in)
+default_session_DATA = $(default_session_in_files:.desktop.in=.desktop)
+
+@INTLTOOL_DESKTOP_RULE@
+
+%.desktop.in: %.desktop.in.in Makefile.am
+	sed -e "s,\@registryddir\@,$(libexecdir)," \
+		< $< > $@
+
 @INTLTOOL_SERVER_RULE@
 
 EXTRA_DIST = Accessibility_Registry.server.in.in
-CLEANFILES = $(serverinfo_DATA) $(server_dot_in)
+CLEANFILES = 			\
+	$(serverinfo_DATA)	\
+	$(server_dot_in)	\
+	$(default_session_DATA)	\
+	$(default_session_in_files)
+	
+DISTCLEANFILES =					\
+	$(default_session_in_in_files)
+
+
Index: registryd/at-spi-registryd.desktop.in.in.in
===================================================================
--- registryd/at-spi-registryd.desktop.in.in.in	(revision 0)
+++ registryd/at-spi-registryd.desktop.in.in.in	(revision 0)
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Type=Application
+_Name=AT SPI Registry Wrapper
+Exec=@registryddir@/at-spi-registryd
+OnlyShowIn=GNOME;
+NoDisplay=true
+AutostartCondition=GNOME /desktop/gnome/interface/accessibility
+X-GNOME-Autostart-Phase=Initialization
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=at-spi
+X-GNOME-Bugzilla-Component=general
+X-GNOME-Bugzilla-Version=@VERSION@
Index: configure.in
===================================================================
--- configure.in	(revision 1184)
+++ configure.in	(working copy)
@@ -194,6 +194,19 @@
 	AC_SUBST(XEVIE_LIBS)
 fi
 
+dnl Allow disabling SMlib
+AC_ARG_ENABLE(sm, [  --enable-sm  Enable session management support [default=yes]], enable_sm="$enableval", enable_sm=yes)
+
+if test x$enable_sm = xyes ; then
+	have_sm=
+	AC_CHECK_LIB(SM, SmcSaveYourselfDone, have_sm="yes")
+	if test x$have_sm = xyes ; then
+		SM_LIBS="-lSM -lICE"
+		AC_DEFINE(HAVE_SM, , [Building with SM support])
+	fi
+	AC_SUBST(SM_LIBS)
+fi
+
 dnl CFLAGS="$CFLAGS -Wall"
 AC_SUBST(CFLAGS)
 AC_SUBST(CPPFLAGS)
@@ -243,6 +256,7 @@
 idl/Makefile
 libspi/Makefile
 registryd/Makefile
+registryd/at-spi-registryd.desktop.in.in
 atk-bridge/Makefile
 login-helper/Makefile
 test/Makefile
Index: registryd/registry-main.c
===================================================================
--- registryd/registry-main.c	(revision 1184)
+++ registryd/registry-main.c	(working copy)
@@ -32,9 +32,14 @@
 #include <glib.h>
 #include "registry.h"
 
+#ifdef HAVE_SM
+#include <X11/SM/SMlib.h>
+#endif
+
 #define spi_get_display() GDK_DISPLAY()
 
 static void registry_set_ior (SpiRegistry *registry);
+static void registry_session_init (const char *previous_client_id, const char *exe);
 
 int
 main (int argc, char **argv)
@@ -80,6 +85,19 @@
       fprintf (stderr, "SpiRegistry Message: SpiRegistry daemon is running.\n");
 #endif
       registry_set_ior (registry);
+
+      /* If DESKTOP_AUTOSTART_ID exists, assume we're started by session
+       * manager and connect to it. */
+      const char *desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+      if (desktop_autostart_id != NULL) {
+        char *client_id = g_strdup (desktop_autostart_id);
+        /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
+         * use the same client id. */
+        g_unsetenv ("DESKTOP_AUTOSTART_ID");
+        registry_session_init (client_id, argv[0]);
+        g_free (client_id);
+      }
+
       bonobo_main ();
     }
 
@@ -115,3 +133,88 @@
   CORBA_exception_free (&ev);
 
 }
+
+void
+registry_session_init (const char *previous_client_id, const char *exe)
+{
+#ifdef HAVE_SM
+  char buf[256];
+  char *client_id;
+
+  SmcConn session_connection =
+    SmcOpenConnection (NULL, /* use SESSION_MANAGER env */
+                       NULL, /* means use existing ICE connection */
+                       SmProtoMajor,
+                       SmProtoMinor,
+                       0,
+                       NULL,
+                       (char*) previous_client_id,
+                       &client_id,
+                       255, buf);
+
+  if (session_connection != NULL) {
+    SmProp prop1, prop2, prop3, prop4, prop5, prop6, *props[6];
+    SmPropValue prop1val, prop2val, prop3val, prop4val, prop5val, prop6val;
+    char pid[32];
+    char hint = SmRestartImmediately;
+    char priority = 1; /* low to run before other apps */
+
+    prop1.name = SmProgram;
+    prop1.type = SmARRAY8;
+    prop1.num_vals = 1;
+    prop1.vals = &prop1val;
+    prop1val.value = exe;
+    prop1val.length = strlen (exe);
+
+    /* twm sets getuid() for this, but the SM spec plainly
+     * says pw_name, twm is on crack
+     */
+    prop2.name = SmUserID;
+    prop2.type = SmARRAY8;
+    prop2.num_vals = 1;
+    prop2.vals = &prop2val;
+    prop2val.value = (char*) g_get_user_name ();
+    prop2val.length = strlen (prop2val.value);
+
+    prop3.name = SmRestartStyleHint;
+    prop3.type = SmCARD8;
+    prop3.num_vals = 1;
+    prop3.vals = &prop3val;
+    prop3val.value = &hint;
+    prop3val.length = 1;
+
+    sprintf (pid, "%d", getpid ());
+    prop4.name = SmProcessID;
+    prop4.type = SmARRAY8;
+    prop4.num_vals = 1;
+    prop4.vals = &prop4val;
+    prop4val.value = pid;
+    prop4val.length = strlen (prop4val.value);
+
+    /* Always start in home directory */
+    prop5.name = SmCurrentDirectory;
+    prop5.type = SmARRAY8;
+    prop5.num_vals = 1;
+    prop5.vals = &prop5val;
+    prop5val.value = (char*) g_get_home_dir ();
+    prop5val.length = strlen (prop5val.value);
+
+    prop6.name = "_GSM_Priority";
+    prop6.type = SmCARD8;
+    prop6.num_vals = 1;
+    prop6.vals = &prop6val;
+    prop6val.value = &priority;
+    prop6val.length = 1;
+
+    props[0] = &prop1;
+    props[1] = &prop2;
+    props[2] = &prop3;
+    props[3] = &prop4;
+    props[4] = &prop5;
+    props[5] = &prop6;
+
+    SmcSetProperties (session_connection, 6, props);
+  }
+
+#endif
+}
Index: po/POTFILES.in
===================================================================
--- po/POTFILES.in	(revision 1184)
+++ po/POTFILES.in	(working copy)
@@ -2,3 +2,4 @@
 # Please keep this file sorted alphabetically.
 at-spi.schemas.in
 registryd/Accessibility_Registry.server.in.in
+registryd/at-spi-registryd-wrapper.desktop.in.in.in
Index: po/POTFILES.skip
===================================================================
--- po/POTFILES.skip	(revision 1184)
+++ po/POTFILES.skip	(working copy)
@@ -2,3 +2,5 @@
 # Please keep this file sorted alphabetically.
 atk-bridge/bridge.c
 registryd/Accessibility_Registry.server.in
+registryd/at-spi-registryd-wrapper.desktop.in
+registryd/at-spi-registryd-wrapper.desktop.in.in
