pass full Unicode characters to EV_GUI_Char for Linux and macOS.

The Linux backend looked like it didn't handle anything non-ASCII at all, but this all needs to be tested.
Windows will be a bit more work because it requires using the Unicode API for creating the main window.
This commit is contained in:
Christoph Oelckers 2019-02-14 14:29:49 +01:00
parent 8efc3188b9
commit 5f574033b5
2 changed files with 17 additions and 8 deletions

View file

@ -371,7 +371,7 @@ NSStringEncoding GetEncodingForUnicodeCharacter(const unichar character)
return NSWindowsCP1252StringEncoding;
}
unsigned char GetCharacterFromNSEvent(NSEvent* theEvent)
unsigned char GetCharacterFromNSEvent(NSEvent* theEvent, unichar *realchar)
{
const NSString* unicodeCharacters = [theEvent characters];
@ -400,6 +400,7 @@ unsigned char GetCharacterFromNSEvent(NSEvent* theEvent)
: '\0';
}
*realchar = unicodeCharacter;
return character;
}
@ -407,9 +408,10 @@ void ProcessKeyboardEventInMenu(NSEvent* theEvent)
{
event_t event = {};
unichar realchar;
event.type = EV_GUI_Event;
event.subtype = NSKeyDown == [theEvent type] ? EV_GUI_KeyDown : EV_GUI_KeyUp;
event.data2 = GetCharacterFromNSEvent(theEvent);
event.data2 = GetCharacterFromNSEvent(theEvent, &realchar);
event.data3 = ModifierFlagsToGUIKeyModifiers(theEvent);
if (EV_GUI_KeyDown == event.subtype && [theEvent isARepeat])
@ -462,7 +464,7 @@ void ProcessKeyboardEventInMenu(NSEvent* theEvent)
&& ShouldGenerateGUICharEvent(theEvent))
{
event.subtype = EV_GUI_Char;
event.data1 = event.data2;
event.data1 = realchar;
event.data2 = event.data3 & GKM_ALT;
D_PostEvent(&event);

View file

@ -471,11 +471,18 @@ void MessagePump (const SDL_Event &sev)
case SDL_TEXTINPUT:
if (GUICapture)
{
event.type = EV_GUI_Event;
event.subtype = EV_GUI_Char;
event.data1 = sev.text.text[0];
event.data2 = !!(SDL_GetModState() & KMOD_ALT);
D_PostEvent (&event);
int utf8_decode(const char *src, int *size);
int size;
int unichar = utf8_decode(sev.text.text, &size);
if (size != 4)
{
event.type = EV_GUI_Event;
event.subtype = EV_GUI_Char;
event.data1 = (int16_t)unichar;
event.data2 = !!(SDL_GetModState() & KMOD_ALT);
D_PostEvent (&event);
}
}
break;