diff options
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtcursor.cpp | 16 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp | 71 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtinputcontext.cpp | 15 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtscreen.cpp | 9 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtwindow.cpp | 3 |
5 files changed, 70 insertions, 44 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtcursor.cpp b/src/plugins/platforms/winrt/qwinrtcursor.cpp index 707f3bf0ba..1a511f103f 100644 --- a/src/plugins/platforms/winrt/qwinrtcursor.cpp +++ b/src/plugins/platforms/winrt/qwinrtcursor.cpp @@ -161,15 +161,19 @@ void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *window) QPoint QWinRTCursor::pos() const { - ICoreWindow *coreWindow = - static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle())->coreWindow(); - HRESULT hr; + const QWinRTScreen *screen = static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle()); + Q_ASSERT(screen); + ICoreWindow *coreWindow = screen->coreWindow(); + Q_ASSERT(coreWindow); Point point; - hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { + HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point]() { return coreWindow->get_PointerPosition(&point); }); - RETURN_IF_FAILED("Failed to get native cursor position", QPoint()); - return QPoint(point.X, point.Y); + Q_ASSERT_SUCCEEDED(hr); + const QPoint position = QPoint(point.X, point.Y) * screen->scaleFactor(); + // If no cursor get_PointerPosition returns SHRT_MIN for x and y + return position.x() == SHRT_MIN && position.y() == SHRT_MIN || FAILED(hr) ? QPointF(Q_INFINITY, Q_INFINITY).toPoint() + : position; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp index 05b1fd76b1..b0f377147e 100644 --- a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp +++ b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp @@ -239,20 +239,24 @@ static bool pickFiles(IFileOpenPicker *picker, QWinRTFileDialogHelper *helper, b eventDispatcher->installEventFilter(helper); return true; #else - if (singleFile) { - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = picker->PickSingleFileAsync(&op); - RETURN_FALSE_IF_FAILED("Failed to open single file picker"); - hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); - RETURN_FALSE_IF_FAILED("Failed to attach file picker callback"); - } else { - ComPtr<IAsyncOperation<IVectorView<StorageFile *> *>> op; - hr = picker->PickMultipleFilesAsync(&op); - RETURN_FALSE_IF_FAILED("Failed to open multi file picker"); - hr = op->put_Completed(Callback<MultipleFileHandler>(helper, &QWinRTFileDialogHelper::onMultipleFilesPicked).Get()); - RETURN_FALSE_IF_FAILED("Failed to attach multi file callback"); - } - return true; + hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper, singleFile]() { + HRESULT hr; + if (singleFile) { + ComPtr<IAsyncOperation<StorageFile *>> op; + hr = picker->PickSingleFileAsync(&op); + RETURN_HR_IF_FAILED("Failed to open single file picker"); + hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); + RETURN_HR_IF_FAILED("Failed to attach file picker callback"); + } else { + ComPtr<IAsyncOperation<IVectorView<StorageFile *> *>> op; + hr = picker->PickMultipleFilesAsync(&op); + RETURN_HR_IF_FAILED("Failed to open multi file picker"); + hr = op->put_Completed(Callback<MultipleFileHandler>(helper, &QWinRTFileDialogHelper::onMultipleFilesPicked).Get()); + RETURN_HR_IF_FAILED("Failed to attach multi file callback"); + } + return S_OK; + }); + return SUCCEEDED(hr); #endif } @@ -274,13 +278,17 @@ static bool pickFolder(IFolderPicker *picker, QWinRTFileDialogHelper *helper) Q_ASSERT(eventDispatcher); eventDispatcher->installEventFilter(helper); #else - ComPtr<IAsyncOperation<StorageFolder *>> op; - hr = picker->PickSingleFolderAsync(&op); - RETURN_FALSE_IF_FAILED("Failed to open folder picker"); - hr = op->put_Completed(Callback<SingleFolderHandler>(helper, &QWinRTFileDialogHelper::onSingleFolderPicked).Get()); - RETURN_FALSE_IF_FAILED("Failed to attach folder picker callback"); + hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper]() { + HRESULT hr; + ComPtr<IAsyncOperation<StorageFolder *>> op; + hr = picker->PickSingleFolderAsync(&op); + RETURN_HR_IF_FAILED("Failed to open folder picker"); + hr = op->put_Completed(Callback<SingleFolderHandler>(helper, &QWinRTFileDialogHelper::onSingleFolderPicked).Get()); + RETURN_HR_IF_FAILED("Failed to attach folder picker callback"); + return S_OK; + }); #endif - return true; + return SUCCEEDED(hr); } static bool pickSaveFile(IFileSavePicker *picker, QWinRTFileDialogHelper *helper) @@ -301,13 +309,17 @@ static bool pickSaveFile(IFileSavePicker *picker, QWinRTFileDialogHelper *helper Q_ASSERT(eventDispatcher); eventDispatcher->installEventFilter(helper); #else - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = picker->PickSaveFileAsync(&op); - RETURN_FALSE_IF_FAILED("Failed to open save file picker"); - hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); - RETURN_FALSE_IF_FAILED("Failed to attach save file picker callback"); + hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper]() { + HRESULT hr; + ComPtr<IAsyncOperation<StorageFile *>> op; + hr = picker->PickSaveFileAsync(&op); + RETURN_HR_IF_FAILED("Failed to open save file picker"); + hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); + RETURN_HR_IF_FAILED("Failed to attach save file picker callback"); + return S_OK; + }); #endif - return true; + return SUCCEEDED(hr); } class QWinRTFileDialogHelperPrivate @@ -423,7 +435,12 @@ bool QWinRTFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModalit filterTitle.length()); boolean replaced; hr = choices->Insert(namedFilterRef.Get(), entry.Get(), &replaced); - RETURN_FALSE_IF_FAILED("Failed to insert file extension choice entry"); + // Only print a warning as * or *.* is not a valid choice on Windows 10 + // but used on a regular basis on all other platforms + if (FAILED(hr)) { + qWarning("Failed to insert file extension choice entry: %s: %s", + qPrintable(filterTitle), qPrintable(qt_error_string(hr))); + } } } diff --git a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp index 750233c94f..9d8792a6db 100644 --- a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp @@ -54,6 +54,14 @@ typedef ITypedEventHandler<InputPane*, InputPaneVisibilityEventArgs*> InputPaneV QT_BEGIN_NAMESPACE +inline QRectF getInputPaneRect(IInputPane *pane, qreal scaleFactor) +{ + Rect rect; + pane->get_OccludedRect(&rect); + return QRectF(qRound(rect.X * scaleFactor), qRound(rect.Y * scaleFactor), + qRound(rect.Width * scaleFactor), qRound(rect.Height * scaleFactor)); +} + /*! \class QWinRTInputContext \brief Manages Input Method visibility @@ -87,7 +95,7 @@ QWinRTInputContext::QWinRTInputContext(QWinRTScreen *screen) inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>( this, &QWinRTInputContext::onHiding).Get(), &hideToken); - handleVisibilityChange(inputPane); + m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor()); m_isInputPanelVisible = !m_keyboardRect.isEmpty(); } else { qWarning(Q_FUNC_INFO ": failed to retrieve InputPane."); @@ -120,10 +128,7 @@ HRESULT QWinRTInputContext::onHiding(IInputPane *pane, IInputPaneVisibilityEvent HRESULT QWinRTInputContext::handleVisibilityChange(IInputPane *pane) { - Rect rect; - pane->get_OccludedRect(&rect); - const QRectF keyboardRect = QRectF(qRound(rect.X * m_screen->scaleFactor()), qRound(rect.Y * m_screen->scaleFactor()), - qRound(rect.Width * m_screen->scaleFactor()), qRound(rect.Height * m_screen->scaleFactor())); + const QRectF keyboardRect = getInputPaneRect(pane, m_screen->scaleFactor()); if (m_keyboardRect != keyboardRect) { m_keyboardRect = keyboardRect; emitKeyboardRectChanged(); diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 8ba71d88e7..158917184c 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -507,11 +507,7 @@ QWinRTScreen::QWinRTScreen() hr = d->displayInformation->get_NativeOrientation(&displayOrientation); Q_ASSERT_SUCCEEDED(hr); d->nativeOrientation = static_cast<Qt::ScreenOrientation>(static_cast<int>(qtOrientationsFromNative(displayOrientation))); - - // Set initial orientation & pixel density - onDpiChanged(Q_NULLPTR, Q_NULLPTR); d->orientation = d->nativeOrientation; - onOrientationChanged(Q_NULLPTR, Q_NULLPTR); ComPtr<IApplicationViewStatics2> applicationViewStatics; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(), @@ -699,7 +695,8 @@ Xaml::IDependencyObject *QWinRTScreen::canvas() const void QWinRTScreen::setStatusBarVisibility(bool visible, QWindow *window) { Q_D(QWinRTScreen); - if (!window || (window->flags() & Qt::WindowType_Mask) != Qt::Window) + const Qt::WindowFlags windowType = window->flags() & Qt::WindowType_Mask; + if (!window || (windowType != Qt::Window && windowType != Qt::Dialog)) return; QEventDispatcherWinRT::runOnXamlThread([d, visible]() { @@ -756,6 +753,8 @@ void QWinRTScreen::initialize() Q_ASSERT_SUCCEEDED(hr); hr = d->displayInformation->add_DpiChanged(Callback<DisplayInformationHandler>(this, &QWinRTScreen::onDpiChanged).Get(), &d->displayTokens[&IDisplayInformation::remove_DpiChanged]); Q_ASSERT_SUCCEEDED(hr); + onDpiChanged(Q_NULLPTR, Q_NULLPTR); + onOrientationChanged(Q_NULLPTR, Q_NULLPTR); onVisibilityChanged(nullptr, nullptr); } diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp index 0d43e76c1a..bec94c1e51 100644 --- a/src/plugins/platforms/winrt/qwinrtwindow.cpp +++ b/src/plugins/platforms/winrt/qwinrtwindow.cpp @@ -207,7 +207,8 @@ void QWinRTWindow::setGeometry(const QRect &rect) Q_D(QWinRTWindow); const Qt::WindowFlags windowFlags = window()->flags(); - if (window()->isTopLevel() && (windowFlags & Qt::WindowType_Mask) == Qt::Window) { + const Qt::WindowFlags windowType = windowFlags & Qt::WindowType_Mask; + if (window()->isTopLevel() && (windowType == Qt::Window || windowType == Qt::Dialog)) { QPlatformWindow::setGeometry(windowFlags & Qt::MaximizeUsingFullscreenGeometryHint ? d->screen->geometry() : d->screen->availableGeometry()); QWindowSystemInterface::handleGeometryChange(window(), geometry()); |