winphone: Fix keyboard show/hide calls
authorAndrew Knight <andrew.knight@intopalo.com>
Sun, 23 Aug 2015 20:51:26 +0000 (23:51 +0300)
committerAndrew Knight <andrew.knight@intopalo.com>
Mon, 24 Aug 2015 07:02:58 +0000 (07:02 +0000)
These need to occur on the XAML thread.

Change-Id: Id42a37df95b09e6d3c0a1b6e593bbf8cbfe5a129
Reviewed-by: Samuel Nevala <samuel.nevala@intopalo.com>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
src/plugins/platforms/winrt/qwinrtinputcontext.cpp

index 7bd9e87ca6bfcabbbfd5e101259818a415d0154d..f3b390b4d6be96c4f7e62a4a4f601fbe8d9a6970 100644 (file)
@@ -37,7 +37,9 @@
 #include "qwinrtinputcontext.h"
 #include "qwinrtscreen.h"
 #include <QtGui/QWindow>
+#include <private/qeventdispatcher_winrt_p.h>
 
+#include <functional>
 #include <wrl.h>
 #include <roapi.h>
 #include <windows.ui.viewmanagement.h>
@@ -163,10 +165,14 @@ void QWinRTInputContext::showInputPanel()
     if (FAILED(hr))
         return;
 
-    boolean success;
-    hr = inputPane->TryShow(&success);
-    if (FAILED(hr))
-        qErrnoWarning(hr, "Failed to show input panel.");
+    QEventDispatcherWinRT::runOnXamlThread([&inputPane]() {
+        HRESULT hr;
+        boolean success;
+        hr = inputPane->TryShow(&success);
+        if (FAILED(hr) || !success)
+            qErrnoWarning(hr, "Failed to show input panel.");
+        return hr;
+    });
 }
 
 void QWinRTInputContext::hideInputPanel()
@@ -176,10 +182,14 @@ void QWinRTInputContext::hideInputPanel()
     if (FAILED(hr))
         return;
 
-    boolean success;
-    hr = inputPane->TryHide(&success);
-    if (FAILED(hr))
-        qErrnoWarning(hr, "Failed to hide input panel.");
+    QEventDispatcherWinRT::runOnXamlThread([&inputPane]() {
+        HRESULT hr;
+        boolean success;
+        hr = inputPane->TryHide(&success);
+        if (FAILED(hr) || !success)
+            qErrnoWarning(hr, "Failed to hide input panel.");
+        return hr;
+    });
 }
 
 #endif // Q_OS_WINPHONE