Skip to content

Commit

Permalink
OSX: Enable application shortcuts (CMD-Q etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris.oneill committed Nov 2, 2012
1 parent dd869c9 commit cba8ff4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sdl/ht.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main( int argc, char *argv[] )
switch( event.type )
{
case SDL_QUIT:
quitting = TRUE;
quitting = gui_maybe_quit();
break;

default:
Expand Down
3 changes: 2 additions & 1 deletion sdl/osx/xcode/SDLMain.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (void)setAppleMenu:(NSMenu *)menu;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
BOOL enableKeys = FALSE;

static NSString *getApplicationName(void)
{
Expand Down Expand Up @@ -80,7 +81,7 @@ - (void)terminate:(id)sender
- (void)sendEvent:(NSEvent *)anEvent {
if( NSKeyDown == [anEvent type] || NSKeyUp ==
[anEvent type] ) {
if( [anEvent modifierFlags] & NSCommandKeyMask )
if( enableKeys || [anEvent modifierFlags] & NSCommandKeyMask )
[super sendEvent: anEvent];
} else
[super sendEvent: anEvent];
Expand Down
13 changes: 12 additions & 1 deletion sdl/osx/xcode/osx.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
typedef Sint32 int32;
typedef char TEXT;

extern BOOL enableKeys;

int32 gui_req( uint32 img, TEXT *title, TEXT *reqtxt, TEXT *buttons )
{
int i;
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:[NSString stringWithUTF8String:title]];
[alert setInformativeText:[NSString stringWithUTF8String:reqtxt]];
Expand All @@ -25,7 +28,10 @@ int32 gui_req( uint32 img, TEXT *title, TEXT *reqtxt, TEXT *buttons )
[alert addButtonWithTitle:btnStr];
}

return [alert runModal] - 1000;
enableKeys = TRUE;
i = [alert runModal] - 1000;
enableKeys = FALSE;
return i;
}

#define FR_HVLSAVE 0
Expand Down Expand Up @@ -69,7 +75,10 @@ int32 gui_req( uint32 img, TEXT *title, TEXT *reqtxt, TEXT *buttons )
[panel setTitle:[NSString stringWithUTF8String:title]];
[panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:path] isDirectory:YES]];
[panel setNameFieldStringValue:[NSString stringWithUTF8String:fname]];

enableKeys = TRUE;
int i = [panel runModal];
enableKeys = FALSE;
if (i == 1) {
const char *cstr = [[[panel URL] path] UTF8String];
char *rval = (char *) malloc(strlen(cstr) + 1);
Expand All @@ -87,7 +96,9 @@ BOOL directoryrequester( char *title, char *path )
[panel setCanChooseDirectories:YES];
[panel setTitle: [NSString stringWithUTF8String:title]];
[panel setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:path] isDirectory:YES]];
enableKeys = FALSE;
int i = [panel runModal];
enableKeys = FALSE;
if (i == 1) {
const char *cstr = [[[panel URL] path] UTF8String];
strncpy(path, cstr, 512);
Expand Down

0 comments on commit cba8ff4

Please sign in to comment.