Linux/SDL2 - FIRE-32214 - Add checkbox to Preferences/General to enable or disable IME text input, so regular keyboard input will not be affected

master
Zi Ree 2022-09-26 02:02:12 +02:00
parent 02d9ba16c8
commit 07c9d38526
7 changed files with 98 additions and 3 deletions

View File

@ -393,6 +393,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks,
// IME - International input compositing, i.e. for Japanese / Chinese text input
// Preeditor means here the actual XUI input field currently in use
mIMEEnabled = false;
mPreeditor = nullptr;
#if LL_X11
@ -661,7 +662,10 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B
// IME - International input compositing, i.e. for Japanese / Chinese text input
// Request the IME interface to show over-the-top compositing while typing
SDL_SetHint( SDL_HINT_IME_INTERNAL_EDITING, "1");
if (mIMEEnabled)
{
SDL_SetHint( SDL_HINT_IME_INTERNAL_EDITING, "1");
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
{
@ -883,7 +887,12 @@ BOOL LLWindowSDL::createContext(int x, int y, int width, int height, int bits, B
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(mWindow);
SDL_StartTextInput();
// start text input immediately when IME is not enabled
if (!mIMEEnabled)
{
SDL_StartTextInput();
}
//make sure multisampling is disabled by default
glDisable(GL_MULTISAMPLE_ARB);
@ -1821,7 +1830,7 @@ void LLWindowSDL::gatherInput()
mKeyVirtualKey = SDLK_RETURN;
}
if (mKeyVirtualKey == SDLK_RETURN)
if (mKeyVirtualKey == SDLK_RETURN && mIMEEnabled)
{
// block spurious enter key events that break up IME entered lines in teh wrong places
U64 eventTimeDiff = LLFrameTimer::getTotalTime() - previousTextinputTime;
@ -2670,11 +2679,32 @@ void LLWindowSDL::toggleVSync(bool enable_vsync)
}
// </FS:Zi>
void LLWindowSDL::enableIME(bool b)
{
mIMEEnabled = b;
if (mIMEEnabled)
{
SDL_SetHint( SDL_HINT_IME_INTERNAL_EDITING, "1");
SDL_StopTextInput();
}
else
{
SDL_SetHint( SDL_HINT_IME_INTERNAL_EDITING, "0");
SDL_StartTextInput();
}
}
// IME - International input compositing, i.e. for Japanese / Chinese text input
// Put the IME window at the right place (near current text input).
// Point coordinates should be the top of the current text line.
void LLWindowSDL::setLanguageTextInput(const LLCoordGL& position)
{
if (!mIMEEnabled)
{
return;
}
LLCoordWindow win_pos;
convertCoords( position, &win_pos );
@ -2690,6 +2720,11 @@ void LLWindowSDL::setLanguageTextInput(const LLCoordGL& position)
// IME - International input compositing, i.e. for Japanese / Chinese text input
void LLWindowSDL::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b)
{
if (!mIMEEnabled)
{
return;
}
if (preeditor != mPreeditor && !b)
{
// This condition may occur with a call to

View File

@ -136,6 +136,8 @@ public:
/*virtual*/ void setTitle(const std::string& title);
void enableIME(bool b);
static std::vector<std::string> getDynamicFallbackFontList();
// Not great that these are public, but they have to be accessible
@ -205,6 +207,7 @@ protected:
SDL_GLContext mContext;
SDL_Cursor* mSDLCursors[UI_CURSOR_COUNT];
LLPreeditor* mPreeditor;
bool mIMEEnabled;
std::string mWindowTitle;
double mOriginalAspectRatio;

View File

@ -26247,6 +26247,17 @@ Change of this parameter will affect the layout of buttons in notification toast
<key>Value</key>
<integer>-4</integer>
</map>
<key>SDL2IMEEnabled</key>
<map>
<key>Comment</key>
<string>Enable the international input method editor for Japanese, Chinese, etc.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>0</integer>
</map>
<key>FSLocalMeshScaleAlwaysMeters</key>
<map>
<key>Comment</key>

View File

@ -1292,6 +1292,12 @@ void FSChatHistory::setFocus(BOOL b)
{
LLTextEditor::setFocus(b);
// IME - Don't do anything here if IME is disabled
if (!gSavedSettings.getBOOL("SDL2IMEEnabled"))
{
return;
}
// IME - International input compositing, i.e. for Japanese / Chinese text input
updateChatInputLine();

View File

@ -805,6 +805,12 @@ BOOL LLFloaterPreference::postBuild()
mPopupFilter = getChild<LLFilterEditor>("popup_filter");
// </FS:Zi>
// <FS:Zi> SDL2 IME support
#if LL_SDL2
childSetVisible("use_ime", true);
#endif
// </FS:Zi>
return TRUE;
}

View File

@ -32,6 +32,12 @@
// Library includes
#include "llwindow.h" // getGamma()
// <FS:Zi> Handle IME text input getting enabled or disabled
#if LL_SDL2
#include "llwindowsdl2.h"
#endif
// </FS:Zi>
// For Listeners
#include "llaudioengine.h"
#include "llagent.h"
@ -1140,6 +1146,17 @@ void handleFPSTuningStrategyChanged(const LLSD& newValue)
// </FS:Beq>
// <FS:Zi> Handle IME text input getting enabled or disabled
#if LL_SDL2
static bool handleSDL2IMEEnabledChanged(const LLSD& newvalue)
{
((LLWindowSDL*)gViewerWindow->getWindow())->enableIME(newvalue.asBoolean());
return true;
}
#endif
// </FS:Zi>
////////////////////////////////////////////////////////////////////////////
void settings_setup_listeners()
@ -1406,6 +1423,12 @@ void settings_setup_listeners()
gSavedSettings.getControl("FSAutoTuneImpostorByDistEnabled")->getSignal()->connect(boost::bind(&handleUserImpostorByDistEnabledChanged, _2));
gSavedSettings.getControl("FSTuningFPSStrategy")->getSignal()->connect(boost::bind(&handleFPSTuningStrategyChanged, _2));
// </FS:Beq>
// <FS:Zi> Handle IME text input getting enabled or disabled
#if LL_SDL2
gSavedSettings.getControl("SDL2IMEEnabled")->getSignal()->connect(boost::bind(&handleSDL2IMEEnabledChanged, _2));
#endif
// </FS:Zi>
}
#if TEST_CACHED_CONTROL

View File

@ -114,6 +114,17 @@
width="130">
(Requires restart)
</text>
<check_box
control_name="SDL2IMEEnabled"
height="16"
label="Use IME Text Input"
layout="topleft"
left_pad="5"
name="use_ime"
top_delta="5"
width="256"
visible="false"
tool_tip="Use the international input method editor, only needed for specific languages like Japanese, Chinese, etc." />
<!--maturity-->
<text
type="string"