diff options
author | JiDe Zhang <[email protected]> | 2023-12-18 14:57:28 +0800 |
---|---|---|
committer | JiDe Zhang <[email protected]> | 2024-03-05 12:26:10 +0800 |
commit | 8596998cb025a8338c9403f5ef9db5a23f5cc682 (patch) | |
tree | bae414b15b5adc0524d4e4bb6c0b1a2e35f13fe8 /src/gui/kernel/qplatforminputcontextfactory.cpp | |
parent | ca4774131b9b8ee40b4d7f5c1ba296af4700207f (diff) |
Add QT_IM_MODULES env to allows specify multi IM key
Like as QT_QPA_PLATFORM, supports specifying multiple keys, and can
perform fallback operations to prioritize the use of a certain plug-in.
This is useful when using Wayland and XWayland applications at the same
time. For an example, we can set "QT_IM_MODULES=wayland;fcitx", and the
wayland application will use the wayland input context plugin, the
xwayland application will use fcitx, which can't be done without adding
a new environment variable, if we specify "QT_IM_MODULE=wayland", the
XWayland applications may not be able to use the input method.
Fixes: QTBUG-120202
Change-Id: Iac408af241963147747a2fe685f1e27bf9d9ee64
Reviewed-by: Liang Qi <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: David Edmundson <[email protected]>
Diffstat (limited to 'src/gui/kernel/qplatforminputcontextfactory.cpp')
-rw-r--r-- | src/gui/kernel/qplatforminputcontextfactory.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gui/kernel/qplatforminputcontextfactory.cpp b/src/gui/kernel/qplatforminputcontextfactory.cpp index 7074de56afa..933d990f7c9 100644 --- a/src/gui/kernel/qplatforminputcontextfactory.cpp +++ b/src/gui/kernel/qplatforminputcontextfactory.cpp @@ -28,10 +28,33 @@ QStringList QPlatformInputContextFactory::keys() #endif } -QString QPlatformInputContextFactory::requested() +QStringList QPlatformInputContextFactory::requested() { - QByteArray env = qgetenv("QT_IM_MODULE"); - return env.isNull() ? QString() : QString::fromLocal8Bit(env); + QStringList imList; + QByteArray env = qgetenv("QT_IM_MODULES"); + + if (!env.isEmpty()) + imList = QString::fromLocal8Bit(env).split(QChar::fromLatin1(';'), Qt::SkipEmptyParts); + + if (!imList.isEmpty()) + return imList; + + env = qgetenv("QT_IM_MODULE"); + if (!env.isEmpty()) + imList = {QString::fromLocal8Bit(env)}; + + return imList; +} + +QPlatformInputContext *QPlatformInputContextFactory::create(const QStringList& keys) +{ + for (const QString &key : keys) { + auto plugin = create(key); + if (plugin) + return plugin; + } + + return nullptr; } QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key) |