Added Max's patches for building MacOS X apps on command line
authorSam Lantinga <slouken@libsdl.org>
Tue, 04 Sep 2001 23:18:45 +0000
changeset 168 e92aa316c517
parent 167 cb384ef627f6
child 169 8039a5b760b9
Added Max's patches for building MacOS X apps on command line
Makefile.am
PBProjects.tar.gz
configure.in
sdl-config.in
sdl.m4
src/main/Makefile.am
src/main/macosx/Info.plist
src/main/macosx/Makefile.am
src/main/macosx/SDLMain.h
src/main/macosx/SDLMain.m
src/main/macosx/SDLMain.nib/classes.nib
src/main/macosx/SDLMain.nib/info.nib
src/main/macosx/SDLMain.nib/objects.nib
src/video/maccommon/SDL_macevents.c
src/video/maccommon/SDL_macmouse.c
src/video/quartz/Makefile.am
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzWM.m
--- a/Makefile.am	Tue Sep 04 22:53:46 2001 +0000
+++ b/Makefile.am	Tue Sep 04 23:18:45 2001 +0000
@@ -61,7 +61,7 @@
 PBProjects.tar.gz:
 	rm -f `find . -name .DS_Store`
 	if [ -d PBProjects ]; then \
-	    tar zcvf $@ PBProjects src/main/macosx/SDLMain.nib; \
+	    tar zcvf $@ PBProjects; \
 	fi
 
 # Rule to force automake to rebuild the library
Binary file PBProjects.tar.gz has changed
--- a/configure.in	Tue Sep 04 22:53:46 2001 +0000
+++ b/configure.in	Tue Sep 04 23:18:45 2001 +0000
@@ -2191,6 +2191,7 @@
 include/Makefile
 src/Makefile
 src/main/Makefile
+src/main/macosx/Makefile
 src/audio/Makefile
 src/audio/alsa/Makefile
 src/audio/arts/Makefile
--- a/sdl-config.in	Tue Sep 04 22:53:46 2001 +0000
+++ b/sdl-config.in	Tue Sep 04 23:18:45 2001 +0000
@@ -56,6 +56,12 @@
 @ENABLE_STATIC_TRUE@      libdirs="-L@libdir@ @SDL_RLD_FLAGS@"
 @ENABLE_STATIC_TRUE@      echo $libdirs @SDL_LIBS@ @SYSTEM_LIBS@
 @ENABLE_STATIC_TRUE@      ;;
+@TARGET_MACOSX_TRUE@    --nib)
+@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDLMain.nib
+@TARGET_MACOSX_TRUE@      ;;
+@TARGET_MACOSX_TRUE@    --plist)
+@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/Info.plist
+@TARGET_MACOSX_TRUE@      ;;
     *)
       echo "${usage}" 1>&2
       exit 1
--- a/sdl.m4	Tue Sep 04 22:53:46 2001 +0000
+++ b/sdl.m4	Tue Sep 04 23:18:45 2001 +0000
@@ -58,6 +58,17 @@
 dnl checks the results of sdl-config to some extent
 dnl
       rm -f conf.sdltest
+      case "$target" in
+          *-*-darwin*)
+            cp -r `$SDL_CONFIG --nib` .
+            dnl create an Info.plist file, unless one exists
+            if test -f Info.plist ; then
+             :
+            else
+             cp `$SDL_CONFIG --plist` .
+            fi
+              ;;
+      esac
       AC_TRY_RUN([
 #include <stdio.h>
 #include <stdlib.h>
@@ -169,5 +180,11 @@
   fi
   AC_SUBST(SDL_CFLAGS)
   AC_SUBST(SDL_LIBS)
+      case "$target" in
+          *-*-darwin*)
+              SDL_APPLE_CREATOR="????"
+              AC_SUBST(SDL_APPLE_CREATOR)
+              ;;
+      esac
   rm -f conf.sdltest
 ])
--- a/src/main/Makefile.am	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/main/Makefile.am	Tue Sep 04 23:18:45 2001 +0000
@@ -4,6 +4,8 @@
 # This is necessary because some platforms have special program
 # entry points, which require special application initialization.
 
