--- gdm-2.18.1/daemon/display.c	2007-05-22 22:30:59.000000000 +0800
+++ gdm-2.18.1-mine/daemon/display.c	2007-05-22 22:05:35.000000000 +0800
@@ -520,6 +520,9 @@ gdm_display_dispose (GdmDisplay *d)
     g_free (d->userauth);
     d->userauth = NULL;
 
+    g_free (d->windowpath);
+    d->windowpath = NULL;
+
     g_free (d->command);
     d->command = NULL;
 
--- gdm-2.18.1/daemon/gdm.h	2007-04-09 13:15:15.000000000 +0800
+++ gdm-2.18.1-mine/daemon/gdm.h	2007-05-22 22:19:53.000000000 +0800
@@ -490,6 +490,7 @@ struct _GdmDisplay {
     gchar *userauth;
     gboolean authfb;
     time_t last_auth_touch;
+    char *windowpath; /* path to server "window" */
     gchar *command;
     gboolean failsafe_xserver;
     gboolean use_chooser; /* run chooser instead of greeter */
--- gdm-2.18.1/daemon/server.c	2007-05-22 22:30:59.000000000 +0800
+++ gdm-2.18.1-mine/daemon/server.c	2007-05-22 22:06:04.000000000 +0800
@@ -1427,6 +1427,7 @@ gdm_server_alloc (gint id, const gchar *
     d->authfile_gdm = NULL;
     d->auths = NULL;
     d->userauth = NULL;
+    d->windowpath = NULL;
     d->command = g_strdup (command);
     d->cookie = NULL;
     d->dispstat = DISPLAY_UNBORN;
--- gdm-2.18.1/daemon/slave.c	2007-05-22 22:31:00.000000000 +0800
+++ gdm-2.18.1-mine/daemon/slave.c	2007-05-22 23:05:38.000000000 +0800
@@ -63,6 +63,7 @@
 #include <errno.h>
 #include <time.h>
 #include <syslog.h>
+#include <stdint.h>
 
 #ifdef HAVE_TSOL
 #include <user_attr.h>
@@ -1061,6 +1062,77 @@ gdm_screen_init (GdmDisplay *display) 
 }
 
 static void
+gdm_window_path (GdmDisplay *d)
+{
+	/* setting WINDOWPATH for clients */
+	Atom prop;
+	Atom actualtype;
+	int actualformat;
+	unsigned long nitems;
+	unsigned long bytes_after;
+	unsigned char *buf;
+	const char *windowpath;
+	char *newwindowpath;
+	unsigned long num;
+	char nums[10];
+	int numn;
+
+	prop = XInternAtom (d->dsp, "XFree86_VT", False);
+	if (prop == None) {
+		gdm_debug ("no XFree86_VT atom\n");
+		return;
+	}
+	if (XGetWindowProperty (d->dsp, DefaultRootWindow (d->dsp), prop, 0, 1, 
+		False, AnyPropertyType, &actualtype, &actualformat, 
+		&nitems, &bytes_after, &buf)) {
+		gdm_debug ("no XFree86_VT property\n");
+		return;
+	}
+	if (nitems != 1) {
+		gdm_debug ("%lu items in XFree86_VT property!\n", nitems);
+		XFree (buf);
+		return;
+	}
+	switch (actualtype) {
+	case XA_CARDINAL:
+	case XA_INTEGER:
+	case XA_WINDOW:
+		switch (actualformat) {
+		case  8:
+			num = (*(uint8_t  *)(void *)buf);
+			break;
+		case 16:
+			num = (*(uint16_t *)(void *)buf);
+			break;
+		case 32:
+			num = (*(uint32_t *)(void *)buf);
+			break;
+		default:
+			gdm_debug ("format %d in XFree86_VT property!\n", actualformat);
+			XFree (buf);
+			return;
+		}
+		break;
+	default:
+		gdm_debug ("type %lx in XFree86_VT property!\n", actualtype);
+		XFree (buf);
+		return;
+	}
+	XFree (buf);
+	windowpath = getenv("WINDOWPATH");
+	numn = snprintf (nums, sizeof (nums), "%lu", num);
+	if (!windowpath) {
+		newwindowpath = malloc (numn + 1);
+		sprintf (newwindowpath, "%s", nums);
+	} else {
+		newwindowpath = malloc (strlen (windowpath) + 1 + numn + 1);
+		sprintf (newwindowpath, "%s:%s", windowpath, nums);
+	}
+	free (d->windowpath);
+	d->windowpath = newwindowpath;
+}
+
+static void
 gdm_slave_whack_greeter (void)
 {
 	GdmWaitPid *wp;
@@ -1478,6 +1550,9 @@ gdm_slave_run (GdmDisplay *display)
 		gdm_tsol_init (d);
 #endif
 
+    /* checkout window number */
+    gdm_window_path (d);
+
     /* check log stuff for the server, this is done here
      * because it's really a race */
     if (SERVER_IS_LOCAL (d))
@@ -3078,6 +3153,8 @@ gdm_slave_chooser (void)
 
 		g_setenv ("XAUTHORITY", GDM_AUTHFILE (d), TRUE);
 		g_setenv ("DISPLAY", d->name, TRUE);
+		if (d->windowpath)
+			g_setenv ("WINDOWPATH", d->windowpath, TRUE);
 
 		g_setenv ("LOGNAME", gdmuser, TRUE);
 		g_setenv ("USER", gdmuser, TRUE);
@@ -3540,6 +3617,8 @@ session_child_run (struct passwd *pwent,
 	/* Prepare user session */
 	g_setenv ("XAUTHORITY", d->userauth, TRUE);
 	g_setenv ("DISPLAY", d->name, TRUE);
+	if (d->windowpath)
+		g_setenv ("WINDOWPATH", d->windowpath, TRUE);
 	g_setenv ("LOGNAME", pwent->pw_name, TRUE);
 	g_setenv ("USER", pwent->pw_name, TRUE);
 	g_setenv ("USERNAME", pwent->pw_name, TRUE);
@@ -5438,6 +5517,8 @@ gdm_slave_exec_script (GdmDisplay *d, co
 	else
 		g_unsetenv ("XAUTHORITY");
         g_setenv ("DISPLAY", d->name, TRUE);
+	if (d->windowpath)
+		g_setenv ("WINDOWPATH", d->windowpath, TRUE);
 	g_setenv ("PATH", gdm_get_value_string (GDM_KEY_ROOT_PATH), TRUE);
 	g_setenv ("RUNNING_UNDER_GDM", "true", TRUE);
 	if ( ! ve_string_empty (d->theme_name))
--- gdm-2.18.1/daemon/xdmcp.c	2007-04-09 13:15:15.000000000 +0800
+++ gdm-2.18.1-mine/daemon/xdmcp.c	2007-05-22 22:06:28.000000000 +0800
@@ -2743,6 +2743,7 @@ gdm_xdmcp_display_alloc (
     d->authfile         = NULL;
     d->auths            = NULL;
     d->userauth         = NULL;
+    d->windowpath       = NULL;
     d->greetpid         = 0;
     d->servpid          = 0;
     d->servstat         = 0;
