Skip to content

Commit

Permalink
Added key composition support, courtesy of Kuon
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 11, 2007
1 parent 8858693 commit 3f8c5c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/video/quartz/SDL_QuartzEvents.m
Expand Up @@ -254,7 +254,7 @@ void QZ_InitOSKeymap (_THIS) {
static void QZ_DoKey (_THIS, int state, NSEvent *event) {

NSString *chars;
unsigned int numChars;
unsigned int i, numChars;
SDL_keysym key;

/*
Expand All @@ -265,7 +265,8 @@ static void QZ_DoKey (_THIS, int state, NSEvent *event) {
contains multiple characters, we'll use 0 as
the scancode/keysym.
*/
if (SDL_TranslateUNICODE) {
if (SDL_TranslateUNICODE && state == SDL_PRESSED) {
[field_edit interpretKeyEvents:[NSArray arrayWithObject:event]];
chars = [ event characters ];
numChars = [ chars length ];
} else {
Expand All @@ -281,19 +282,16 @@ static void QZ_DoKey (_THIS, int state, NSEvent *event) {

SDL_PrivateKeyboard (state, &key);
}
else if (numChars == 1) {
else if (numChars >= 1) {

key.scancode = [ event keyCode ];
key.sym = keymap [ key.scancode ];
key.unicode = [ chars characterAtIndex:0 ];
key.mod = KMOD_NONE;

SDL_PrivateKeyboard (state, &key);
}
else /* (numChars > 1) */ {

int i;
for (i = 0; i < numChars; i++) {
for (i = 1; i < numChars; i++) {

key.scancode = 0;
key.sym = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.h
Expand Up @@ -99,6 +99,7 @@ typedef struct SDL_PrivateVideoData {
SDL_Rect **client_mode_list; /* resolution list to pass back to client */
SDLKey keymap[256]; /* Mac OS X to SDL key mapping */
Uint32 current_mods; /* current keyboard modifiers, to track modifier state */
NSText *field_edit; /* a field editor for keyboard composition processing */
Uint32 last_virtual_button;/* last virtual mouse button pressed */
io_connect_t power_connection; /* used with IOKit to detect wake from sleep */
Uint8 expect_mouse_up; /* used to determine when to send mouse up events */
Expand Down Expand Up @@ -146,6 +147,7 @@ typedef struct SDL_PrivateVideoData {
#define client_mode_list (this->hidden->client_mode_list)
#define keymap (this->hidden->keymap)
#define current_mods (this->hidden->current_mods)
#define field_edit (this->hidden->field_edit)
#define last_virtual_button (this->hidden->last_virtual_button)
#define power_connection (this->hidden->power_connection)
#define expect_mouse_up (this->hidden->expect_mouse_up)
Expand Down
7 changes: 7 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -169,6 +169,7 @@ static void QZ_DeleteDevice (SDL_VideoDevice *device) {

static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {

NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
const char *env = NULL;

/* Initialize the video settings; this data persists between mode switches */
Expand Down Expand Up @@ -202,6 +203,7 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
cursor_should_be_visible = YES;
cursor_visible = YES;
current_mods = 0;
field_edit = [[NSTextView alloc] initWithFrame:r];

if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
system_version = 0;
Expand Down Expand Up @@ -1456,6 +1458,11 @@ static void QZ_VideoQuit (_THIS) {
opengl_library = NULL;
}
this->gl_config.driver_loaded = 0;

if (field_edit) {
[field_edit release];
field_edit = NULL;
}
}

#if 0 /* Not used (apparently, it's really slow) */
Expand Down

0 comments on commit 3f8c5c5

Please sign in to comment.