Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix KisScreenMigrationTracker to use nearest window, not top level
Dmitry Kazakov5d31ee77d51c
diff --git a/libs/widgetutils/KisScreenMigrationTracker.cpp b/libs/widgetutils/KisScreenMigrationTracker.cppindex 20c40cf2f8..1f09d5813c 100644--- a/libs/widgetutils/KisScreenMigrationTracker.cpp+++ b/libs/widgetutils/KisScreenMigrationTracker.cpp@@ -13,6 +13,22 @@#include <kis_assert.h>#include <kis_signal_compressor.h>+namespace {+QWindow *findNearestParentWithNativeWindow(QWidget *widget)+{+ do {+ QWindow *nativeWindow = widget->windowHandle();++ if (nativeWindow) {+ return nativeWindow;+ }++ } while ((widget = widget->parentWidget()));++ return nullptr;+}+}+KisScreenMigrationTracker::KisScreenMigrationTracker(QWidget *trackedWidget, QObject *parent): QObject(parent), m_trackedWidget(trackedWidget)@@ -25,7 +41,7 @@ KisScreenMigrationTracker::KisScreenMigrationTracker(QWidget *trackedWidget, QOb* of the widget. Hence we should postpone initialization of the window handle* till the widget gets shown on screen.*/- m_trackedTopLevelWindow = trackedWidget->topLevelWidget()->windowHandle();+ m_trackedTopLevelWindow = findNearestParentWithNativeWindow(trackedWidget);if (m_trackedTopLevelWindow) {connectTopLevelWindow(m_trackedTopLevelWindow);} else {@@ -38,10 +54,8 @@ KisScreenMigrationTracker::KisScreenMigrationTracker(QWidget *trackedWidget, QObQScreen* KisScreenMigrationTracker::currentScreen() const{- QWindow *window = m_trackedWidget->topLevelWidget()->windowHandle();- KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(window, qApp->screens().first());-- return window->screen();+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_trackedTopLevelWindow, qApp->screens().first());+ return m_trackedTopLevelWindow->screen();}QScreen *KisScreenMigrationTracker::currentScreenSafe() const@@ -71,7 +85,7 @@ void KisScreenMigrationTracker::connectTopLevelWindow(QWindow *window)bool KisScreenMigrationTracker::eventFilter(QObject *watched, QEvent *event){if (watched == m_trackedWidget && event->type() == QEvent::Show) {- m_trackedTopLevelWindow = m_trackedWidget->topLevelWidget()->windowHandle();+ m_trackedTopLevelWindow = findNearestParentWithNativeWindow(m_trackedWidget);if (m_trackedTopLevelWindow) {connectTopLevelWindow(m_trackedTopLevelWindow);m_trackedWidget->removeEventFilter(this);