Sophie

Sophie

distrib > Mageia > 1 > i586 > media > core-updates-src > by-pkgid > 00483d81de16d6155bb71015324df6f6 > files > 25

kdebase4-workspace-4.6.5-1.3.mga1.src.rpm

commit c6b621ff55d6218bd726c53389581b10f99963b0
Author: Alberto Mattea <alberto@mattea.info>
Date:   Fri May 6 19:06:22 2011 +0200

    Add multihead support to ksplashx
    REVIEW: 101136

diff --git a/ksplash/ksplashx/main.cpp b/ksplash/ksplashx/main.cpp
index 236bb87..5d133b7 100644
--- a/ksplash/ksplashx/main.cpp
+++ b/ksplash/ksplashx/main.cpp
@@ -23,6 +23,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+#include <signal.h>
+#include <math.h>
+
+int screen_number = 0;
+int number_of_screens = 1;
 
 static void usage( char* name )
     {
@@ -36,6 +41,7 @@ int main( int argc, char* argv[] )
         usage( argv[ 0 ] );
     bool test = false;
     bool print_pid = false;
+    int* cpid;
     for( int i = 2; // 1 is the theme
          i < argc;
          ++i )
@@ -72,6 +78,55 @@ int main( int argc, char* argv[] )
             close( 0 ); // close stdin,stdout,stderr, otherwise startkde will block
             close( 1 );
             close( 2 );
+            Display* dpy = XOpenDisplay(NULL);
+            if (!dpy)
+                {
+                exit(1);
+                }
+            number_of_screens = ScreenCount(dpy);
+            if (number_of_screens > 1)
+                {
+                cpid = (int*)calloc(number_of_screens, sizeof(int));
+                screen_number = DefaultScreen(dpy);
+                char* display_name;
+                display_name = XDisplayString(dpy);
+                int breakpos;
+                for (int i = strlen(display_name) - 1; i >= 0; i--)
+                    {
+                    if (display_name[i] == '.')
+                        {
+                        breakpos = i;
+                        break;
+                        }
+                    }
+                // Calculate the array size: part before the dot + length of the screen
+                // string (which is log10 + 1) + 1 for the dot itself + 8 for "DISPLAY=" + \0
+                char envir[breakpos + (int)log10(number_of_screens) + 11];
+                char server_name[breakpos + 1];
+                strncpy(server_name, display_name, breakpos);
+                server_name[breakpos] = '\0';
+
+                XCloseDisplay(dpy);
+                dpy = 0;
+                for (int i = 0; i < number_of_screens; i++)
+                    {
+                    if (i != screen_number)
+                        {
+                        cpid[i] = fork();
+                        if (cpid[i] == 0)
+                            {
+                            screen_number = i;
+                            // Break here because we are the child process, we don't
+                            // want to fork() anymore
+                            break;
+                            }
+                        }
+                    }
+                sprintf(envir, "DISPLAY=%s.%d", server_name, screen_number);
+                putenv(strdup(envir));
+                }
+            else
+                XCloseDisplay(dpy);
             }
         else
             { // parent
@@ -91,4 +146,9 @@ int main( int argc, char* argv[] )
         XSynchronize( qt_xdisplay(), True );
     runSplash( theme, test, parent_pipe );
     closeDisplay();
+    if (number_of_screens > 1)
+        {
+        for (int i = 1; i < number_of_screens; i++)
+            kill(cpid[i], SIGTERM);
+        }
     }
diff --git a/ksplash/ksplashx/splash.cpp b/ksplash/ksplashx/splash.cpp
index d6a992a..d1c0c81 100644
--- a/ksplash/ksplashx/splash.cpp
+++ b/ksplash/ksplashx/splash.cpp
@@ -30,6 +30,8 @@ const char states[][ 12 ] =
 // State "ready" isn't used, make splash go away as soon as desktop is ready.
 const int LAST_STATE = 6;
 
+extern int screen_number;
+
 #include <config-workspace.h>
 
 #include "splash.h"
@@ -595,7 +597,7 @@ static bool waitState( int expected_state )
 #ifdef DEBUG
     fprintf( stderr,"AWATING STATE: %d (%s)\n", expected_state, states[ expected_state ] );
 #endif
-    if( parent_pipe >= 0 )
+    if( parent_pipe >= 0 && screen_number == 0)
         { // wait for paint being finished, and tell parent to exit
         XSync( qt_xdisplay(), False );
         char buf = '\0';