# HG changeset patch # User Alex Baines # Date 1408487510 -3600 # Node ID bda9fa101b9f76b91bbd200e5e7af9aa9c806904 # Parent d515a63aaec4bf628a1d1e3b997bebd70192bbd3 Add a SDL_IM_INTERNAL_EDITING event to make IMs like iBus render editing text in its own UI instead of sending TEXTEDITING events. This is useful for applications that handle TEXTINPUT events but not TEXTEDITING events. diff -r d515a63aaec4 -r bda9fa101b9f include/SDL_hints.h --- a/include/SDL_hints.h Tue Aug 19 23:17:28 2014 +0100 +++ b/include/SDL_hints.h Tue Aug 19 23:31:50 2014 +0100 @@ -477,6 +477,18 @@ */ #define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION" +/** + * \brief A variable to control whether certain IMs should handle text editing internally instead of sending TEXTEDITING events. + * + * + * The variable can be set to the following values: + * "0" - TEXTEDITING events are sent, and it is the application's + * responsibility to render the text from these events and + * differentiate it somehow from committed text. (default) + * "1" - If supported by the IM then TEXTEDITING events are not sent, + * and text that is being composed will be rendered in its own UI. + */ +#define SDL_HINT_IM_INTERNAL_EDITING "SDL_IM_INTERNAL_EDITING" /** * \brief An enumeration of hint priorities diff -r d515a63aaec4 -r bda9fa101b9f src/core/linux/SDL_ibus.c --- a/src/core/linux/SDL_ibus.c Tue Aug 19 23:17:28 2014 +0100 +++ b/src/core/linux/SDL_ibus.c Tue Aug 19 23:31:50 2014 +0100 @@ -288,6 +288,41 @@ return SDL_strdup(file_path); } +static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus); + +static void +IBus_SetCapabilities(void *data, const char *name, const char *old_val, + const char *internal_editing) +{ + SDL_DBusContext *dbus = SDL_DBus_GetContext(); + + if(IBus_CheckConnection(dbus)){ + + DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE, + input_ctx_path, + IBUS_INPUT_INTERFACE, + "SetCapabilities"); + if(msg){ + Uint32 caps = IBUS_CAP_FOCUS; + if(!(internal_editing && *internal_editing == '1')){ + caps |= IBUS_CAP_PREEDIT_TEXT; + } + + dbus->message_append_args(msg, + DBUS_TYPE_UINT32, &caps, + DBUS_TYPE_INVALID); + } + + if(msg){ + if(dbus->connection_send(ibus_conn, msg, NULL)){ + dbus->connection_flush(ibus_conn); + } + dbus->message_unref(msg); + } + } +} + + static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr) { @@ -340,23 +375,7 @@ } if(result){ - msg = dbus->message_new_method_call(IBUS_SERVICE, - input_ctx_path, - IBUS_INPUT_INTERFACE, - "SetCapabilities"); - if(msg){ - Uint32 caps = IBUS_CAP_FOCUS | IBUS_CAP_PREEDIT_TEXT; - dbus->message_append_args(msg, - DBUS_TYPE_UINT32, &caps, - DBUS_TYPE_INVALID); - } - - if(msg){ - if(dbus->connection_send(ibus_conn, msg, NULL)){ - dbus->connection_flush(ibus_conn); - } - dbus->message_unref(msg); - } + SDL_AddHintCallback(SDL_HINT_IM_INTERNAL_EDITING, &IBus_SetCapabilities, NULL); dbus->bus_add_match(ibus_conn, "type='signal',interface='org.freedesktop.IBus.InputContext'", NULL); dbus->connection_add_filter(ibus_conn, &IBus_MessageFilter, dbus, NULL); @@ -476,6 +495,8 @@ inotify_wd = -1; } + SDL_DelHintCallback(SDL_HINT_IM_INTERNAL_EDITING, &IBus_SetCapabilities, NULL); + SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect)); } @@ -548,6 +569,8 @@ } + SDL_IBus_UpdateTextRect(NULL); + return result; }