not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / ksplash / ksplashx / main.cpp
blob236bb8777b8bf27fd7e574cfc6b9be43fdd0ac96
1 /********************************************************************
3 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
5 Please see file LICENSE for the licensing terms of ksplashx as a whole.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "pixmap.h"
22 #include "splash.h"
23 #include <string.h>
24 #include <unistd.h>
25 #include <errno.h>
27 static void usage( char* name )
29 fprintf( stderr, "Usage: %s <theme> [--test] [--pid]\n", name );
30 exit( 1 );
33 int main( int argc, char* argv[] )
35 if( argc != 2 && argc != 3 && argc != 4 )
36 usage( argv[ 0 ] );
37 bool test = false;
38 bool print_pid = false;
39 for( int i = 2; // 1 is the theme
40 i < argc;
41 ++i )
43 if( strcmp( argv[ i ], "--test" ) == 0 )
44 test = true;
45 else if( strcmp( argv[ i ], "--pid" ) == 0 )
46 print_pid = true;
47 else
48 usage( argv[ 0 ] );
50 const char* theme = argv[ 1 ];
51 if( strcmp( theme, "DefaultFullscreen" ) == 0 )
52 theme = "Default"; // these are now the same
53 int parent_pipe = -1;
54 if( print_pid )
56 int pipes[ 2 ];
57 if( pipe( pipes ) < 0 )
59 perror( "pipe()" );
60 abort();
62 pid_t pid = fork();
63 if( pid < 0 )
65 perror( "fork()" );
66 abort();
68 if( pid == 0 )
69 { // child
70 close( pipes[ 0 ] );
71 parent_pipe = pipes[ 1 ];
72 close( 0 ); // close stdin,stdout,stderr, otherwise startkde will block
73 close( 1 );
74 close( 2 );
76 else
77 { // parent
78 close( pipes[ 1 ] );
79 char buf;
80 while( read( pipes[ 0 ], &buf, 1 ) < 0
81 && ( errno == EINTR || errno == EAGAIN || errno == ECHILD ))
83 if( print_pid )
84 printf( "%d\n", pid );
85 return 0;
88 if( !openDisplay())
89 return 2;
90 if( test )
91 XSynchronize( qt_xdisplay(), True );
92 runSplash( theme, test, parent_pipe );
93 closeDisplay();