Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Max's patches for building MacOS X apps on command line
  • Loading branch information
slouken committed Sep 4, 2001
1 parent fa07c50 commit c80db4d
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -61,7 +61,7 @@ exports:
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
Expand Down
Binary file modified PBProjects.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions configure.in
Expand Up @@ -2191,6 +2191,7 @@ docs/man3/Makefile
include/Makefile
src/Makefile
src/main/Makefile
src/main/macosx/Makefile
src/audio/Makefile
src/audio/alsa/Makefile
src/audio/arts/Makefile
Expand Down
6 changes: 6 additions & 0 deletions sdl-config.in
Expand Up @@ -56,6 +56,12 @@ while test $# -gt 0; do
@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
Expand Down
17 changes: 17 additions & 0 deletions sdl.m4
Expand Up @@ -58,6 +58,17 @@ dnl Now check if the installed SDL is sufficiently new. (Also sanity
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>
Expand Down Expand Up @@ -169,5 +180,11 @@ int main(int argc, char *argv[])
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
])
2 changes: 2 additions & 0 deletions src/main/Makefile.am
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions src/main/macosx/Info.plist
@@ -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>
17 changes: 17 additions & 0 deletions src/main/macosx/Makefile.am
@@ -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
1 change: 1 addition & 0 deletions src/main/macosx/SDLMain.h
Expand Up @@ -10,5 +10,6 @@
{
}
- (IBAction)quit:(id)sender;
- (IBAction)makeFullscreen:(id)sender;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
@end
28 changes: 20 additions & 8 deletions src/main/macosx/SDLMain.m
Expand Up @@ -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;
Expand All @@ -29,27 +30,35 @@ - (void) quit:(id)sender
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++;

while (*c != '/') /* back up to parent */
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" */
Expand Down Expand Up @@ -81,9 +90,10 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note
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 */
Expand Down Expand Up @@ -148,8 +158,10 @@ int main (int argc, char **argv) {
/* 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);
Expand Down
12 changes: 12 additions & 0 deletions src/main/macosx/SDLMain.nib/classes.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/main/macosx/SDLMain.nib/info.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added src/main/macosx/SDLMain.nib/objects.nib
Binary file not shown.
4 changes: 2 additions & 2 deletions src/video/maccommon/SDL_macevents.c
Expand Up @@ -72,7 +72,7 @@ static int Mac_HandleActivate(int activate)
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;
Expand Down Expand Up @@ -617,7 +617,7 @@ void Mac_InitEvents(_THIS)
FlushEvents(everyEvent, 0);

/* Allow every event but keyrepeat */
SetEventMask(everyEvent - autoKeyMask);
SetEventMask(everyEvent & ~autoKeyMask);
}

void Mac_QuitEvents(_THIS)
Expand Down
22 changes: 13 additions & 9 deletions src/video/maccommon/SDL_macmouse.c
Expand Up @@ -67,18 +67,22 @@ WMcursor *Mac_CreateWMCursor(_THIS,
return(NULL);
}
memset(cursor, 0, sizeof(*cursor));

bytes = (w/8);
if ( bytes > 2 ) {
bytes = 2;
}
for ( row=0; row<h && (row < 16); ++row ) {

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 += w/8;
data += bytes;
}
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;
Expand Down
2 changes: 1 addition & 1 deletion src/video/quartz/Makefile.am
Expand Up @@ -11,7 +11,7 @@ QUARTZ_SRCS = \
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
14 changes: 14 additions & 0 deletions src/video/quartz/SDL_QuartzEvents.m
Expand Up @@ -206,6 +206,12 @@ static void QZ_DoActivate (_THIS)
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);
}
Expand All @@ -218,6 +224,12 @@ static void QZ_DoDeactivate (_THIS) {
if (currentGrabMode == SDL_GRAB_ON) {
CGAssociateMouseAndMouseCursorPosition (1);
}

/* Show the mouse cursor */
// FIXME
if (!QZ_cursor_visible) {
ShowCursor ();
}

SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
}
Expand Down Expand Up @@ -309,6 +321,8 @@ static void QZ_PumpEvents (_THIS)
case NSRightMouseDragged:
case 27:
case NSMouseMoved:
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN)
|| NSPointInRect([event locationInWindow], winRect) )
{
static int moves = 0;
NSPoint p;
Expand Down
38 changes: 22 additions & 16 deletions src/video/quartz/SDL_QuartzWM.m
Expand Up @@ -35,46 +35,52 @@ static void QZ_FreeWMCursor (_THIS, WMcursor *cursor) {
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;
}
for ( row=0; row<h && (row < 16); ++row ) {

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 += w/8;
data += bytes;
}
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;
}
}

Expand Down

0 comments on commit c80db4d

Please sign in to comment.