From 0c77cafc595f6b38bd7e5e11aea9b0f3f95b87db Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 30 Aug 2022 13:16:13 -0400
Subject: [PATCH] events: Only look at first codepoint of TEXTINPUT, use it if
keypress matches.
SDL 1.2 wasn't complicated (or correct) about the `unicode` field on
KEYDOWN events, this feels like it matches more closely.
We _might_ revert this change, though, because this is taking a sledgehammer
to something pretty delicate.
---
src/SDL12_compat.c | 33 ++++-----------------------------
1 file changed, 4 insertions(+), 29 deletions(-)
diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index ab776573..f529f140 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -4458,35 +4458,10 @@ EventFilter20to12(void *data, SDL_Event *event20)
case SDL_TEXTEDITING: return 1;
case SDL_TEXTINPUT: {
char *text = event20->text.text;
- int codePoint;
- while ((codePoint = DecodeUTF8Char(&text)) != 0) {
- if (codePoint > 0xFFFF) {
- /* We need to send a UTF-16 surrogate pair. */
- Uint16 firstChar = ((codePoint - 0x10000) >> 10) + 0xD800;
- Uint16 secondChar = ((codePoint - 0x10000) & 0x3FF) + 0xDC00;
- event12.type = SDL12_KEYDOWN;
- event12.key.state = SDL12_PRESSED;
- event12.key.keysym.scancode = 0;
- event12.key.keysym.sym = SDLK12_UNKNOWN;
- event12.key.keysym.unicode = firstChar;
- if (!FlushPendingKeydownEvent(firstChar)) {
- PushEventIfNotFiltered(&event12);
- }
- event12.key.keysym.unicode = secondChar;
- PushEventIfNotFiltered(&event12);
- } else {
- if (!FlushPendingKeydownEvent(codePoint)) {
- event12.type = SDL12_KEYDOWN;
- event12.key.state = SDL12_PRESSED;
- event12.key.keysym.scancode = 0;
- event12.key.keysym.sym = SDLK12_UNKNOWN;
- event12.key.keysym.unicode = codePoint;
- PushEventIfNotFiltered(&event12);
- }
- }
- }
- }
- return 1;
+ const int codePoint = DecodeUTF8Char(&text);
+ FlushPendingKeydownEvent(codePoint);
+ return 1;
+ }
case SDL_MOUSEMOTION:
event12.type = SDL12_MOUSEMOTION;