All pastes #738734 Raw Edit

Zeug

public text v1 · immutable
·published 2007-10-16 16:08 UTC
rendered paste body
diff --git a/src/screen.c b/src/screen.c
index 41f031e..0699007 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -3282,8 +3283,45 @@ runCommand (CompScreen *s,
 
     if (fork () == 0)
     {
+	/* build a display string that uses the right screen number */
+	int  stringLen;
+	char *pos, *delimiter, *screenString, *colon;
+	
 	setsid ();
-	putenv (s->display->displayString);
+
+	/* 5 extra chars should be enough for pretty much every situation */
+	stringLen    = strlen (s->display->displayString) + 5;
+	screenString = malloc (sizeof (char) * stringLen);
+
+	if (screenString)
+	{
+	    strcpy (screenString, s->display->displayString);
+	    delimiter = strrchr (screenString, ':');
+	    if (delimiter)
+	    {
+		colon = "";
+		delimiter = strchr (delimiter, '.');
+		if (delimiter)
+		    *p = '\0';
+	    }
+	    else
+	    {
+		/* insert :0 to keep the syntax correct */
+		colon = ":0";
+	    }
+	    pos = screenString + strlen (screenString);
+
+	    snprintf (pos, stringLen - (pos - screenString) - 1,
+		      ".%d", s->screenNum);
+
+	    putenv (screenString);
+	    free (screenString);
+	}
+	else
+	{
+	    putenv (s->display->displayString);
+	}
+
 	execl ("/bin/sh", "/bin/sh", "-c", command, NULL);
 	exit (0);
     }