SDL  2.0
SDL_ime.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #include "SDL_ime.h"
23 #include "SDL_ibus.h"
24 #include "SDL_fcitx.h"
25 
26 typedef SDL_bool (*_SDL_IME_Init)();
27 typedef void (*_SDL_IME_Quit)();
29 typedef void (*_SDL_IME_Reset)();
33 
41 
42 static void
44 {
45  static SDL_bool inited = SDL_FALSE;
46 #ifdef HAVE_FCITX_FRONTEND_H
47  const char *im_module = SDL_getenv("SDL_IM_MODULE");
48  const char *xmodifiers = SDL_getenv("XMODIFIERS");
49 #endif
50 
51  if (inited == SDL_TRUE)
52  return;
53 
54  inited = SDL_TRUE;
55 
56  /* See if fcitx IME support is being requested */
57 #ifdef HAVE_FCITX_FRONTEND_H
58  if (!SDL_IME_Init_Real &&
59  ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
60  (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
68  }
69 #endif /* HAVE_FCITX_FRONTEND_H */
70 
71  /* default to IBus */
72 #ifdef HAVE_IBUS_IBUS_H
73  if (!SDL_IME_Init_Real) {
74  SDL_IME_Init_Real = SDL_IBus_Init;
75  SDL_IME_Quit_Real = SDL_IBus_Quit;
76  SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
77  SDL_IME_Reset_Real = SDL_IBus_Reset;
78  SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
79  SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
80  SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
81  }
82 #endif /* HAVE_IBUS_IBUS_H */
83 }
84 
87 {
88  InitIME();
89 
90  if (SDL_IME_Init_Real) {
91  if (SDL_IME_Init_Real()) {
92  return SDL_TRUE;
93  }
94 
95  /* uhoh, the IME implementation's init failed! Disable IME support. */
103  }
104 
105  return SDL_FALSE;
106 }
107 
108 void
110 {
111  if (SDL_IME_Quit_Real)
113 }
114 
115 void
117 {
119  SDL_IME_SetFocus_Real(focused);
120 }
121 
122 void
124 {
125  if (SDL_IME_Reset_Real)
127 }
128 
129 SDL_bool
131 {
133  return SDL_IME_ProcessKeyEvent_Real(keysym, keycode);
134 
135  return SDL_FALSE;
136 }
137 
138 void
140 {
143 }
144 
145 void
147 {
150 }
151 
152 /* vi: set ts=4 sw=4 expandtab: */
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
_SDL_IME_Reset
void(* _SDL_IME_Reset)()
Definition: SDL_ime.c:29
SDL_IME_UpdateTextRect_Real
static _SDL_IME_UpdateTextRect SDL_IME_UpdateTextRect_Real
Definition: SDL_ime.c:39
SDL_IME_Reset
void SDL_IME_Reset(void)
Definition: SDL_ime.c:123
NULL
#define NULL
Definition: begin_code.h:167
SDL_Fcitx_UpdateTextRect
void SDL_Fcitx_UpdateTextRect(SDL_Rect *rect)
InitIME
static void InitIME()
Definition: SDL_ime.c:43
_SDL_IME_Init
SDL_bool(* _SDL_IME_Init)()
Definition: SDL_ime.c:26
SDL_IME_SetFocus_Real
static _SDL_IME_SetFocus SDL_IME_SetFocus_Real
Definition: SDL_ime.c:36
SDL_IME_Init
SDL_bool SDL_IME_Init(void)
Definition: SDL_ime.c:86
_SDL_IME_ProcessKeyEvent
SDL_bool(* _SDL_IME_ProcessKeyEvent)(Uint32, Uint32)
Definition: SDL_ime.c:30
SDL_IME_Reset_Real
static _SDL_IME_Reset SDL_IME_Reset_Real
Definition: SDL_ime.c:37
SDL_Fcitx_Init
SDL_bool SDL_Fcitx_Init(void)
SDL_IME_ProcessKeyEvent
SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
Definition: SDL_ime.c:130
SDL_ibus.h
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
_SDL_IME_UpdateTextRect
void(* _SDL_IME_UpdateTextRect)(SDL_Rect *)
Definition: SDL_ime.c:31
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_IME_SetFocus
void SDL_IME_SetFocus(SDL_bool focused)
Definition: SDL_ime.c:116
SDL_Fcitx_Reset
void SDL_Fcitx_Reset(void)
SDL_Fcitx_PumpEvents
void SDL_Fcitx_PumpEvents(void)
SDL_IME_PumpEvents_Real
static _SDL_IME_PumpEvents SDL_IME_PumpEvents_Real
Definition: SDL_ime.c:40
SDL_Fcitx_Quit
void SDL_Fcitx_Quit(void)
SDL_fcitx.h
SDL_IME_Quit_Real
static _SDL_IME_Quit SDL_IME_Quit_Real
Definition: SDL_ime.c:35
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:378
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_Fcitx_SetFocus
void SDL_Fcitx_SetFocus(SDL_bool focused)
SDL_IME_ProcessKeyEvent_Real
static _SDL_IME_ProcessKeyEvent SDL_IME_ProcessKeyEvent_Real
Definition: SDL_ime.c:38
SDL_IME_Quit
void SDL_IME_Quit(void)
Definition: SDL_ime.c:109
SDL_Rect
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:77
SDL_Fcitx_ProcessKeyEvent
SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
SDL_IME_UpdateTextRect
void SDL_IME_UpdateTextRect(SDL_Rect *rect)
Definition: SDL_ime.c:139
_SDL_IME_SetFocus
void(* _SDL_IME_SetFocus)(SDL_bool)
Definition: SDL_ime.c:28
_SDL_IME_Quit
void(* _SDL_IME_Quit)()
Definition: SDL_ime.c:27
SDL_IME_Init_Real
static _SDL_IME_Init SDL_IME_Init_Real
Definition: SDL_ime.c:34
SDL_strcmp
#define SDL_strcmp
Definition: SDL_dynapi_overrides.h:417
void
const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char const char const SDL_SCANF_FORMAT_STRING char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
SDL_strstr
#define SDL_strstr
Definition: SDL_dynapi_overrides.h:403
SDL_IME_PumpEvents
void SDL_IME_PumpEvents()
Definition: SDL_ime.c:146
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
_SDL_IME_PumpEvents
void(* _SDL_IME_PumpEvents)()
Definition: SDL_ime.c:32
SDL_ime.h