Path: blob/master/thirdparty/sdl/core/linux/SDL_ime.c
10279 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#include "SDL_ime.h"23#include "SDL_ibus.h"24#include "SDL_fcitx.h"2526typedef bool (*SDL_IME_Init_t)(void);27typedef void (*SDL_IME_Quit_t)(void);28typedef void (*SDL_IME_SetFocus_t)(bool);29typedef void (*SDL_IME_Reset_t)(void);30typedef bool (*SDL_IME_ProcessKeyEvent_t)(Uint32, Uint32, bool down);31typedef void (*SDL_IME_UpdateTextInputArea_t)(SDL_Window *window);32typedef void (*SDL_IME_PumpEvents_t)(void);3334static SDL_IME_Init_t SDL_IME_Init_Real = NULL;35static SDL_IME_Quit_t SDL_IME_Quit_Real = NULL;36static SDL_IME_SetFocus_t SDL_IME_SetFocus_Real = NULL;37static SDL_IME_Reset_t SDL_IME_Reset_Real = NULL;38static SDL_IME_ProcessKeyEvent_t SDL_IME_ProcessKeyEvent_Real = NULL;39static SDL_IME_UpdateTextInputArea_t SDL_IME_UpdateTextInputArea_Real = NULL;40static SDL_IME_PumpEvents_t SDL_IME_PumpEvents_Real = NULL;4142static void InitIME(void)43{44static bool inited = false;45#ifdef HAVE_FCITX46const char *im_module = SDL_getenv("SDL_IM_MODULE");47const char *xmodifiers = SDL_getenv("XMODIFIERS");48#endif4950if (inited == true) {51return;52}5354inited = true;5556// See if fcitx IME support is being requested57#ifdef HAVE_FCITX58if (!SDL_IME_Init_Real &&59((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||60(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {61SDL_IME_Init_Real = SDL_Fcitx_Init;62SDL_IME_Quit_Real = SDL_Fcitx_Quit;63SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;64SDL_IME_Reset_Real = SDL_Fcitx_Reset;65SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;66SDL_IME_UpdateTextInputArea_Real = SDL_Fcitx_UpdateTextInputArea;67SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;68}69#endif // HAVE_FCITX7071// default to IBus72#ifdef HAVE_IBUS_IBUS_H73if (!SDL_IME_Init_Real) {74SDL_IME_Init_Real = SDL_IBus_Init;75SDL_IME_Quit_Real = SDL_IBus_Quit;76SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;77SDL_IME_Reset_Real = SDL_IBus_Reset;78SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;79SDL_IME_UpdateTextInputArea_Real = SDL_IBus_UpdateTextInputArea;80SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;81}82#endif // HAVE_IBUS_IBUS_H83}8485bool SDL_IME_Init(void)86{87InitIME();8889if (SDL_IME_Init_Real) {90if (SDL_IME_Init_Real()) {91return true;92}9394// uhoh, the IME implementation's init failed! Disable IME support.95SDL_IME_Init_Real = NULL;96SDL_IME_Quit_Real = NULL;97SDL_IME_SetFocus_Real = NULL;98SDL_IME_Reset_Real = NULL;99SDL_IME_ProcessKeyEvent_Real = NULL;100SDL_IME_UpdateTextInputArea_Real = NULL;101SDL_IME_PumpEvents_Real = NULL;102}103104return false;105}106107void SDL_IME_Quit(void)108{109if (SDL_IME_Quit_Real) {110SDL_IME_Quit_Real();111}112}113114void SDL_IME_SetFocus(bool focused)115{116if (SDL_IME_SetFocus_Real) {117SDL_IME_SetFocus_Real(focused);118}119}120121void SDL_IME_Reset(void)122{123if (SDL_IME_Reset_Real) {124SDL_IME_Reset_Real();125}126}127128bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode, bool down)129{130if (SDL_IME_ProcessKeyEvent_Real) {131return SDL_IME_ProcessKeyEvent_Real(keysym, keycode, down);132}133134return false;135}136137void SDL_IME_UpdateTextInputArea(SDL_Window *window)138{139if (SDL_IME_UpdateTextInputArea_Real) {140SDL_IME_UpdateTextInputArea_Real(window);141}142}143144void SDL_IME_PumpEvents(void)145{146if (SDL_IME_PumpEvents_Real) {147SDL_IME_PumpEvents_Real();148}149}150151152