+SUBDIRS = macosx
+
 ARCH_SUBDIRS = $(srcdir)/beos $(srcdir)/linux \
                $(srcdir)/macos $(srcdir)/macosx $(srcdir)/win32
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/Info.plist	Tue Sep 04 23:18:45 2001 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>English</string>
+	<key>CFBundleExecutable</key>
+	<string>dummy</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>dummy</string>
+	<key>CFBundlePackageType</key>
+	<string>APPL</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>NSMainNibFile</key>
+	<string>SDLMain.nib</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/Makefile.am	Tue Sep 04 23:18:45 2001 +0000
@@ -0,0 +1,17 @@
+# On OS X, install the SDLMain.nib.
+# We use an ugly hack to force the creation of the
+# destination dir, maybe somebody with more automake
+# experience knows how to do this properly?
+
+if TARGET_MACOSX
+masternibdatadir = $(datadir)/sdl/SDLMain.nib
+masternibdata_DATA =		\
+	SDLMain.nib
+
+nibdatadir = $(datadir)/sdl
+nibdata_DATA =			\
+	SDLMain.nib/classes.nib	\
+	SDLMain.nib/info.nib	\
+	SDLMain.nib/objects.nib	\
+	Info.plist
+endif
--- a/src/main/macosx/SDLMain.h	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/main/macosx/SDLMain.h	Tue Sep 04 23:18:45 2001 +0000
@@ -10,5 +10,6 @@
 {
 }
 - (IBAction)quit:(id)sender;
+- (IBAction)makeFullscreen:(id)sender;
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
 @end
--- a/src/main/macosx/SDLMain.m	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/main/macosx/SDLMain.m	Tue Sep 04 23:18:45 2001 +0000
@@ -12,6 +12,7 @@
 static int    gArgc;
 static char  **gArgv;
 static NSString *gAppName = 0;
+static BOOL   gFinderLaunch;
 
 @interface NSString (ReplaceSubString)
 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@@ -29,15 +30,21 @@
     SDL_PushEvent(&event);
 }
 
+/* Invoked from the Make Full-Screen menu item */
+- (void) makeFullscreen:(id)sender
+{
+    /* TODO */
+}
+
 /* Set the working directory to the .app's parent directory */
-- (void) setupWorkingDirectory
+- (void) setupWorkingDirectory:(BOOL)shouldChdir
 {
     char parentdir[MAXPATHLEN];
     char *c;
     
     strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
     c = (char*) parentdir;
-    
+
     while (*c != '\0')     /* go to end */
         c++;
     
@@ -45,11 +52,13 @@
         c--;
     
     *c++ = '\0';             /* cut off last part (binary name) */
-    
-    assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
-    assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
-    
-    gAppName = [ NSString stringWithCString: c ];
+  
+    if (shouldChdir)
+    {
+      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
+      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
+    }
+    /* gAppName = [ NSString stringWithCString: c ]; */
 }
 
 /* Fix menu to contain the real app name instead of "SDL App" */
@@ -81,9 +90,10 @@
     int status;
 
     /* Set the working directory to the .app's parent directory */
-    [ self setupWorkingDirectory ];
+    [ self setupWorkingDirectory: gFinderLaunch ];
 
     /* Set the main menu to contain the real app name instead of "SDL App" */
+    gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
     [ self fixMenu: [ NSApp mainMenu ] ];
 
     /* Hand off to main application code */
@@ -148,8 +158,10 @@
     /* This is passed if we are launched by double-clicking */
     if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
         gArgc = 1;
+	gFinderLaunch = YES;
     } else {
         gArgc = argc;
+	gFinderLaunch = NO;
     }
     gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
     assert (gArgv != NULL);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/SDLMain.nib/classes.nib	Tue Sep 04 23:18:45 2001 +0000
