diff options
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrtinputcontext.cpp')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtinputcontext.cpp | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp index 3f476556ee..63e5b0cf27 100644 --- a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp @@ -39,6 +39,7 @@ #include "qwinrtinputcontext.h" #include "qwinrtscreen.h" +#include <QtGui/QGuiApplication> #include <QtGui/QWindow> #include <private/qeventdispatcher_winrt_p.h> @@ -59,7 +60,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods") -inline QRectF getInputPaneRect(IInputPane *pane, qreal scaleFactor) +inline QRectF getInputPaneRect(ComPtr<IInputPane> pane, qreal scaleFactor) { Rect rect; pane->get_OccludedRect(&rect); @@ -85,28 +86,33 @@ QWinRTInputContext::QWinRTInputContext(QWinRTScreen *screen) { qCDebug(lcQpaInputMethods) << __FUNCTION__ << screen; - IInputPaneStatics *statics; - if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), - &statics))) { - qWarning("failed to retrieve input pane statics."); - return; - } + QEventDispatcherWinRT::runOnXamlThread([this]() { + ComPtr<IInputPaneStatics> statics; + if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), + &statics))) { + qWarning("failed to retrieve input pane statics."); + return S_OK; + } + + ComPtr<IInputPane> inputPane; + statics->GetForCurrentView(&inputPane); + if (inputPane) { + EventRegistrationToken showToken, hideToken; + inputPane->add_Showing(Callback<InputPaneVisibilityHandler>( + this, &QWinRTInputContext::onShowing).Get(), &showToken); + inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>( + this, &QWinRTInputContext::onHiding).Get(), &hideToken); + + m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor()); + m_isInputPanelVisible = !m_keyboardRect.isEmpty(); + } else { + qWarning("failed to retrieve InputPane."); + } + return S_OK; + }); - IInputPane *inputPane; - statics->GetForCurrentView(&inputPane); - statics->Release(); - if (inputPane) { - EventRegistrationToken showToken, hideToken; - inputPane->add_Showing(Callback<InputPaneVisibilityHandler>( - this, &QWinRTInputContext::onShowing).Get(), &showToken); - inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>( - this, &QWinRTInputContext::onHiding).Get(), &hideToken); - - m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor()); - m_isInputPanelVisible = !m_keyboardRect.isEmpty(); - } else { - qWarning("failed to retrieve InputPane."); - } + connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, + this, &QWinRTInputContext::updateScreenCursorRect); } QRectF QWinRTInputContext::keyboardRect() const @@ -119,6 +125,11 @@ bool QWinRTInputContext::isInputPanelVisible() const return m_isInputPanelVisible; } +void QWinRTInputContext::updateScreenCursorRect() +{ + m_screen->setCursorRect(QGuiApplication::inputMethod()->cursorRectangle()); +} + HRESULT QWinRTInputContext::onShowing(IInputPane *pane, IInputPaneVisibilityEventArgs *) { qCDebug(lcQpaInputMethods) << __FUNCTION__ << pane; @@ -141,6 +152,7 @@ HRESULT QWinRTInputContext::handleVisibilityChange(IInputPane *pane) const QRectF keyboardRect = getInputPaneRect(pane, m_screen->scaleFactor()); if (m_keyboardRect != keyboardRect) { m_keyboardRect = keyboardRect; + m_screen->setKeyboardRect(m_keyboardRect); emitKeyboardRectChanged(); } return S_OK; |