1 /**************************************************************
3 * Startup program for Darwin X servers
5 * This program selects the appropriate X server to launch:
6 * XDarwin IOKit X server (default)
7 * XDarwinQuartz A soft link to the Quartz X server
8 * executable (-quartz etc. option)
10 * If told to idle, the program will simply pause and not
11 * launch any X server. This is to support startx being
14 **************************************************************/
16 * Copyright (c) 2001-2002 Torrey T. Lyons. All Rights Reserved.
18 * Permission is hereby granted, free of charge, to any person obtaining a
19 * copy of this software and associated documentation files (the "Software"),
20 * to deal in the Software without restriction, including without limitation
21 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
22 * and/or sell copies of the Software, and to permit persons to whom the
23 * Software is furnished to do so, subject to the following conditions:
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31 * TORREY T. LYONS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
33 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * Except as contained in this notice, the name of Torrey T. Lyons shall not
37 * be used in advertising or otherwise to promote the sale, use or other
38 * dealings in this Software without prior written authorization from
46 #include <sys/syslimits.h>
47 #include <ApplicationServices/ApplicationServices.h>
49 // Macros to build the path name
51 #define XBINDIR /usr/X11/bin
54 #define XSTRPATH(s) STR(s) "/"
55 #define XPATH(file) XSTRPATH(XBINDIR) STR(file)
61 int i
, j
, quartzMode
= -1;
64 // Check if we are going to run in Quartz mode or idle
65 // to support startx from the Quartz server. The last
66 // parameter in the list is the one used.
67 for (i
= argc
-1; i
; i
--) {
68 if (!strcmp(argv
[i
], "-idle")) {
72 } else if (!strcmp(argv
[i
], "-quartz") ||
73 !strcmp(argv
[i
], "-rootless") ||
74 !strcmp(argv
[i
], "-fullscreen"))
79 } else if (!strcmp(argv
[i
], "-iokit")) {
85 if (quartzMode
== -1) {
86 #ifdef HAS_CG_MACH_PORT
87 // Check if the CoreGraphics window server is running.
88 // Mike Paquette says this is the fastest way to determine if it is running.
89 CFMachPortRef cgMachPortRef
= CGWindowServerCFMachPort();
90 if (cgMachPortRef
== NULL
)
95 // On older systems we assume IOKit mode.
101 // Launch the X server for the quartz modes
103 char quartzPath
[PATH_MAX
+1];
110 // Build the new argument list
111 newargv
= (char **) malloc((argc
+2) * sizeof(char *));
112 for (j
= argc
; j
; j
--)
113 newargv
[j
] = argv
[j
];
114 newargv
[argc
] = "-nostartx";
115 newargv
[argc
+1] = NULL
;
117 // Use the XDarwinQuartz soft link if it is valid
118 pathLength
= readlink(XPATH(XDarwinQuartz
), quartzPath
, PATH_MAX
);
119 if (pathLength
!= -1) {
120 quartzPath
[pathLength
] = '\0';
121 newargv
[0] = quartzPath
;
122 execv(newargv
[0], newargv
);
125 // Otherwise query LaunchServices for the location of the XDarwin application
126 theStatus
= LSFindApplicationForInfo(kLSUnknownCreator
,
128 NULL
, NULL
, &appURL
);
130 fprintf(stderr
, "Could not find the XDarwin application. (Error = 0x%lx)\n", theStatus
);
131 fprintf(stderr
, "Launch XDarwin once from the Finder.\n");
135 appPath
= CFURLCopyFileSystemPath (appURL
, kCFURLPOSIXPathStyle
);
136 success
= CFStringGetCString(appPath
, quartzPath
, PATH_MAX
, CFStringGetSystemEncoding());
138 fprintf(stderr
, "Could not find path to XDarwin application.\n");
142 // Launch the XDarwin application
143 strncat(quartzPath
, "/Contents/MacOS/XDarwin", PATH_MAX
);
144 newargv
[0] = quartzPath
;
145 execv(newargv
[0], newargv
);
146 fprintf(stderr
, "Could not start XDarwin application at %s.\n", newargv
[0]);
151 // Build the new argument list
152 newargv
= (char **) malloc((argc
+1) * sizeof(char *));
153 for (j
= argc
; j
; j
--)
154 newargv
[j
] = argv
[j
];
155 newargv
[0] = "XDarwin";
156 newargv
[argc
] = NULL
;
158 // Launch the IOKit X server
159 execvp(newargv
[0], newargv
);
160 fprintf(stderr
, "Could not start XDarwin IOKit X server.\n");