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
41
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/XDarwinStartup.c,v 1.1 2002/03/28 02:21:18 torrey Exp $ */
47
#include <sys/syslimits.h>
48
#include <ApplicationServices/ApplicationServices.h>
50
// Macros to build the path name
52
#define XBINDIR /usr/X11R6/bin
55
#define XSTRPATH(s) STR(s) "/"
56
#define XPATH(file) XSTRPATH(XBINDIR) STR(file)
62
int i, j, quartzMode = -1;
65
// Check if we are going to run in Quartz mode or idle
66
// to support startx from the Quartz server. The last
67
// parameter in the list is the one used.
68
for (i = argc-1; i; i--) {
69
if (!strcmp(argv[i], "-idle")) {
73
} else if (!strcmp(argv[i], "-quartz") ||
74
!strcmp(argv[i], "-rootless") ||
75
!strcmp(argv[i], "-fullscreen"))
80
} else if (!strcmp(argv[i], "-iokit")) {
86
if (quartzMode == -1) {
87
#ifdef HAS_CG_MACH_PORT
88
// Check if the CoreGraphics window server is running.
89
// Mike Paquette says this is the fastest way to determine if it is running.
90
CFMachPortRef cgMachPortRef = CGWindowServerCFMachPort();
91
if (cgMachPortRef == NULL)
96
// On older systems we assume IOKit mode.
102
// Launch the X server for the quartz modes
104
char quartzPath[PATH_MAX+1];
111
// Build the new argument list
112
newargv = (char **) malloc((argc+2) * sizeof(char *));
113
for (j = argc; j; j--)
114
newargv[j] = argv[j];
115
newargv[argc] = "-nostartx";
116
newargv[argc+1] = NULL;
118
// Use the XDarwinQuartz soft link if it is valid
119
pathLength = readlink(XPATH(XDarwinQuartz), quartzPath, PATH_MAX);
120
if (pathLength != -1) {
121
quartzPath[pathLength] = '\0';
122
newargv[0] = quartzPath;
123
execv(newargv[0], newargv);
126
// Otherwise query LaunchServices for the location of the XDarwin application
127
theStatus = LSFindApplicationForInfo(kLSUnknownCreator,
128
CFSTR("org.xfree86.XDarwin"),
129
NULL, NULL, &appURL);
131
fprintf(stderr, "Could not find the XDarwin application. (Error = 0x%lx)\n", theStatus);
132
fprintf(stderr, "Launch XDarwin once from the Finder.\n");
136
appPath = CFURLCopyFileSystemPath (appURL, kCFURLPOSIXPathStyle);
137
success = CFStringGetCString(appPath, quartzPath, PATH_MAX, CFStringGetSystemEncoding());
139
fprintf(stderr, "Could not find path to XDarwin application.\n");
143
// Launch the XDarwin application
144
strncat(quartzPath, "/Contents/MacOS/XDarwin", PATH_MAX);
145
newargv[0] = quartzPath;
146
execv(newargv[0], newargv);
147
fprintf(stderr, "Could not start XDarwin application at %s.\n", newargv[0]);
152
// Build the new argument list
153
newargv = (char **) malloc((argc+1) * sizeof(char *));
154
for (j = argc; j; j--)
155
newargv[j] = argv[j];
156
newargv[0] = "XDarwin";
157
newargv[argc] = NULL;
159
// Launch the IOKit X server
160
execvp(newargv[0], newargv);
161
fprintf(stderr, "Could not start XDarwin IOKit X server.\n");