#include <fcntl.h>
#include <unistd.h>
#include <CoreFoundation/CoreFoundation.h>
#include "quartzCommon.h"
#include "darwin.h"
#include "quartz.h"
#include "opaque.h"
#include "micmap.h"
int NSApplicationMain(int argc, char *argv[]);
char **envpGlobal;
typedef void (*GlxExtensionInitPtr)(void);
static GlxExtensionInitPtr GlxExtensionInit = NULL;
typedef void (*GlxWrapInitVisualsPtr)(miInitVisualsProcPtr *);
static GlxWrapInitVisualsPtr GlxWrapInitVisuals = NULL;
typedef Bool (*QuartzModeBundleInitPtr)(void);
void DarwinHandleGUI(
int argc,
char *argv[],
char *envp[] )
{
static Bool been_here = FALSE;
int main_exit, i;
int fd[2];
if (been_here) {
QuartzReadPreferences();
return;
}
been_here = TRUE;
assert( pipe(fd) == 0 );
darwinEventReadFD = fd[0];
darwinEventWriteFD = fd[1];
fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK);
argcGlobal = argc;
argvGlobal = argv;
envpGlobal = envp;
quartzStartClients = 1;
for (i = 1; i < argc; i++) {
if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
DarwinPrintBanner();
exit(0);
}
if (!strcmp(argv[i], "-nostartx")) {
quartzStartClients = 0;
} else if (!strcmp( argv[i], "-fullscreen")) {
quartzRootless = 0;
} else if (!strcmp( argv[i], "-rootless")) {
quartzRootless = 1;
}
}
main_exit = NSApplicationMain(argc, argv);
exit(main_exit);
}
Bool QuartzLoadDisplayBundle(
const char *dpyBundleName)
{
CFBundleRef mainBundle;
CFStringRef bundleName;
CFURLRef bundleURL;
CFBundleRef dpyBundle;
QuartzModeBundleInitPtr bundleInit;
mainBundle = CFBundleGetMainBundle();
bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
dpyBundleName,
kCFStringEncodingASCII,
kCFAllocatorNull);
bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
NULL, NULL);
if (!bundleURL) {
ErrorF("Could not find display mode bundle %s.\n", dpyBundleName);
return FALSE;
}
dpyBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
if (!CFBundleLoadExecutable(dpyBundle)) {
ErrorF("Could not load display mode bundle %s.\n", dpyBundleName);
return FALSE;
}
bundleInit = (void *)
CFBundleGetFunctionPointerForName(dpyBundle,
CFSTR("QuartzModeBundleInit"));
if (!bundleInit) {
ErrorF("Could not initialize display mode bundle %s.\n",
dpyBundleName);
return FALSE;
}
if (!bundleInit())
return FALSE;
CFRelease(bundleName);
CFRelease(bundleURL);
return TRUE;
}
static void LoadGlxBundle(void)
{
CFBundleRef mainBundle;
CFStringRef bundleName;
CFURLRef bundleURL;
CFBundleRef glxBundle;
mainBundle = CFBundleGetMainBundle();
ErrorF("Loading GLX bundle ");
if (quartzUseAGL) {
bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
quartzOpenGLBundle,
kCFStringEncodingASCII,
kCFAllocatorNull);
ErrorF("%s (using Apple's OpenGL)\n", quartzOpenGLBundle);
} else {
bundleName = CFSTR("glxMesa.bundle");
CFRetain(bundleName); ErrorF("glxMesa.bundle (using Mesa)\n");
}
bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
NULL, NULL);
if (!bundleURL) {
FatalError("Could not find GLX bundle.");
}
glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
if (!CFBundleLoadExecutable(glxBundle)) {
FatalError("Could not load GLX bundle.");
}
GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
glxBundle, CFSTR("GlxExtensionInit"));
GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
glxBundle, CFSTR("GlxWrapInitVisuals"));
if (!GlxExtensionInit || !GlxWrapInitVisuals) {
FatalError("Could not initialize GLX bundle.");
}
CFRelease(bundleName);
CFRelease(bundleURL);
}
void DarwinGlxExtensionInit(void)
{
if (!GlxExtensionInit)
LoadGlxBundle();
GlxExtensionInit();
}
void DarwinGlxWrapInitVisuals(
miInitVisualsProcPtr *procPtr)
{
if (!GlxWrapInitVisuals)
LoadGlxBundle();
GlxWrapInitVisuals(procPtr);
}
int DarwinModeProcessArgument( int argc, char *argv[], int i )
{
if ( !strcmp( argv[i], "-fullscreen" ) ) {
ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
#ifdef QUARTZ_SAFETY_DELAY
ErrorF( "Quitting in %d seconds if no controller is found.\n",
QUARTZ_SAFETY_DELAY );
#endif
return 1;
}
if ( !strcmp( argv[i], "-rootless" ) ) {
ErrorF( "Running rootless inside Mac OS X window server.\n" );
#ifdef QUARTZ_SAFETY_DELAY
ErrorF( "Quitting in %d seconds if no controller is found.\n",
QUARTZ_SAFETY_DELAY );
#endif
return 1;
}
if ( !strcmp( argv[i], "-quartz" ) ) {
ErrorF( "Running in parallel with Mac OS X Quartz window server.\n" );
#ifdef QUARTZ_SAFETY_DELAY
ErrorF( "Quitting in %d seconds if no controller is found.\n",
QUARTZ_SAFETY_DELAY );
#endif
return 1;
}
if ( !strcmp( argv[i], "-nostartx" ) ) {
return 1;
}
if ( !strncmp( argv[i], "-psn_", 5 ) ) {
return 1;
}
return 0;
}