~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/darwin/quartz/XDarwinStartup.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************
 
2
 *
 
3
 * Startup program for Darwin X servers
 
4
 *
 
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)
 
9
 *
 
10
 * If told to idle, the program will simply pause and not
 
11
 * launch any X server. This is to support startx being
 
12
 * run by XDarwin.app.
 
13
 *
 
14
 **************************************************************/
 
15
/*
 
16
 * Copyright (c) 2001-2002 Torrey T. Lyons. All Rights Reserved.
 
17
 *
 
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:
 
24
 *
 
25
 * The above copyright notice and this permission notice shall be included in
 
26
 * all copies or substantial portions of the Software.
 
27
 *
 
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
 
34
 * SOFTWARE.
 
35
 *
 
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
 
39
 * Torrey T. Lyons.
 
40
 */
 
41
/* $XFree86: xc/programs/Xserver/hw/darwin/quartz/XDarwinStartup.c,v 1.1 2002/03/28 02:21:18 torrey Exp $ */
 
42
 
 
43
#include <unistd.h>
 
44
#include <stdio.h>
 
45
#include <stdlib.h>
 
46
#include <errno.h>
 
47
#include <sys/syslimits.h>
 
48
#include <ApplicationServices/ApplicationServices.h>
 
49
 
 
50
// Macros to build the path name
 
51
#ifndef XBINDIR
 
52
#define XBINDIR /usr/X11R6/bin
 
53
#endif
 
54
#define STR(s) #s
 
55
#define XSTRPATH(s) STR(s) "/"
 
56
#define XPATH(file) XSTRPATH(XBINDIR) STR(file)
 
57
 
 
58
int main(
 
59
    int         argc,
 
60
    char        *argv[] )
 
61
{
 
62
    int         i, j, quartzMode = -1;
 
63
    char        **newargv;
 
64
 
 
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")) {
 
70
            pause();
 
71
            return 0;
 
72
 
 
73
        } else if (!strcmp(argv[i], "-quartz") ||
 
74
                   !strcmp(argv[i], "-rootless") ||
 
75
                   !strcmp(argv[i], "-fullscreen"))
 
76
        {
 
77
            quartzMode = 1;
 
78
            break;
 
79
 
 
80
        } else if (!strcmp(argv[i], "-iokit")) {
 
81
            quartzMode = 0;
 
82
            break;
 
83
        }
 
84
    }
 
85
 
 
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)
 
92
            quartzMode = 0;
 
93
        else
 
94
            quartzMode = 1;
 
95
#else
 
96
        // On older systems we assume IOKit mode.
 
97
        quartzMode = 0;
 
98
#endif
 
99
    }
 
100
 
 
101
    if (quartzMode) {
 
102
        // Launch the X server for the quartz modes
 
103
 
 
104
        char quartzPath[PATH_MAX+1];
 
105
        int pathLength;
 
106
        OSStatus theStatus;
 
107
        CFURLRef appURL;
 
108
        CFStringRef appPath;
 
109
        Boolean success;
 
110
 
 
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;
 
117
 
 
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);
 
124
        }
 
125
 
 
126
        // Otherwise query LaunchServices for the location of the XDarwin application
 
127
        theStatus = LSFindApplicationForInfo(kLSUnknownCreator,
 
128
                                             CFSTR("org.xfree86.XDarwin"),
 
129
                                             NULL, NULL, &appURL);
 
130
        if (theStatus) {
 
131
            fprintf(stderr, "Could not find the XDarwin application. (Error = 0x%lx)\n", theStatus);
 
132
            fprintf(stderr, "Launch XDarwin once from the Finder.\n");
 
133
            return theStatus;
 
134
        }
 
135
 
 
136
        appPath = CFURLCopyFileSystemPath (appURL, kCFURLPOSIXPathStyle);
 
137
        success = CFStringGetCString(appPath, quartzPath, PATH_MAX, CFStringGetSystemEncoding());
 
138
        if (! success) {
 
139
            fprintf(stderr, "Could not find path to XDarwin application.\n");
 
140
            return success;
 
141
        }
 
142
 
 
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]);
 
148
        return errno;
 
149
 
 
150
    } else {
 
151
 
 
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;
 
158
    
 
159
        // Launch the IOKit X server
 
160
        execvp(newargv[0], newargv);
 
161
        fprintf(stderr, "Could not start XDarwin IOKit X server.\n");
 
162
        return errno;
 
163
    }
 
164
}