From d97fab8ffa9dc582d3ba3f5eb9f2aaf2241b4694 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 15 Dec 2002 09:09:31 +0000 Subject: [PATCH] Date: Sat, 14 Dec 2002 13:33:05 -0500 From: Darrell Walisser Subject: Re: crash in SDL / OSX > Yes, compose keys and other "dead" keys should have unicode 0. > As a hack, if you get multiple composed characters, you can send the > sequence with a valid unicode and a keysym of 0. It's because of > things like this that I'm separating the key and char events in SDL 2.0 I've done this and here's the patch. --- src/video/quartz/SDL_QuartzEvents.m | 46 ++++++++++++++++++++++------- src/video/quartz/SDL_QuartzVideo.h | 3 +- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/video/quartz/SDL_QuartzEvents.m b/src/video/quartz/SDL_QuartzEvents.m index 2f26b6dcb..20861ffaa 100644 --- a/src/video/quartz/SDL_QuartzEvents.m +++ b/src/video/quartz/SDL_QuartzEvents.m @@ -206,25 +206,51 @@ static void QZ_InitOSKeymap (_THIS) { static void QZ_DoKey (_THIS, int state, NSEvent *event) { NSString *chars; - int i; + unsigned int numChars; SDL_keysym key; - + /* - An event can contain multiple characters - I'll ignore this fact for now, since there - is only one virtual key code per event, so - no good way to handle this. + A key event can contain multiple characters, + or no characters at all. In most cases, it + will contain a single character. If it contains + 0 characters, we'll use 0 as the unicode. If it + contains multiple characters, we'll use 0 as + the scancode/keysym. */ chars = [ event characters ]; - for (i =0; i < 1 /*[ chars length ] */; i++) { + numChars = [ chars length ]; + + 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 if (numChars == 0) { + key.scancode = [ event keyCode ]; - key.sym = keymap [ key.scancode ]; - key.unicode = [ chars characterAtIndex:i]; - key.mod = KMOD_NONE; + key.sym = keymap [ key.scancode ]; + key.unicode = 0; + key.mod = KMOD_NONE; SDL_PrivateKeyboard (state, &key); } + else /* (numChars > 1) */ { + + int i; + for (i = 0; i < numChars; i++) { + + key.scancode = 0; + key.sym = 0; + key.unicode = [ chars characterAtIndex:i]; + key.mod = KMOD_NONE; + + SDL_PrivateKeyboard (state, &key); + } + } } static void QZ_DoModifiers (_THIS, unsigned int newMods) { diff --git a/src/video/quartz/SDL_QuartzVideo.h b/src/video/quartz/SDL_QuartzVideo.h index f9af234a2..3e098fd6c 100644 --- a/src/video/quartz/SDL_QuartzVideo.h +++ b/src/video/quartz/SDL_QuartzVideo.h @@ -52,6 +52,7 @@ #include #include #include +#include /* For powersave handling */ #include "SDL_video.h" #include "SDL_error.h" @@ -308,4 +309,4 @@ static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode); /* YUV functions */ static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height, - Uint32 format, SDL_Surface *display); \ No newline at end of file + Uint32 format, SDL_Surface *display);