@@ -0,0 +1,12 @@
+{
+    IBClasses = (
+        {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
+        {
+            ACTIONS = {makeFullscreen = id; quit = id; }; 
+            CLASS = SDLMain; 
+            LANGUAGE = ObjC; 
+            SUPERCLASS = NSObject; 
+        }
+    ); 
+    IBVersion = 1; 
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/SDLMain.nib/info.nib	Tue Sep 04 23:18:45 2001 +0000
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
+<plist version="0.9">
+<dict>
+	<key>IBDocumentLocation</key>
+	<string>49 97 356 240 0 0 987 746 </string>
+	<key>IBMainMenuLocation</key>
+	<string>20 515 195 44 0 46 800 532 </string>
+	<key>IBUserGuides</key>
+	<dict/>
+</dict>
+</plist>
Binary file src/main/macosx/SDLMain.nib/objects.nib has changed
--- a/src/video/maccommon/SDL_macevents.c	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/video/maccommon/SDL_macevents.c	Tue Sep 04 23:18:45 2001 +0000
@@ -72,7 +72,7 @@
 		SDL_SetCursor(NULL);
 
 		/* put our mask back case it changed during context switch */
-		SetEventMask(everyEvent - autoKeyMask);
+		SetEventMask(everyEvent & ~autoKeyMask);
 	} else {
 #if TARGET_API_MAC_CARBON
 		{ Cursor cursor;
@@ -617,7 +617,7 @@
 	FlushEvents(everyEvent, 0);
 	
 	/* Allow every event but keyrepeat */
-	SetEventMask(everyEvent - autoKeyMask);
+	SetEventMask(everyEvent & ~autoKeyMask);
 }
 
 void Mac_QuitEvents(_THIS)
--- a/src/video/maccommon/SDL_macmouse.c	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/video/maccommon/SDL_macmouse.c	Tue Sep 04 23:18:45 2001 +0000
@@ -67,18 +67,22 @@
 		return(NULL);
 	}
 	memset(cursor, 0, sizeof(*cursor));
-		
-	bytes = (w/8);
-	if ( bytes > 2 ) {
-		bytes = 2;
+    
+    if (w > 16)
+        w = 16;
+    
+    if (h > 16)
+        h = 16;
+    
+	bytes = (w+7)/8;
+
+	for ( row=0; row<h; ++row ) {
+		memcpy(&cursor->curs.data[row], data, bytes);
+		data += bytes;
 	}
-	for ( row=0; row<h && (row < 16); ++row ) {
-		memcpy(&cursor->curs.data[row], data, bytes);
-		data += w/8;
-	}
-	for ( row=0; row<h && (row < 16); ++row ) {
+	for ( row=0; row<h; ++row ) {
 		memcpy(&cursor->curs.mask[row], mask, bytes);
-		mask += w/8;
+		mask += bytes;
 	}
 	cursor->curs.hotSpot.h = hot_x;
 	cursor->curs.hotSpot.v = hot_y;
--- a/src/video/quartz/Makefile.am	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/video/quartz/Makefile.am	Tue Sep 04 23:18:45 2001 +0000
@@ -11,7 +11,7 @@
 	SDL_QuartzVideo.m
 
 # These files are included by SDL_QuartzVideo.m (is that right??)
-EXTRA_DIST = 			\
+noinst_HEADERS =		\
 	SDL_QuartzEvents.m	\
 	SDL_QuartzWM.m		\
 	SDL_QuartzWindow.m
--- a/src/video/quartz/SDL_QuartzEvents.m	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/video/quartz/SDL_QuartzEvents.m	Tue Sep 04 23:18:45 2001 +0000
@@ -206,6 +206,12 @@
         QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
         CGAssociateMouseAndMouseCursorPosition (0);
     }
+
+    /* Hide the mouse cursor if inside the app window */
+    // FIXME
+    if (!QZ_cursor_visible) {
+            HideCursor ();
+    }
     
     SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
 }
@@ -218,6 +224,12 @@
     if (currentGrabMode == SDL_GRAB_ON) {
         CGAssociateMouseAndMouseCursorPosition (1);
     }
+
+    /* Show the mouse cursor */
+    // FIXME
+    if (!QZ_cursor_visible) {
+            ShowCursor ();
+    }
     
     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
 }
@@ -309,6 +321,8 @@
             case NSRightMouseDragged:
             case 27:
             case NSMouseMoved:
+                if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN)
+                	|| NSPointInRect([event locationInWindow], winRect) )
                 {
                    static int moves = 0;
                    NSPoint p;
--- a/src/video/quartz/SDL_QuartzWM.m	Tue Sep 04 22:53:46 2001 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m	Tue Sep 04 23:18:45 2001 +0000
@@ -35,46 +35,52 @@
                                           int w, int h, int hot_x, int hot_y) { 
 	WMcursor *cursor;
 	int row, bytes;
+		
+	/* Allocate the cursor memory */
 	cursor = (WMcursor *)malloc(sizeof(WMcursor));
 	if ( cursor == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
 	memset(cursor, 0, sizeof(*cursor));
-		
-	bytes = (w/8);
-	if ( bytes > 2 ) {
-		bytes = 2;
+    
+    if (w > 16)
+        w = 16;
+    
+    if (h > 16)
+        h = 16;
+    
+	bytes = (w+7)/8;
+
+	for ( row=0; row<h; ++row ) {
+		memcpy(&cursor->curs.data[row], data, bytes);
+		data += bytes;
 	}
-	for ( row=0; row<h && (row < 16); ++row ) {
-		memcpy(&cursor->curs.data[row], data, bytes);
-		data += w/8;
-	}
-	for ( row=0; row<h && (row < 16); ++row ) {
+	for ( row=0; row<h; ++row ) {
 		memcpy(&cursor->curs.mask[row], mask, bytes);
-		mask += w/8;
+		mask += bytes;
 	}
 	cursor->curs.hotSpot.h = hot_x;
 	cursor->curs.hotSpot.v = hot_y;
 	
-        return(cursor);
+    return(cursor);
 }
 
+static int QZ_cursor_visible = 1;
+    
 static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
 
-    static int visible = 1;
-    
     if ( cursor == NULL) {
-        if ( visible ) {
+        if ( QZ_cursor_visible ) {
             HideCursor ();
-            visible = 0;
+            QZ_cursor_visible = 0;
         }
     }
     else {
         SetCursor(&cursor->curs);
-        if ( ! visible ) {
+        if ( ! QZ_cursor_visible ) {
             ShowCursor ();
-            visible = 1;
+            QZ_cursor_visible = 1;
         }
     }