From c13e74be6b0f76d97a587656f4c86e8a4b8d8402 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 23 Sep 2025 10:46:43 +0100 Subject: [PATCH 1/2] progress: Correct calls to dbus_message_iter_open_container with variants As documented, the contained_signature is to be passed in as a nul-terminated C string. For basic types that are represented by a single character, on little-endian platforms, putting the type in the least significant byte of an int and casting its address to `char *` happens to result in a valid string, because the int's in-memory representation looks like `(char []){ 'b', 0, 0, 0 }`. However, on big-endian platforms, the int's in-memory representation is `(char []){ 0, 0, 0, 'b' }` which is not a valid type for a D-Bus variant to hold (it is interpreted as an empty string, and variants are not allowed to be empty). Instead, do this the straightforward way, with a mnemonic string and no casts (in the same style used in `SDL_portaldialog`). Fixes: 3f2226a9 "Add progress bar support for Linux" Resolves: https://github.com/libsdl-org/SDL/issues/13953 Bug-Debian: https://bugs.debian.org/1115705 Signed-off-by: Simon McVittie --- src/core/linux/SDL_progressbar.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/linux/SDL_progressbar.c b/src/core/linux/SDL_progressbar.c index ac0789b2d2..9f98e6acfd 100644 --- a/src/core/linux/SDL_progressbar.c +++ b/src/core/linux/SDL_progressbar.c @@ -120,8 +120,6 @@ bool DBUS_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window *window) const char *progress_visible_str = "progress-visible"; const char *progress_str = "progress"; - int dbus_type_boolean_str = DBUS_TYPE_BOOLEAN; - int dbus_type_double_str = DBUS_TYPE_DOUBLE; const int progress_visible = ShouldShowProgress(window->progress_state); double progress = (double)window->progress_value; @@ -134,14 +132,14 @@ bool DBUS_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window *window) // Set progress visible property dbus->message_iter_open_container(&props, DBUS_TYPE_DICT_ENTRY, NULL, &key_it); dbus->message_iter_append_basic(&key_it, DBUS_TYPE_STRING, &progress_visible_str); // Append progress-visible key data - dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, (const char *)&dbus_type_boolean_str, &value_it); + dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, "b", &value_it); dbus->message_iter_append_basic(&value_it, DBUS_TYPE_BOOLEAN, &progress_visible); // Append progress-visible value data dbus->message_iter_close_container(&key_it, &value_it); dbus->message_iter_close_container(&props, &key_it); // Set progress value property dbus->message_iter_open_container(&props, DBUS_TYPE_DICT_ENTRY, NULL, &key_it); dbus->message_iter_append_basic(&key_it, DBUS_TYPE_STRING, &progress_str); // Append progress key data - dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, (const char *)&dbus_type_double_str, &value_it); + dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, "d", &value_it); dbus->message_iter_append_basic(&value_it, DBUS_TYPE_DOUBLE, &progress); // Append progress value data dbus->message_iter_close_container(&key_it, &value_it); dbus->message_iter_close_container(&props, &key_it); From fe8c0807134176e2060b15dc6adefc9dfb5e8905 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 23 Sep 2025 09:59:11 -0700 Subject: [PATCH 2/2] testime: allow enabling/disabling text input on individual windows --- test/testime.c | 52 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/test/testime.c b/test/testime.c index a1a7e44299..a987a3f323 100644 --- a/test/testime.c +++ b/test/testime.c @@ -791,7 +791,11 @@ static void RedrawWindow(WindowState *ctx) break; } - SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a); + if (SDL_TextInputActive(ctx->window)) { + SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a); + } else { + SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xFF); + } SDL_RenderFillRect(renderer, &ctx->textRect); /* Initialize the drawn text rectangle for the cursor */ @@ -876,20 +880,22 @@ static void RedrawWindow(WindowState *ctx) } /* Draw the cursor */ - Uint64 now = SDL_GetTicks(); - if ((now - ctx->last_cursor_change) >= CURSOR_BLINK_INTERVAL_MS) { - ctx->cursor_visible = !ctx->cursor_visible; - ctx->last_cursor_change = now; - } - if (ctx->cursor_length > 0) { - /* We'll show a highlight */ - SDL_SetRenderDrawBlendMode(renderer, highlight_mode); - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - SDL_RenderFillRect(renderer, &cursorRect); - SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); - } else if (ctx->cursor_visible) { - SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a); - SDL_RenderFillRect(renderer, &cursorRect); + if (SDL_TextInputActive(ctx->window)) { + Uint64 now = SDL_GetTicks(); + if ((now - ctx->last_cursor_change) >= CURSOR_BLINK_INTERVAL_MS) { + ctx->cursor_visible = !ctx->cursor_visible; + ctx->last_cursor_change = now; + } + if (ctx->cursor_length > 0) { + /* We'll show a highlight */ + SDL_SetRenderDrawBlendMode(renderer, highlight_mode); + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderFillRect(renderer, &cursorRect); + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); + } else if (ctx->cursor_visible) { + SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a); + SDL_RenderFillRect(renderer, &cursorRect); + } } /* Draw the candidates */ @@ -912,6 +918,9 @@ static void Redraw(void) RedrawWindow(&windowstate[i]); + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderDebugTextFormat(renderer, 4, 4, "Window %d", 1 + i); + SDL_RenderPresent(renderer); } } @@ -1076,6 +1085,19 @@ int main(int argc, char *argv[]) } break; default: + if ((event.key.mod & SDL_KMOD_CTRL) && (event.key.key >= SDLK_KP_1 && event.key.key <= SDLK_KP_9)) { + int index = (event.key.key - SDLK_KP_1); + if (index < state->num_windows) { + SDL_Window *window = state->windows[index]; + if (SDL_TextInputActive(window)) { + SDL_Log("Disabling text input for window %d\n", 1 + index); + SDL_StopTextInput(window); + } else { + SDL_Log("Enabling text input for window %d\n", 1 + index); + SDL_StartTextInput(window); + } + } + } break; }