Commits

wifiman committed cc3c855

Added Cocoa initialization workaround for SDL.

Comments (0)

Files changed (3)

 USE_OPENAL = yes
 USE_OSS = yes
 # Renderer functionality:
+USE_COCOA = no
 USE_JPEG = yes
 # Server (including in-client) functionality:
 USE_JUDY = yes
  r1gl_CFLAGS += -DUSE_JPEG $(JPEG_CFLAGS)
  r1gl_LIBS += $(JPEG_LIBS)
 endif
+ifeq ($(strip $(USE_COCOA)),yes)
+ COCOA_CFLAGS = 
+ COCOA_LIBS = -framework Cocoa
+ r1gl_CFLAGS += -DCOCOA $(COCOA_CFLAGS)
+ r1gl_LIBS += $(COCOA_LIBS)
+ r1gl_COCOA_OBJ = cocoa.o
+endif
 OPENGL_CFLAGS = 
 OPENGL_LIBS = -lGL
 PNG_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpng || libpng-config --cflags)
 r1gl_OBJ=$(addprefix obj/ref_r1gl/, \
          gl_draw.o gl_image.o gl_light.o gl_mesh.o gl_model.o gl_rmain.o \
          gl_rmisc.o gl_rsurf.o gl_sdl.o gl_warp.o glob.o q_shared.o \
-         q_shlinux.o qgl_linux.o )
+         q_shlinux.o qgl_linux.o $(r1gl_COCOA_OBJ) )
 r1q2ded_OBJ=$(addprefix obj/r1q2ded/, \
             cmd.o cmodel.o common.o crc.o cvar.o files.o glob.o ioapi.o md4.o \
             mersennetwister.o net_chan.o net_udp.o pmove.o q_shared.o \
 	$(CC) $(r1q2ded_CFLAGS) $(dep_CFLAGS) -c -o $@ $<
 obj/ref_r1gl/%.o: %.c | obj/ref_r1gl
 	$(CC) $(r1gl_CFLAGS) $(dep_CFLAGS) -c -o $@ $<
+obj/ref_r1gl/%.o: %.m | obj/ref_r1gl
+	$(CC) $(r1gl_CFLAGS) $(dep_CFLAGS) -c -o $@ $<
 
 obj/client/cl_main.o: _version.h
 obj/client/console.o: _version.h
+/*
+   Hack for native windowing on Mac OS X.
+   http://forums.libsdl.org/viewtopic.php?p=3324
+*/
+
+#import <Cocoa/Cocoa.h>
+
+typedef struct CPSProcessSerNum {
+	UInt32 lo;
+	UInt32 hi;
+} CPSProcessSerNum;
+
+extern OSErr CPSGetCurrentProcess (CPSProcessSerNum *psn);
+extern OSErr CPSEnableForegroundOperation (CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
+extern OSErr CPSSetFrontProcess (CPSProcessSerNum *psn);
+
+void CocoaHack (void) {
+	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+	[NSApplication sharedApplication];
+	[NSApp setMainMenu:[[NSMenu alloc] init]];
+	CPSProcessSerNum PSN;
+	if (!CPSGetCurrentProcess(&PSN))
+		if (!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103))
+			if (!CPSSetFrontProcess(&PSN))
+				[NSApplication sharedApplication];
+}
 
 /*****************************************************************************/
 
+#ifdef COCOA
+void CocoaHack (void);
+#endif
+
 /*
 ** SWimp_Init
 **
 int SWimp_Init( void *hInstance, void *wndProc )
 {
 	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+#ifdef COCOA
+		CocoaHack();
+#endif
 		if (SDL_Init(SDL_INIT_VIDEO) < 0) {
 			Sys_Error("SDL Init failed: %s\n", SDL_GetError());
 			return qfalse;
 		}
 	} else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
+#ifdef COCOA
+		CocoaHack();
+#endif
 		if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
 			Sys_Error("SDL Init failed: %s\n", SDL_GetError());
 			return qfalse;