Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Implemented Cocoa key event handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 30, 2006
1 parent 7dd17d8 commit f788806
Show file tree
Hide file tree
Showing 7 changed files with 717 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/events/SDL_keyboard.c
Expand Up @@ -654,6 +654,7 @@ SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
event.key.keysym.mod = modstate;
event.key.keysym.unicode = 0;
event.key.windowID = keyboard->focus;
/* FIXME: This doesn't make sense anymore... */
/*
* jk 991215 - Added
*/
Expand Down Expand Up @@ -688,7 +689,7 @@ SDL_SendKeyboardText(int index, const char *text)
event.text.type = SDL_TEXTINPUT;
event.text.which = (Uint8) index;
SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
event.key.windowID = keyboard->focus;
event.text.windowID = keyboard->focus;
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
Expand Down
19 changes: 14 additions & 5 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -89,17 +89,17 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
[appleMenu addItem:[NSMenuItem separatorItem]];

title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@/*"h"*/""];

menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@/*"h"*/""];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];

[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];

[appleMenu addItem:[NSMenuItem separatorItem]];

title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@/*"q"*/""];

/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
Expand All @@ -116,7 +116,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];

/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@/*"m"*/""];
[windowMenu addItem:menuItem];
[menuItem release];

Expand Down Expand Up @@ -169,7 +169,16 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
if ( event == nil ) {
break;
}
[NSApp sendEvent:event];
switch ([event type]) {
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
Cocoa_HandleKeyEvent(_this, event);
/* Fall through to pass event to NSApp */
default:
[NSApp sendEvent:event];
break;
}
}
[pool release];
}
Expand Down

0 comments on commit f788806

Please sign in to comment.