Date: Sat, 14 Dec 2002 13:33:05 -0500
authorSam Lantinga <slouken@libsdl.org>
Sun, 15 Dec 2002 09:09:31 +0000
changeset 5614bcf7dd06c47
parent 560 37c31c12eb70
child 562 cb40b26523a5
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
src/video/quartz/SDL_QuartzVideo.h
     1.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Fri Dec 13 21:09:52 2002 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sun Dec 15 09:09:31 2002 +0000
     1.3 @@ -206,25 +206,51 @@
     1.4  static void QZ_DoKey (_THIS, int state, NSEvent *event) {
     1.5  
     1.6      NSString *chars;
     1.7 -    int i;
     1.8 +    unsigned int numChars;
     1.9      SDL_keysym key;
    1.10 -
    1.11 +    
    1.12      /* 
    1.13 -        An event can contain multiple characters
    1.14 -        I'll ignore this fact for now, since there 
    1.15 -        is only one virtual key code per event, so
    1.16 -        no good way to handle this.
    1.17 +        A key event can contain multiple characters,
    1.18 +        or no characters at all. In most cases, it
    1.19 +        will contain a single character. If it contains
    1.20 +        0 characters, we'll use 0 as the unicode. If it
    1.21 +        contains multiple characters, we'll use 0 as
    1.22 +        the scancode/keysym.
    1.23      */
    1.24      chars = [ event characters ];
    1.25 -    for (i =0; i < 1 /*[ chars length ] */; i++) {
    1.26 +    numChars = [ chars length ];
    1.27 +
    1.28 +    if (numChars == 1) {
    1.29  
    1.30          key.scancode = [ event keyCode ];
    1.31 -        key.sym         = keymap [ key.scancode ];
    1.32 -        key.unicode     = [ chars characterAtIndex:i];
    1.33 -        key.mod         = KMOD_NONE;
    1.34 +        key.sym      = keymap [ key.scancode ];
    1.35 +        key.unicode  = [ chars characterAtIndex:0 ];
    1.36 +        key.mod      = KMOD_NONE;
    1.37  
    1.38          SDL_PrivateKeyboard (state, &key);
    1.39      }
    1.40 +    else if (numChars == 0) {
    1.41 +      
    1.42 +        key.scancode = [ event keyCode ];
    1.43 +        key.sym      = keymap [ key.scancode ];
    1.44 +        key.unicode  = 0;
    1.45 +        key.mod      = KMOD_NONE;
    1.46 +
    1.47 +        SDL_PrivateKeyboard (state, &key);
    1.48 +    }
    1.49 +    else /* (numChars > 1) */ {
    1.50 +      
    1.51 +        int i;
    1.52 +        for (i = 0; i < numChars; i++) {
    1.53 +
    1.54 +            key.scancode = 0;
    1.55 +            key.sym      = 0;
    1.56 +            key.unicode  = [ chars characterAtIndex:i];
    1.57 +            key.mod      = KMOD_NONE;
    1.58 +
    1.59 +            SDL_PrivateKeyboard (state, &key);
    1.60 +        }
    1.61 +    }
    1.62  }
    1.63  
    1.64  static void QZ_DoModifiers (_THIS, unsigned int newMods) {
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Fri Dec 13 21:09:52 2002 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sun Dec 15 09:09:31 2002 +0000
     2.3 @@ -52,6 +52,7 @@
     2.4  #include <OpenGL/OpenGL.h>
     2.5  #include <Carbon/Carbon.h>
     2.6  #include <QuickTime/QuickTime.h>
     2.7 +#include <IOKit/IOKitLib.h>	/* For powersave handling */
     2.8  
     2.9  #include "SDL_video.h"
    2.10  #include "SDL_error.h"
    2.11 @@ -308,4 +309,4 @@
    2.12  
    2.13  /* YUV functions */
    2.14  static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
    2.15 -                                         Uint32 format, SDL_Surface *display);
    2.16 \ No newline at end of file
    2.17 +                                         Uint32 format, SDL_Surface *display);