diff options
Diffstat (limited to 'src/plugins/platforms/winrt/qwinrtscreen.cpp')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtscreen.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 2a4b6c8907..edfcf038d7 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -58,7 +58,7 @@ #include <functional> #include <wrl.h> #include <windows.system.h> -#include <Windows.Applicationmodel.h> +#include <Windows.ApplicationModel.h> #include <Windows.ApplicationModel.core.h> #include <windows.devices.input.h> #include <windows.ui.h> @@ -91,6 +91,7 @@ typedef ITypedEventHandler<CoreWindow*, PointerEventArgs*> PointerHandler; typedef ITypedEventHandler<CoreWindow*, WindowSizeChangedEventArgs*> SizeChangedHandler; typedef ITypedEventHandler<CoreWindow*, VisibilityChangedEventArgs*> VisibilityChangedHandler; typedef ITypedEventHandler<DisplayInformation*, IInspectable*> DisplayInformationHandler; +typedef ITypedEventHandler<ICorePointerRedirector*, PointerEventArgs*> RedirectHandler; #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) typedef ITypedEventHandler<ApplicationView*, IInspectable*> VisibleBoundsChangedHandler; #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) @@ -454,6 +455,8 @@ typedef HRESULT (__stdcall ICoreWindow::*CoreWindowCallbackRemover)(EventRegistr uint qHash(CoreWindowCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } typedef HRESULT (__stdcall IDisplayInformation::*DisplayCallbackRemover)(EventRegistrationToken); uint qHash(DisplayCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } +typedef HRESULT (__stdcall ICorePointerRedirector::*RedirectorCallbackRemover)(EventRegistrationToken); +uint qHash(RedirectorCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) typedef HRESULT (__stdcall IApplicationView2::*ApplicationView2CallbackRemover)(EventRegistrationToken); uint qHash(ApplicationView2CallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } @@ -464,6 +467,7 @@ class QWinRTScreenPrivate public: QTouchDevice *touchDevice; ComPtr<ICoreWindow> coreWindow; + ComPtr<ICorePointerRedirector> redirect; ComPtr<Xaml::IDependencyObject> canvas; ComPtr<IApplicationView> view; ComPtr<IDisplayInformation> displayInformation; @@ -482,6 +486,7 @@ public: QHash<Qt::Key, KeyInfo> activeKeys; QHash<CoreWindowCallbackRemover, EventRegistrationToken> windowTokens; QHash<DisplayCallbackRemover, EventRegistrationToken> displayTokens; + QHash<RedirectorCallbackRemover, EventRegistrationToken> redirectTokens; #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) QHash<ApplicationView2CallbackRemover, EventRegistrationToken> view2Tokens; ComPtr<IApplicationView2> view2; @@ -513,6 +518,10 @@ QWinRTScreen::QWinRTScreen() hr = window->get_CoreWindow(&d->coreWindow); Q_ASSERT_SUCCEEDED(hr); + + hr = d->coreWindow.As(&d->redirect); + Q_ASSERT_SUCCEEDED(hr); + hr = d->coreWindow->Activate(); Q_ASSERT_SUCCEEDED(hr); @@ -562,7 +571,7 @@ QWinRTScreen::QWinRTScreen() ComPtr<Xaml::IUIElement> uiElement; hr = canvas.As(&uiElement); Q_ASSERT_SUCCEEDED(hr); -#if _MSC_VER >= 1900 && !defined(QT_NO_DRAGANDDROP) +#ifndef QT_NO_DRAGANDDROP QWinRTDrag::instance()->setUiElement(uiElement); #endif hr = window->put_Content(uiElement.Get()); @@ -595,6 +604,10 @@ QWinRTScreen::~QWinRTScreen() hr = (d->displayInformation.Get()->*i.key())(i.value()); Q_ASSERT_SUCCEEDED(hr); } + for (QHash<RedirectorCallbackRemover, EventRegistrationToken>::const_iterator i = d->redirectTokens.begin(); i != d->redirectTokens.end(); ++i) { + hr = (d->redirect.Get()->*i.key())(i.value()); + Q_ASSERT_SUCCEEDED(hr); + } #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) for (QHash<ApplicationView2CallbackRemover, EventRegistrationToken>::const_iterator i = d->view2Tokens.begin(); i != d->view2Tokens.end(); ++i) { hr = (d->view2.Get()->*i.key())(i.value()); @@ -754,6 +767,9 @@ void QWinRTScreen::initialize() Q_ASSERT_SUCCEEDED(hr); onOrientationChanged(Q_NULLPTR, Q_NULLPTR); onVisibilityChanged(nullptr, nullptr); + + hr = d->redirect->add_PointerRoutedReleased(Callback<RedirectHandler>(this, &QWinRTScreen::onRedirectReleased).Get(), &d->redirectTokens[&ICorePointerRedirector::remove_PointerRoutedReleased]); + Q_ASSERT_SUCCEEDED(hr); } void QWinRTScreen::setCursorRect(const QRectF &cursorRect) @@ -833,7 +849,7 @@ void QWinRTScreen::addWindow(QWindow *window) handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); -#if _MSC_VER >= 1900 && !defined(QT_NO_DRAGANDDROP) +#ifndef QT_NO_DRAGANDDROP QWinRTDrag::instance()->setDropTarget(window); #endif } @@ -852,7 +868,7 @@ void QWinRTScreen::removeWindow(QWindow *window) QWindowSystemInterface::handleWindowActivated(Q_NULLPTR, Qt::OtherFocusReason); handleExpose(); QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); -#if _MSC_VER >= 1900 && !defined(QT_NO_DRAGANDDROP) +#ifndef QT_NO_DRAGANDDROP if (wasTopWindow) QWinRTDrag::instance()->setDropTarget(topWindow()); #endif @@ -1221,11 +1237,7 @@ HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) properties->get_Pressure(&pressure); boolean isPressed; -#ifndef Q_OS_WINPHONE pointerPoint->get_IsInContact(&isPressed); -#else - properties->get_IsLeftButtonPressed(&isPressed); // IsInContact not reliable on phone -#endif // Devices like the Hololens set a static pressure of 0.5 independent // of the pressed state. In those cases we need to synthesize the @@ -1356,16 +1368,10 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) Q_D(QWinRTScreen); HRESULT hr; -#ifdef Q_OS_WINPHONE - ComPtr<IDisplayInformation2> displayInformation; - hr = d->displayInformation.As(&displayInformation); - RETURN_OK_IF_FAILED("Failed to cast display information."); - hr = displayInformation->get_RawPixelsPerViewPixel(&d->scaleFactor); -#else ResolutionScale resolutionScale; hr = d->displayInformation->get_ResolutionScale(&resolutionScale); d->scaleFactor = qreal(resolutionScale) / 100; -#endif + qCDebug(lcQpaWindows) << __FUNCTION__ << "Scale Factor:" << d->scaleFactor; RETURN_OK_IF_FAILED("Failed to get scale factor"); @@ -1388,6 +1394,13 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) return S_OK; } +HRESULT QWinRTScreen::onRedirectReleased(ICorePointerRedirector *, IPointerEventArgs *args) +{ + // When dragging ends with a non-mouse input device then onRedirectRelease is invoked. + // QTBUG-58781 + return onPointerUpdated(nullptr, args); +} + #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) HRESULT QWinRTScreen::onWindowSizeChanged(IApplicationView *, IInspectable *) #else |