Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402704
This commit is contained in:
parent
6f2082d584
commit
e558eee568
13 changed files with 1484 additions and 105 deletions
|
@ -36,6 +36,48 @@ static int SDL_num_keyboards;
|
|||
static int SDL_current_keyboard;
|
||||
static SDL_Keyboard **SDL_keyboards;
|
||||
|
||||
/* Taken from SDL_iconv() */
|
||||
static char *
|
||||
encodeUtf8(Uint32 ch, char *dst)
|
||||
{
|
||||
Uint8 *p = (Uint8 *) dst;
|
||||
if (ch <= 0x7F) {
|
||||
*p = (Uint8) ch;
|
||||
++dst;
|
||||
} else if (ch <= 0x7FF) {
|
||||
p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
|
||||
p[1] = 0x80 | (Uint8) (ch & 0x3F);
|
||||
dst += 2;
|
||||
} else if (ch <= 0xFFFF) {
|
||||
p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
|
||||
p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
|
||||
p[2] = 0x80 | (Uint8) (ch & 0x3F);
|
||||
dst += 3;
|
||||
} else if (ch <= 0x1FFFFF) {
|
||||
p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
|
||||
p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
|
||||
p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
|
||||
p[3] = 0x80 | (Uint8) (ch & 0x3F);
|
||||
dst += 4;
|
||||
} else if (ch <= 0x3FFFFFF) {
|
||||
p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
|
||||
p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
|
||||
p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
|
||||
p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
|
||||
p[4] = 0x80 | (Uint8) (ch & 0x3F);
|
||||
dst += 5;
|
||||
} else {
|
||||
p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
|
||||
p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
|
||||
p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
|
||||
p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
|
||||
p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
|
||||
p[5] = 0x80 | (Uint8) (ch & 0x3F);
|
||||
dst += 6;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
SDL_KeyboardInit(void)
|
||||
|
@ -227,21 +269,14 @@ SDL_GetKeyName(SDLKey layoutKey)
|
|||
/* SDLK_INDEX(layoutKey) is the unicode code point of the character generated by the key */
|
||||
static char buffer[9]; /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */
|
||||
char *bufferPtr = &buffer[1];
|
||||
SDL_iconv_t cd;
|
||||
size_t inbytesleft = 4, outbytesleft = 8;
|
||||
Uint32 codepoint = SDLK_INDEX(layoutKey);
|
||||
const char *codepointPtr = (const char *) &codepoint;
|
||||
|
||||
/* Unaccented letter keys on latin keyboards are normally labeled in upper case (and probably on others like Greek or Cyrillic too, so if you happen to know for sure, please adapt this). */
|
||||
if (codepoint >= 'a' && codepoint <= 'z') {
|
||||
codepoint -= 32;
|
||||
}
|
||||
|
||||
cd = SDL_iconv_open("UTF-8", "UCS-4");
|
||||
if (cd == (SDL_iconv_t) (-1))
|
||||
return "";
|
||||
SDL_iconv(cd, &codepointPtr, &inbytesleft, &bufferPtr, &outbytesleft);
|
||||
SDL_iconv_close(cd);
|
||||
bufferPtr = encodeUtf8(codepoint, bufferPtr);
|
||||
*bufferPtr = '\0';
|
||||
|
||||
if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue