winrt: Fix initialization of input context
f104e43a72380f66f8c517b90326a9209612106d moved QWinRTInputContext to the gui thread. However, IInputPane needs to be queried from Xaml itself. Otherwise it might cause unhandled exceptions. Change-Id: I43848c796e7ff163e6befa7c58f0ad68445b9865 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
6320ca79e9
commit
60da6313cf
@ -86,30 +86,31 @@ QWinRTInputContext::QWinRTInputContext(QWinRTScreen *screen)
|
|||||||
{
|
{
|
||||||
qCDebug(lcQpaInputMethods) << __FUNCTION__ << screen;
|
qCDebug(lcQpaInputMethods) << __FUNCTION__ << screen;
|
||||||
|
|
||||||
ComPtr<IInputPaneStatics> statics;
|
QEventDispatcherWinRT::runOnXamlThread([this]() {
|
||||||
if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(),
|
ComPtr<IInputPaneStatics> statics;
|
||||||
&statics))) {
|
if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(),
|
||||||
qWarning("failed to retrieve input pane statics.");
|
&statics))) {
|
||||||
return;
|
qWarning("failed to retrieve input pane statics.");
|
||||||
}
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
ComPtr<IInputPane> inputPane;
|
ComPtr<IInputPane> inputPane;
|
||||||
statics->GetForCurrentView(&inputPane);
|
statics->GetForCurrentView(&inputPane);
|
||||||
if (inputPane) {
|
if (inputPane) {
|
||||||
QEventDispatcherWinRT::runOnXamlThread([this, inputPane]() {
|
|
||||||
EventRegistrationToken showToken, hideToken;
|
EventRegistrationToken showToken, hideToken;
|
||||||
inputPane->add_Showing(Callback<InputPaneVisibilityHandler>(
|
inputPane->add_Showing(Callback<InputPaneVisibilityHandler>(
|
||||||
this, &QWinRTInputContext::onShowing).Get(), &showToken);
|
this, &QWinRTInputContext::onShowing).Get(), &showToken);
|
||||||
inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>(
|
inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>(
|
||||||
this, &QWinRTInputContext::onHiding).Get(), &hideToken);
|
this, &QWinRTInputContext::onHiding).Get(), &hideToken);
|
||||||
return S_OK;
|
|
||||||
});
|
|
||||||
|
|
||||||
m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor());
|
m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor());
|
||||||
m_isInputPanelVisible = !m_keyboardRect.isEmpty();
|
m_isInputPanelVisible = !m_keyboardRect.isEmpty();
|
||||||
} else {
|
} else {
|
||||||
qWarning("failed to retrieve InputPane.");
|
qWarning("failed to retrieve InputPane.");
|
||||||
}
|
}
|
||||||
|
return S_OK;
|
||||||
|
});
|
||||||
|
|
||||||
connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
|
connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
|
||||||
this, &QWinRTInputContext::updateScreenCursorRect);
|
this, &QWinRTInputContext::updateScreenCursorRect);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user