Harmonize input context selection
authorBernd Weimer <bernd.weimer@pelagicore.com>
Mon, 23 Mar 2015 10:53:16 +0000 (11:53 +0100)
committerBernd Weimer <bernd.weimer@pelagicore.com>
Tue, 25 Aug 2015 07:04:19 +0000 (07:04 +0000)
Input context selection works differently across platforms. On some
platforms it is not possible to request a specific context at all
(e.g. Wayland). This will be unified, depending on the environment
variable "QT_IM_MODULE", you will get:
- null:  default (platform) context, if defined (otherwise no context)
- empty: no context
- set:   set one, if it exists and is valid (otherwise no context)

[ChangeLog][Platform Specific Changes] Haromnized input context selection.
QT_IM_MODULE environment variable will be taken into account.

Change-Id: Ic8f826fbc6ace25941cd19b9b086943e848fbe01
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Nedim Hadzic <nedim.hadzic@pelagicore.com>
src/gui/kernel/qplatforminputcontextfactory.cpp
src/gui/kernel/qplatforminputcontextfactory_p.h
src/plugins/platforms/cocoa/qcocoaintegration.mm
src/plugins/platforms/windows/qwindowsintegration.cpp
src/plugins/platforms/xcb/qxcbconnection.cpp
src/plugins/platforms/xcb/qxcbintegration.cpp
tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp

index a7660e76aeb041c6ec26cc57296fc920fc0749c0..9d55b778ce4dbb641f0dc00814255d16b04915ee 100644 (file)
@@ -56,48 +56,32 @@ QStringList QPlatformInputContextFactory::keys()
 #endif
 }
 
-QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
+QString QPlatformInputContextFactory::requested()
 {
-    QStringList paramList = key.split(QLatin1Char(':'));
-    const QString platform = paramList.takeFirst().toLower();
-
-#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
-    if (QPlatformInputContext *ret = qLoadPlugin1<QPlatformInputContext, QPlatformInputContextPlugin>(loader(), platform, paramList))
-        return ret;
-#endif
-    return 0;
+    QByteArray env = qgetenv("QT_IM_MODULE");
+    return env.isNull() ? QString() : QString::fromLocal8Bit(env);
 }
 
-QPlatformInputContext *QPlatformInputContextFactory::create()
+QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key)
 {
-    QPlatformInputContext *ic = 0;
-
-    QString icString = QString::fromLatin1(qgetenv("QT_IM_MODULE"));
-
-    if (icString == QLatin1String("none"))
-        return 0;
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
+    QStringList paramList = key.split(QLatin1Char(':'));
+    const QString platform = paramList.takeFirst().toLower();
 
-    ic = create(icString);
+    QPlatformInputContext *ic = qLoadPlugin1<QPlatformInputContext, QPlatformInputContextPlugin>
+                                             (loader(), platform, paramList);
     if (ic && ic->isValid())
         return ic;
 
     delete ic;
-    ic = 0;
-
-    QStringList k = keys();
-    for (int i = 0; i < k.size(); ++i) {
-        if (k.at(i) == icString)
-            continue;
-        ic = create(k.at(i));
-        if (ic && ic->isValid())
-            return ic;
-        delete ic;
-        ic = 0;
-    }
-
+#endif
     return 0;
 }
 
+QPlatformInputContext *QPlatformInputContextFactory::create()
+{
+    return create(requested());
+}
 
 QT_END_NAMESPACE
 
index a74c4f5f803942f5f710549ec7916a3a3a9c1260..38f43582879547ac22bc4b23aef1a5b61478ba9f 100644 (file)
@@ -56,6 +56,7 @@ class Q_GUI_EXPORT QPlatformInputContextFactory
 {
 public:
     static QStringList keys();
+    static QString requested();
     static QPlatformInputContext *create(const QString &key);
     static QPlatformInputContext *create();
 };
index 2e6bfc95db7604b12c79825737f789f8ab28c71f..051a1c8710144c36eb30e0b7ec098b38b32fe83b 100644 (file)
@@ -47,6 +47,7 @@
 #include "qcocoamimetypes.h"
 #include "qcocoaaccessibility.h"
 
+#include <qpa/qplatforminputcontextfactory_p.h>
 #include <qpa/qplatformaccessibility.h>
 #include <qpa/qplatforminputcontextfactory_p.h>
 #include <QtCore/qcoreapplication.h>
@@ -286,9 +287,9 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
         qWarning("Creating multiple Cocoa platform integrations is not supported");
     mInstance = this;
 
-    mInputContext.reset(QPlatformInputContextFactory::create());
-    if (mInputContext.isNull())
-        mInputContext.reset(new QCocoaInputContext());
+    QString icStr = QPlatformInputContextFactory::requested();
+    icStr.isNull() ? mInputContext.reset(new QCocoaInputContext)
+                   : mInputContext.reset(QPlatformInputContextFactory::create(icStr));
 
     initResources();
     QMacAutoReleasePool pool;
index f97c23c2070ad0274c34fe7edfb1f360106822ab..bbb1f68a52486ff247c2ccf8d4c84bb677392796 100644 (file)
@@ -264,10 +264,9 @@ QWindowsIntegration::~QWindowsIntegration()
 
 void QWindowsIntegration::initialize()
 {
-    if (QPlatformInputContext *pluginContext = QPlatformInputContextFactory::create())
-        d->m_inputContext.reset(pluginContext);
-    else
-        d->m_inputContext.reset(new QWindowsInputContext);
+    QString icStr = QPlatformInputContextFactory::requested();
+    icStr.isNull() ? d->m_inputContext.reset(new QWindowsInputContext)
+                   : d->m_inputContext.reset(QPlatformInputContextFactory::create(icStr));
 }
 
 bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) const
index 15d3575e6058f8f5e178a6e4f3a1ee4de7fa55d0..e612cff9a3fa05e6afc7d005df543f9a11d9e2c3 100644 (file)
@@ -590,9 +590,6 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
         qCDebug(QT_XCB_GLINTEGRATION) << "Failed to create xcb gl-integration";
 
     sync();
-
-    if (qEnvironmentVariableIsEmpty("QT_IM_MODULE"))
-        qputenv("QT_IM_MODULE", QByteArray("compose"));
 }
 
 QXcbConnection::~QXcbConnection()
index fc06f1a7b0b0c76d328f55a3406c397c43cf76e3..9cedfa77ad6cd0026352abd4f502b84dc4b6265f 100644 (file)
@@ -268,7 +268,10 @@ void QXcbIntegration::initialize()
 {
     // Perform everything that may potentially need the event dispatcher (timers, socket
     // notifiers) here instead of the constructor.
-    m_inputContext.reset(QPlatformInputContextFactory::create());
+    QString icStr = QPlatformInputContextFactory::requested();
+    if (icStr.isNull())
+        icStr = QLatin1String("compose");
+    m_inputContext.reset(QPlatformInputContextFactory::create(icStr));
 }
 
 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
index a36e31e2e2b720389e5a61ccf7f4d9eeaa1506cf..ab17edecb65a03ee7e0be4dd7290f528c5b6a35d 100644 (file)
@@ -292,6 +292,9 @@ void tst_qinputmethod::inputMethodAccepted()
     if (qApp->platformName().toLower() == QLatin1String("wayland"))
         QSKIP("Wayland: This fails. Figure out why.");
 
+    if (qApp->platformName().toLower() == QLatin1String("xcb"))
+        QSKIP("XCB: depends on dedicated platform context.");
+
     InputItem disabledItem;
     disabledItem.setEnabled(false);