Fcitx: Fix edge cases around text handling and setup

This commit is contained in:
Jonathan G Rennison
2019-10-12 00:20:07 +01:00
parent 641b008374
commit 29ed470e04

View File

@@ -194,7 +194,8 @@ static void FcitxInit()
dbus_connection_send(_fcitx_dbus_session_conn, msg2, NULL); dbus_connection_send(_fcitx_dbus_session_conn, msg2, NULL);
dbus_connection_flush(_fcitx_dbus_session_conn); dbus_connection_flush(_fcitx_dbus_session_conn);
SDL_EventState(SDL_SYSWMEVENT, 1); setenv("SDL_IM_MODULE", "N/A", true);
setenv("IBUS_ADDRESS", "/dev/null/invalid", true);
_fcitx_mode = true; _fcitx_mode = true;
} }
@@ -555,26 +556,6 @@ bool VideoDriver_SDL::ClaimMousePointer()
return true; return true;
} }
static void StartTextInput()
{
#if defined(WITH_FCITX)
if (_fcitx_mode) {
return;
}
#endif
SDL_StartTextInput();
}
static void StopTextInput()
{
#if defined(WITH_FCITX)
if (_fcitx_mode) {
return;
}
#endif
SDL_StopTextInput();
}
static void SetTextInputRect() static void SetTextInputRect()
{ {
SDL_Rect winrect; SDL_Rect winrect;
@@ -625,9 +606,7 @@ static void SetTextInputRect()
void VideoDriver_SDL::EditBoxGainedFocus() void VideoDriver_SDL::EditBoxGainedFocus()
{ {
if (!this->edit_box_focused) { if (!this->edit_box_focused) {
if (!_fcitx_mode) { SDL_StartTextInput();
StartTextInput();
}
this->edit_box_focused = true; this->edit_box_focused = true;
} }
SetTextInputRect(); SetTextInputRect();
@@ -641,9 +620,8 @@ void VideoDriver_SDL::EditBoxLostFocus()
FcitxICMethod("Reset"); FcitxICMethod("Reset");
FcitxICMethod("CloseIC"); FcitxICMethod("CloseIC");
#endif #endif
} else {
StopTextInput();
} }
SDL_StopTextInput();
this->edit_box_focused = false; this->edit_box_focused = false;
} }
/* Clear any marked string from the current edit box. */ /* Clear any marked string from the current edit box. */
@@ -781,6 +759,7 @@ static uint ConvertSdlKeycodeIntoMy(SDL_Keycode kc)
return key; return key;
} }
static bool suppress_text_event = false;
int VideoDriver_SDL::PollEvent() int VideoDriver_SDL::PollEvent()
{ {
#if defined(WITH_FCITX) #if defined(WITH_FCITX)
@@ -845,11 +824,13 @@ int VideoDriver_SDL::PollEvent()
break; break;
case SDL_KEYDOWN: // Toggle full-screen on ALT + ENTER/F case SDL_KEYDOWN: // Toggle full-screen on ALT + ENTER/F
suppress_text_event = false;
#if defined(WITH_FCITX) #if defined(WITH_FCITX)
if (_fcitx_mode && EditBoxInGlobalFocus() && !(FocusedWindowIsConsole() && if (_fcitx_mode && EditBoxInGlobalFocus() && !(FocusedWindowIsConsole() &&
ConvertSdlKeycodeIntoMy(SDL_GetKeyFromName(ev.text.text)) == WKC_BACKQUOTE)) { ev.key.keysym.scancode == SDL_SCANCODE_GRAVE)) {
if (FcitxProcessKey(ev.key.keysym)) { if (FcitxProcessKey(ev.key.keysym)) {
/* key press handled by Fcitx */ /* key press handled by Fcitx */
suppress_text_event = true;
break; break;
} }
} }
@@ -873,14 +854,14 @@ int VideoDriver_SDL::PollEvent()
keycode & WKC_ALT || keycode & WKC_ALT ||
(keycode >= WKC_F1 && keycode <= WKC_F12) || (keycode >= WKC_F1 && keycode <= WKC_F12) ||
!IsValidChar(character, CS_ALPHANUMERAL) || !IsValidChar(character, CS_ALPHANUMERAL) ||
!this->edit_box_focused || !this->edit_box_focused) {
_fcitx_mode) {
HandleKeypress(keycode, character); HandleKeypress(keycode, character);
} }
} }
break; break;
case SDL_TEXTINPUT: { case SDL_TEXTINPUT: {
if (suppress_text_event) break;
if (EditBoxInGlobalFocus() && !(FocusedWindowIsConsole() && if (EditBoxInGlobalFocus() && !(FocusedWindowIsConsole() &&
ConvertSdlKeycodeIntoMy(SDL_GetKeyFromName(ev.text.text)) == WKC_BACKQUOTE)) { ConvertSdlKeycodeIntoMy(SDL_GetKeyFromName(ev.text.text)) == WKC_BACKQUOTE)) {
HandleTextInput(nullptr, true); HandleTextInput(nullptr, true);
@@ -948,6 +929,10 @@ int VideoDriver_SDL::PollEvent()
const char *VideoDriver_SDL::Start(const char * const *parm) const char *VideoDriver_SDL::Start(const char * const *parm)
{ {
#if defined(WITH_FCITX)
FcitxInit();
#endif
/* Explicitly disable hardware acceleration. Enabling this causes /* Explicitly disable hardware acceleration. Enabling this causes
* UpdateWindowSurface() to update the window's texture instead of * UpdateWindowSurface() to update the window's texture instead of
* its surface. */ * its surface. */
@@ -978,7 +963,7 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
this->edit_box_focused = false; this->edit_box_focused = false;
#if defined(WITH_FCITX) #if defined(WITH_FCITX)
FcitxInit(); if (_fcitx_mode) SDL_EventState(SDL_SYSWMEVENT, 1);
#endif #endif
return nullptr; return nullptr;