mirror of https://github.com/encounter/SDL.git
Improvements to the IBus related code:
+ Handle HidePreeditText IBus signal. + Use SDL_GetKeyboardFocus instead of SDL_GetFocusWindow. + Move the X11 IBus SetFocus calls to the X11_DispatchFocus functions. + Simplify the IBus ifdefs when handling X11 KeyEvents. + Remove inotify watch when SDL_IBus_Quit is called.
This commit is contained in:
parent
6f84f37c0a
commit
f4ddacf425
|
@ -45,7 +45,7 @@ static char *input_ctx_path = NULL;
|
|||
static SDL_Rect ibus_cursor_rect = {0};
|
||||
static DBusConnection *ibus_conn = NULL;
|
||||
static char *ibus_addr_file = NULL;
|
||||
int inotify_fd = -1;
|
||||
int inotify_fd = -1, inotify_wd = -1;
|
||||
|
||||
static Uint32
|
||||
IBus_ModState(void)
|
||||
|
@ -166,8 +166,6 @@ IBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
|||
i += sz;
|
||||
cursor += chars;
|
||||
}
|
||||
} else {
|
||||
SDL_SendEditingText("", 0, 0);
|
||||
}
|
||||
|
||||
SDL_IBus_UpdateTextRect(NULL);
|
||||
|
@ -175,6 +173,11 @@ IBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data)
|
|||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "HidePreeditText")){
|
||||
SDL_SendEditingText("", 0, 0);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
|
@ -360,7 +363,7 @@ IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
|
|||
dbus->connection_flush(ibus_conn);
|
||||
}
|
||||
|
||||
SDL_IBus_SetFocus(SDL_GetFocusWindow() != NULL);
|
||||
SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
|
||||
SDL_IBus_UpdateTextRect(NULL);
|
||||
|
||||
return result;
|
||||
|
@ -375,7 +378,7 @@ IBus_CheckConnection(SDL_DBusContext *dbus)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
if(inotify_fd != -1){
|
||||
if(inotify_fd > 0 && inotify_wd > 0){
|
||||
char buf[1024];
|
||||
ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
|
||||
if(readsize > 0){
|
||||
|
@ -428,15 +431,17 @@ SDL_IBus_Init(void)
|
|||
|
||||
char *addr = IBus_ReadAddressFromFile(addr_file);
|
||||
|
||||
inotify_fd = inotify_init();
|
||||
fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
|
||||
if(inotify_fd < 0){
|
||||
inotify_fd = inotify_init();
|
||||
fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
|
||||
}
|
||||
|
||||
char *addr_file_dir = SDL_strrchr(addr_file, '/');
|
||||
if(addr_file_dir){
|
||||
*addr_file_dir = 0;
|
||||
}
|
||||
|
||||
inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
|
||||
inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
|
||||
SDL_free(addr_file);
|
||||
|
||||
result = IBus_SetupConnection(dbus, addr);
|
||||
|
@ -466,6 +471,11 @@ SDL_IBus_Quit(void)
|
|||
dbus->connection_unref(ibus_conn);
|
||||
}
|
||||
|
||||
if(inotify_fd > 0 && inotify_wd > 0){
|
||||
inotify_rm_watch(inotify_fd, inotify_wd);
|
||||
inotify_wd = -1;
|
||||
}
|
||||
|
||||
SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
|
||||
}
|
||||
|
||||
|
@ -548,7 +558,7 @@ SDL_IBus_UpdateTextRect(SDL_Rect *rect)
|
|||
SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
|
||||
}
|
||||
|
||||
SDL_Window *focused_win = SDL_GetFocusWindow();
|
||||
SDL_Window *focused_win = SDL_GetKeyboardFocus();
|
||||
|
||||
if(!focused_win) return;
|
||||
|
||||
|
|
|
@ -347,6 +347,9 @@ X11_DispatchFocusIn(SDL_WindowData *data)
|
|||
X11_XSetICFocus(data->ic);
|
||||
}
|
||||
#endif
|
||||
#ifdef SDL_USE_IBUS
|
||||
SDL_IBus_SetFocus(SDL_TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -367,6 +370,9 @@ X11_DispatchFocusOut(SDL_WindowData *data)
|
|||
X11_XUnsetICFocus(data->ic);
|
||||
}
|
||||
#endif
|
||||
#ifdef SDL_USE_IBUS
|
||||
SDL_IBus_SetFocus(SDL_FALSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -646,11 +652,6 @@ X11_DispatchEvent(_THIS)
|
|||
}
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: FocusIn!\n", data);
|
||||
#endif
|
||||
#ifdef SDL_USE_IBUS
|
||||
if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
|
||||
SDL_IBus_SetFocus(SDL_TRUE);
|
||||
}
|
||||
#endif
|
||||
if (data->pending_focus == PENDING_FOCUS_OUT &&
|
||||
data->window == SDL_GetKeyboardFocus()) {
|
||||
|
@ -688,11 +689,6 @@ X11_DispatchEvent(_THIS)
|
|||
}
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: FocusOut!\n", data);
|
||||
#endif
|
||||
#ifdef SDL_USE_IBUS
|
||||
if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
|
||||
SDL_IBus_SetFocus(SDL_FALSE);
|
||||
}
|
||||
#endif
|
||||
data->pending_focus = PENDING_FOCUS_OUT;
|
||||
data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_OUT_TIME;
|
||||
|
@ -725,16 +721,11 @@ X11_DispatchEvent(_THIS)
|
|||
KeySym keysym = NoSymbol;
|
||||
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
|
||||
Status status = 0;
|
||||
#ifdef SDL_USE_IBUS
|
||||
Bool handled = False;
|
||||
#endif
|
||||
SDL_bool handled_by_ime = SDL_FALSE;
|
||||
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
|
||||
#endif
|
||||
#ifndef SDL_USE_IBUS
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
|
||||
#endif
|
||||
#if 1
|
||||
if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN && keycode) {
|
||||
int min_keycode, max_keycode;
|
||||
|
@ -762,7 +753,7 @@ X11_DispatchEvent(_THIS)
|
|||
#endif
|
||||
#ifdef SDL_USE_IBUS
|
||||
if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
|
||||
if(!(handled = SDL_IBus_ProcessKeyEvent(keysym, keycode))){
|
||||
if(!(handled_by_ime = SDL_IBus_ProcessKeyEvent(keysym, keycode))){
|
||||
#endif
|
||||
if(*text){
|
||||
SDL_SendKeyboardText(text);
|
||||
|
@ -770,11 +761,11 @@ X11_DispatchEvent(_THIS)
|
|||
#ifdef SDL_USE_IBUS
|
||||
}
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
#endif
|
||||
if (!handled_by_ime) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -332,9 +332,7 @@ X11_QuitKeyboard(_THIS)
|
|||
void
|
||||
X11_StartTextInput(_THIS)
|
||||
{
|
||||
#ifdef SDL_USE_IBUS
|
||||
SDL_IBus_SetFocus(SDL_GetFocusWindow() != NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue