linux: Don't crash if fcitx support is requested but unavailable.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 29 May 2017 02:48:51 -0400
changeset 11053dc895d39212c
parent 11052 0666dea591ab
child 11054 0092cb66f341
linux: Don't crash if fcitx support is requested but unavailable.

Fixes Bugzilla #3642.
src/core/linux/SDL_fcitx.c
src/core/linux/SDL_ime.c
     1.1 --- a/src/core/linux/SDL_fcitx.c	Mon May 29 00:51:38 2017 -0400
     1.2 +++ b/src/core/linux/SDL_fcitx.c	Mon May 29 02:48:51 2017 -0400
     1.3 @@ -188,7 +188,7 @@
     1.4      SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, "SetCapacity", DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
     1.5  }
     1.6  
     1.7 -static void
     1.8 +static SDL_bool
     1.9  FcitxClientCreateIC(FcitxClient *client)
    1.10  {
    1.11      char *appname = GetAppName();
    1.12 @@ -196,9 +196,11 @@
    1.13      int id = -1;
    1.14      Uint32 enable, arg1, arg2, arg3, arg4;
    1.15  
    1.16 -    SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
    1.17 -        DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
    1.18 -        DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID);
    1.19 +    if (!SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
    1.20 +            DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
    1.21 +            DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID)) {
    1.22 +        id = -1;  /* just in case. */
    1.23 +    }
    1.24  
    1.25      SDL_free(appname);
    1.26  
    1.27 @@ -218,7 +220,10 @@
    1.28          dbus->connection_flush(dbus->session_conn);
    1.29  
    1.30          SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, &Fcitx_SetCapabilities, client);
    1.31 +        return SDL_TRUE;
    1.32      }
    1.33 +
    1.34 +    return SDL_FALSE;
    1.35  }
    1.36  
    1.37  static Uint32
    1.38 @@ -252,9 +257,7 @@
    1.39              "%s-%d",
    1.40              FCITX_DBUS_SERVICE, GetDisplayNumber());
    1.41  
    1.42 -    FcitxClientCreateIC(&fcitx_client);
    1.43 -
    1.44 -    return SDL_TRUE;
    1.45 +    return FcitxClientCreateIC(&fcitx_client);
    1.46  }
    1.47  
    1.48  void
     2.1 --- a/src/core/linux/SDL_ime.c	Mon May 29 00:51:38 2017 -0400
     2.2 +++ b/src/core/linux/SDL_ime.c	Mon May 29 02:48:51 2017 -0400
     2.3 @@ -87,8 +87,20 @@
     2.4  {
     2.5      InitIME();
     2.6  
     2.7 -    if (SDL_IME_Init_Real)
     2.8 -        return SDL_IME_Init_Real();
     2.9 +    if (SDL_IME_Init_Real) {
    2.10 +        if (SDL_IME_Init_Real()) {
    2.11 +            return SDL_TRUE;
    2.12 +        }
    2.13 +
    2.14 +        /* uhoh, the IME implementation's init failed! Disable IME support. */
    2.15 +        SDL_IME_Init_Real = NULL;
    2.16 +        SDL_IME_Quit_Real = NULL;
    2.17 +        SDL_IME_SetFocus_Real = NULL;
    2.18 +        SDL_IME_Reset_Real = NULL;
    2.19 +        SDL_IME_ProcessKeyEvent_Real = NULL;
    2.20 +        SDL_IME_UpdateTextRect_Real = NULL;
    2.21 +        SDL_IME_PumpEvents_Real = NULL;
    2.22 +    }
    2.23  
    2.24      return SDL_FALSE;
    2.25  }