@@ -174,9 +174,22 @@ static void InitSDL()
174
174
int ret;
175
175
176
176
#if defined(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING)
177
+ // Requires SDL 2.0.5. Disables thread naming so that gdb works correctly
178
+ // with the game.
177
179
SDL_SetHint ( SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, " 1" );
178
180
#endif
179
181
182
+ #if defined(_WIN32) && defined(SDL_HINT_IME_SHOW_UI)
183
+ // Requires SDL 2.0.20. Shows the native IME UI instead of using SDL's
184
+ // broken implementation on Windows which does not show.
185
+ SDL_SetHint ( SDL_HINT_IME_SHOW_UI, " 1" );
186
+ #endif
187
+
188
+ #if defined(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT)
189
+ // Requires SDL 2.0.22. Support long IME composition text.
190
+ SDL_SetHint ( SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, " 1" );
191
+ #endif
192
+
180
193
#if defined(__linux__)
181
194
// https://bugzilla.libsdl.org/show_bug.cgi?id=3472#c5
182
195
if ( SDL_COMPILEDVERSION == SDL_VERSIONNUM ( 2 , 0 , 5 ) ) {
@@ -2519,9 +2532,8 @@ bool is_string_input( input_context &ctx )
2519
2532
{
2520
2533
std::string &category = ctx.get_category ();
2521
2534
return category == " STRING_INPUT"
2522
- || category == " HELP_KEYBINDINGS"
2523
- || category == " NEW_CHAR_DESCRIPTION"
2524
- || category == " WORLDGEN_CONFIRM_DIALOG" ;
2535
+ || category == " STRING_EDITOR"
2536
+ || category == " HELP_KEYBINDINGS" ;
2525
2537
}
2526
2538
2527
2539
int get_key_event_from_string ( const std::string &str )
@@ -3204,11 +3216,35 @@ static void CheckMessages()
3204
3216
last_input = input_event ();
3205
3217
last_input.type = input_event_t ::keyboard_char;
3206
3218
}
3207
- last_input.edit = ev.edit .text ;
3219
+ // Convert to string explicitly to avoid accidentally using
3220
+ // the array out of scope.
3221
+ last_input.edit = std::string ( ev.edit .text );
3208
3222
last_input.edit_refresh = true ;
3209
3223
text_refresh = true ;
3224
+ break ;
3210
3225
}
3211
- break ;
3226
+ #if defined(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT)
3227
+ case SDL_TEXTEDITING_EXT: {
3228
+ if ( !ev.editExt .text ) {
3229
+ break ;
3230
+ }
3231
+ if ( strlen ( ev.editExt .text ) > 0 ) {
3232
+ const unsigned lc = UTF8_getch ( ev.editExt .text );
3233
+ last_input = input_event ( lc, input_event_t ::keyboard_char );
3234
+ } else {
3235
+ // no key pressed in this event
3236
+ last_input = input_event ();
3237
+ last_input.type = input_event_t ::keyboard_char;
3238
+ }
3239
+ // Convert to string explicitly to avoid accidentally using
3240
+ // a pointer that will be freed
3241
+ last_input.edit = std::string ( ev.editExt .text );
3242
+ last_input.edit_refresh = true ;
3243
+ text_refresh = true ;
3244
+ SDL_free ( ev.editExt .text );
3245
+ break ;
3246
+ }
3247
+ #endif
3212
3248
case SDL_CONTROLLERBUTTONDOWN:
3213
3249
case SDL_CONTROLLERBUTTONUP:
3214
3250
gamepad::handle_button_event ( ev );
0 commit comments