Skip to content

armgit / krita

Public Imported from GitHub
0

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 screen migration of Scratch Pad

Dmitry Kazakov85e27426a052
diff --git a/libs/ui/KisRootSurfaceInfoProxy.cpp b/libs/ui/KisRootSurfaceInfoProxy.cpp
index 69a7e0a7d5..b22e55869a 100644
--- a/libs/ui/KisRootSurfaceInfoProxy.cpp
+++ b/libs/ui/KisRootSurfaceInfoProxy.cpp
@@ -15,45 +15,13 @@
#include <KisSRGBSurfaceColorSpaceManager.h>
-namespace {
-class ChildChangedEventFilter : public QObject
-{
- Q_OBJECT
-public:
- ChildChangedEventFilter(QObject *watched, QObject *parent)
- : QObject(parent)
- , m_watched(watched)
- {
- }
-
- bool eventFilter(QObject *watched, QEvent *event) override {
- if (watched == m_watched &&
- (event->type() == QEvent::ChildAdded || event->type() == QEvent::ChildRemoved)) {
- /**
- * Upon receiving QChildEvent, the child object is not yet
- * fully constructed, so we need to postpone the event handling
- * till the next event loop cycle.
- */
- QTimer::singleShot(0, this, &ChildChangedEventFilter::sigChildrenChanged);
- }
-
- return false;
- }
-
- QObject *m_watched {nullptr};
-
-Q_SIGNALS:
- void sigChildrenChanged();
-};
-}
-
KisRootSurfaceInfoProxy::KisRootSurfaceInfoProxy(QWidget *watched, QObject *parent)
- : QObject(parent)
- , m_watched(watched)
+ : KisRootSurfaceTrackerBase(watched, parent)
{
KIS_SAFE_ASSERT_RECOVER_RETURN(KisPlatformPluginInterfaceFactory::instance()->surfaceColorManagedByOS());
m_rootSurfaceProfile = KoColorSpaceRegistry::instance()->p709SRGBProfile();
- tryUpdateHierarchy();
+ // WARNING: we potentially call virtual functions here!
+ initialize();
}
KisRootSurfaceInfoProxy::~KisRootSurfaceInfoProxy()
@@ -82,85 +50,32 @@ QString KisRootSurfaceInfoProxy::osPreferredColorSpaceReport() const
: QString("Top level surface color manager is not found!\n");
}
-bool KisRootSurfaceInfoProxy::eventFilter(QObject *watched, QEvent *event)
+void KisRootSurfaceInfoProxy::connectToNativeWindow(QWindow *nativeWindow)
{
- if (event->type() == QEvent::ParentChange && m_watchedHierarchy.contains(watched)) {
- tryUpdateHierarchy();
- }
-
- if (event->type() == QEvent::PlatformSurface && watched == m_watchedHierarchy.last().data()) {
- tryReconnectSurfaceManager();
- }
-
- return false;
-}
-
-void KisRootSurfaceInfoProxy::tryUpdateHierarchy()
-{
- auto newHierarchy = getCurrentHierarchy(m_watched);
- if (newHierarchy != m_watchedHierarchy) {
- reconnectToHierarchy(newHierarchy);
- QWidget *topLevel = static_cast<QWidget *>(newHierarchy.last().data());
- if (topLevel != m_topLevelWidgetWithSurface) {
- m_topLevelWidgetWithSurface = topLevel;
- tryReconnectSurfaceManager();
+ KIS_SAFE_ASSERT_RECOVER_RETURN(nativeWindow);
+ if (auto manager = nativeWindow->findChild<KisSRGBSurfaceColorSpaceManager *>()) {
+ if (manager != m_topLevelSurfaceManager) {
+ m_topLevelSurfaceManager.clear();
+ if (m_surfaceManagerConnection) {
+ disconnect(m_surfaceManagerConnection);
+ }
+ m_topLevelSurfaceManager = manager;
+ m_surfaceManagerConnection = connect(m_topLevelSurfaceManager,
+ &KisSRGBSurfaceColorSpaceManager::sigDisplayConfigChanged,
+ this,
+ &KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile);
+ tryUpdateRootSurfaceProfile();
}
}
}
-void KisRootSurfaceInfoProxy::tryReconnectSurfaceManager()
+void KisRootSurfaceInfoProxy::disconnectFromNativeWindow()
{
- auto disconnectExistingManager = [this]() {
- m_topLevelSurfaceManager.clear();
- if (m_surfaceManagerConnection) {
- disconnect(m_surfaceManagerConnection);
- }
- };
-
- if (!m_topLevelWidgetWithSurface) {
- disconnectExistingManager();
- tryUpdateRootSurfaceProfile();
- return;
- }
-
- QWindow *nativeWindow = m_topLevelWidgetWithSurface->windowHandle();
-
- if (nativeWindow != m_topLevelNativeWindow) {
- if (m_childChangedFilter && m_topLevelNativeWindow) {
- m_topLevelNativeWindow->removeEventFilter(m_childChangedFilter);
- m_childChangedFilter->deleteLater();
- m_childChangedFilter.clear();
- }
-
- m_topLevelNativeWindow = nativeWindow;
-
- if (m_topLevelNativeWindow) {
- auto *filter = new ChildChangedEventFilter(m_topLevelNativeWindow, m_topLevelNativeWindow);
- connect(filter,
- &ChildChangedEventFilter::sigChildrenChanged,
- this,
- &KisRootSurfaceInfoProxy::tryReconnectSurfaceManager);
- m_childChangedFilter = filter;
- m_topLevelNativeWindow->installEventFilter(m_childChangedFilter);
- }
- }
-
- if (nativeWindow) {
- if (auto manager = nativeWindow->findChild<KisSRGBSurfaceColorSpaceManager *>()) {
- if (manager != m_topLevelSurfaceManager) {
- disconnectExistingManager();
- m_topLevelSurfaceManager = manager;
- m_surfaceManagerConnection = connect(m_topLevelSurfaceManager,
- &KisSRGBSurfaceColorSpaceManager::sigDisplayConfigChanged,
- this,
- &KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile);
- tryUpdateRootSurfaceProfile();
- }
- }
- } else {
- disconnectExistingManager();
- tryUpdateRootSurfaceProfile();
+ m_topLevelSurfaceManager.clear();
+ if (m_surfaceManagerConnection) {
+ disconnect(m_surfaceManagerConnection);
}
+ tryUpdateRootSurfaceProfile();
}
void KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile()
@@ -178,33 +93,3 @@ void KisRootSurfaceInfoProxy::tryUpdateRootSurfaceProfile()
Q_EMIT sigRootSurfaceProfileChanged(m_rootSurfaceProfile);
}
}
-
-QVector<QPointer<QObject>> KisRootSurfaceInfoProxy::getCurrentHierarchy(QWidget *wdg)
-{
- QVector<QPointer<QObject>> result;
-
- while (wdg) {
- result.append(wdg);
- wdg = wdg->parentWidget();
- }
-
- return result;
-}
-
-void KisRootSurfaceInfoProxy::reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy)
-{
- Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
- KIS_SAFE_ASSERT_RECOVER(widget) continue;
- widget->removeEventFilter(this);
- }
-
- m_watchedHierarchy.clear();
-
- Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
- widget->installEventFilter(this);
- }
-
- m_watchedHierarchy = newHierarchy;
-}
-
-#include <KisRootSurfaceInfoProxy.moc>
\ No newline at end of file
diff --git a/libs/ui/KisRootSurfaceInfoProxy.h b/libs/ui/KisRootSurfaceInfoProxy.h
index 78e27bf563..f7514c3d27 100644
--- a/libs/ui/KisRootSurfaceInfoProxy.h
+++ b/libs/ui/KisRootSurfaceInfoProxy.h
@@ -7,14 +7,9 @@
#define KISROOTSURFACEINFOPROXY_H
#include <kritaui_export.h>
-
-#include <QObject>
-#include <QPointer>
+#include <KisRootSurfaceTrackerBase.h>
class KisSRGBSurfaceColorSpaceManager;
-class QWidget;
-class QWindow;
-class QEvent;
class KoColorProfile;
/**
@@ -42,7 +37,7 @@ class KoColorProfile;
* 4) Finally, connects to the manager and forwards its
* sigDisplayConfigChanged() to local sigRootSurfaceProfileChanged()
*/
-class KRITAUI_EXPORT KisRootSurfaceInfoProxy : public QObject
+class KRITAUI_EXPORT KisRootSurfaceInfoProxy : public KisRootSurfaceTrackerBase
{
Q_OBJECT
public:
@@ -59,30 +54,15 @@ Q_SIGNALS:
private:
- bool eventFilter(QObject *watched, QEvent *event) override;
-
- void tryUpdateHierarchy();
- void tryReconnectSurfaceManager();
+ void connectToNativeWindow(QWindow *nativeWindow) override;
+ void disconnectFromNativeWindow() override;
void tryUpdateRootSurfaceProfile();
- QVector<QPointer<QObject>> getCurrentHierarchy(QWidget *wdg);
-
- void reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy);
-
private:
- QWidget *m_watched {nullptr};
- QVector<QPointer<QObject>> m_watchedHierarchy;
-
- QPointer<QWidget> m_topLevelWidgetWithSurface;
-
- QPointer<QWindow> m_topLevelNativeWindow;
- QPointer<QObject> m_childChangedFilter;
-
QPointer<KisSRGBSurfaceColorSpaceManager> m_topLevelSurfaceManager;
QMetaObject::Connection m_surfaceManagerConnection;
const KoColorProfile* m_rootSurfaceProfile {nullptr};
-
};
#endif /* KISROOTSURFACEINFOPROXY_H */
diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txt
index 836f43b05d..e8f074a1b3 100644
--- a/libs/widgetutils/CMakeLists.txt
+++ b/libs/widgetutils/CMakeLists.txt
@@ -49,6 +49,7 @@ set(kritawidgetutils_LIB_SRCS
KisMenuStyleDontCloseOnAlt.cpp
KisSpinBoxI18nHelper.cpp
KisScreenMigrationTracker.cpp
+ KisRootSurfaceTrackerBase.cpp
config/khelpclient.cpp
config/klanguagebutton.cpp
diff --git a/libs/widgetutils/KisRootSurfaceTrackerBase.cpp b/libs/widgetutils/KisRootSurfaceTrackerBase.cpp
new file mode 100644
index 0000000000..d4e4c15cc4
--- /dev/null
+++ b/libs/widgetutils/KisRootSurfaceTrackerBase.cpp
@@ -0,0 +1,172 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisRootSurfaceTrackerBase.h"
+
+#include <QTimer>
+
+#include <QEvent>
+#include <QWidget>
+#include <QWindow>
+
+#include <kis_assert.h>
+
+
+namespace {
+class ChildChangedEventFilter : public QObject
+{
+ Q_OBJECT
+public:
+ ChildChangedEventFilter(QObject *watched, QObject *parent)
+ : QObject(parent)
+ , m_watched(watched)
+ {
+ }
+
+ bool eventFilter(QObject *watched, QEvent *event) override {
+ if (watched == m_watched &&
+ (event->type() == QEvent::ChildAdded || event->type() == QEvent::ChildRemoved)) {
+ /**
+ * Upon receiving QChildEvent, the child object is not yet
+ * fully constructed, so we need to postpone the event handling
+ * till the next event loop cycle.
+ */
+ QTimer::singleShot(0, this, &ChildChangedEventFilter::sigChildrenChanged);
+ }
+
+ return false;
+ }
+
+ QObject *m_watched {nullptr};
+
+Q_SIGNALS:
+ void sigChildrenChanged();
+};
+}
+
+KisRootSurfaceTrackerBase::KisRootSurfaceTrackerBase(QWidget *watched, QObject *parent)
+ : QObject(parent)
+ , m_watched(watched)
+{
+}
+
+KisRootSurfaceTrackerBase::~KisRootSurfaceTrackerBase()
+{
+}
+
+QWidget* KisRootSurfaceTrackerBase::trackedWidget() const
+{
+ return m_watched;
+}
+
+void KisRootSurfaceTrackerBase::initialize()
+{
+ tryUpdateHierarchy();
+}
+
+bool KisRootSurfaceTrackerBase::eventFilter(QObject *watched, QEvent *event)
+{
+ if (event->type() == QEvent::ParentChange && m_watchedHierarchy.contains(watched)) {
+ tryUpdateHierarchy();
+ }
+
+ if (event->type() == QEvent::PlatformSurface) {
+ if (watched == m_watchedHierarchy.last().data()) {
+ tryReconnectToNativeWindow();
+ } else {
+ // some widget in the middle of the hierarchy just received
+ // a native window. Let's promote that to toplevel now!
+ tryUpdateHierarchy();
+ }
+ }
+
+ return false;
+}
+
+void KisRootSurfaceTrackerBase::tryUpdateHierarchy()
+{
+ auto newHierarchy = getCurrentHierarchy(m_watched);
+ if (newHierarchy != m_watchedHierarchy) {
+ reconnectToHierarchy(newHierarchy);
+ QWidget *topLevel = static_cast<QWidget *>(newHierarchy.last().data());
+ if (topLevel != m_topLevelWidgetWithSurface) {
+ m_topLevelWidgetWithSurface = topLevel;
+ tryReconnectToNativeWindow();
+ }
+ }
+}
+
+void KisRootSurfaceTrackerBase::tryReconnectToNativeWindow()
+{
+ if (!m_topLevelWidgetWithSurface) {
+ disconnectFromNativeWindow();
+ return;
+ }
+
+ QWindow *nativeWindow = m_topLevelWidgetWithSurface->windowHandle();
+
+ if (nativeWindow != m_topLevelNativeWindow) {
+ if (m_childChangedFilter && m_topLevelNativeWindow) {
+ m_topLevelNativeWindow->removeEventFilter(m_childChangedFilter);
+ m_childChangedFilter->deleteLater();
+ m_childChangedFilter.clear();
+ }
+
+ m_topLevelNativeWindow = nativeWindow;
+
+ if (m_topLevelNativeWindow) {
+ auto *filter = new ChildChangedEventFilter(m_topLevelNativeWindow, m_topLevelNativeWindow);
+ connect(filter,
+ &ChildChangedEventFilter::sigChildrenChanged,
+ this,
+ &KisRootSurfaceTrackerBase::tryReconnectToNativeWindow);
+ m_childChangedFilter = filter;
+ m_topLevelNativeWindow->installEventFilter(m_childChangedFilter);
+ }
+ }
+
+ if (nativeWindow) {
+ connectToNativeWindow(nativeWindow);
+ } else {
+ disconnectFromNativeWindow();
+ }
+}
+
+QVector<QPointer<QObject>> KisRootSurfaceTrackerBase::getCurrentHierarchy(QWidget *wdg)
+{
+ QVector<QPointer<QObject>> result;
+
+ while (wdg) {
+ result.append(wdg);
+
+ // break on the first native window
+ if (wdg->windowHandle()) {
+ break;
+ } else {
+ wdg = wdg->parentWidget();
+ }
+ }
+
+ return result;
+}
+
+void KisRootSurfaceTrackerBase::reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy)
+{
+ Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
+ KIS_SAFE_ASSERT_RECOVER(widget) continue;
+ widget->removeEventFilter(this);
+ }
+
+ m_watchedHierarchy.clear();
+
+ Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
+ widget->installEventFilter(this);
+ }
+
+ m_watchedHierarchy = newHierarchy;
+}
+
+#include <KisRootSurfaceTrackerBase.moc>
\ No newline at end of file
diff --git a/libs/widgetutils/KisRootSurfaceTrackerBase.h b/libs/widgetutils/KisRootSurfaceTrackerBase.h
new file mode 100644
index 0000000000..cfc9938f99
--- /dev/null
+++ b/libs/widgetutils/KisRootSurfaceTrackerBase.h
@@ -0,0 +1,72 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef KISROOTSURFACETRACKERBASE_H
+#define KISROOTSURFACETRACKERBASE_H
+
+#include <kritawidgetutils_export.h>
+
+#include <QObject>
+#include <QPointer>
+
+class QWidget;
+class QWindow;
+class QEvent;
+
+/**
+ * KisRootSurfaceProxyBase is a special proxy object for toplevel
+ * native window attached to the current QWidget
+ *
+ * When created, the proxy does the following:
+ *
+ * 1) Finds the top-level widget that \p watched belongs to.
+ * (is \p watched changed its parent in the meantime, e.g.
+ * during construction, then the proxy will handle that
+ * as well)
+ *
+ * 2) Finds the QWindow that this toplevel widget is painted on
+ * (if platform window is not created yet, subscribes to
+ * QPlatformSurfaceEvent to attach when platform window is
+ * finally created)
+ *
+ * 3) When found, calls implementation of connectToNativeWindow()
+ * that would connect to the actual native window
+ */
+class KRITAWIDGETUTILS_EXPORT KisRootSurfaceTrackerBase : public QObject
+{
+ Q_OBJECT
+public:
+ KisRootSurfaceTrackerBase(QWidget *watched, QObject *parent = nullptr);
+ ~KisRootSurfaceTrackerBase();
+
+ QWidget* trackedWidget() const;
+
+protected:
+ virtual void connectToNativeWindow(QWindow *nativeWindow) = 0;
+ virtual void disconnectFromNativeWindow() = 0;
+ void initialize();
+
+private:
+
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
+ void tryUpdateHierarchy();
+ void tryReconnectToNativeWindow();
+
+ QVector<QPointer<QObject>> getCurrentHierarchy(QWidget *wdg);
+
+ void reconnectToHierarchy(const QVector<QPointer<QObject>> newHierarchy);
+
+private:
+ QWidget *m_watched {nullptr};
+ QVector<QPointer<QObject>> m_watchedHierarchy;
+
+ QPointer<QWidget> m_topLevelWidgetWithSurface;
+
+ QPointer<QWindow> m_topLevelNativeWindow;
+ QPointer<QObject> m_childChangedFilter;
+};
+
+#endif /* KISROOTSURFACETRACKERBASE_H */
diff --git a/libs/widgetutils/KisScreenMigrationTracker.cpp b/libs/widgetutils/KisScreenMigrationTracker.cpp
index 1f09d5813c..dfaa123c73 100644
--- a/libs/widgetutils/KisScreenMigrationTracker.cpp
+++ b/libs/widgetutils/KisScreenMigrationTracker.cpp
@@ -13,40 +13,16 @@
#include <kis_assert.h>
#include <kis_signal_compressor.h>
-namespace {
-QWindow *findNearestParentWithNativeWindow(QWidget *widget)
-{
- do {
- QWindow *nativeWindow = widget->windowHandle();
-
- if (nativeWindow) {
- return nativeWindow;
- }
+#include <kis_debug.h>
- } while ((widget = widget->parentWidget()));
-
- return nullptr;
-}
-}
KisScreenMigrationTracker::KisScreenMigrationTracker(QWidget *trackedWidget, QObject *parent)
- : QObject(parent)
- , m_trackedWidget(trackedWidget)
+ : KisRootSurfaceTrackerBase(trackedWidget, parent)
, m_resolutionChangeCompressor(new KisSignalCompressor(100, KisSignalCompressor::POSTPONE, this))
{
KIS_SAFE_ASSERT_RECOVER_RETURN(trackedWidget);
-
- /**
- * The window of the tracked widget may be not initialized at the construction
- * of the widget. Hence we should postpone initialization of the window handle
- * till the widget gets shown on screen.
- */
- m_trackedTopLevelWindow = findNearestParentWithNativeWindow(trackedWidget);
- if (m_trackedTopLevelWindow) {
- connectTopLevelWindow(m_trackedTopLevelWindow);
- } else {
- trackedWidget->installEventFilter(this);
- }
+ // WARNING: we potentially call virtual functions here!
+ initialize();
connect(m_resolutionChangeCompressor, &KisSignalCompressor::timeout,
this, &KisScreenMigrationTracker::slotResolutionCompressorTriggered);
@@ -54,13 +30,13 @@ KisScreenMigrationTracker::KisScreenMigrationTracker(QWidget *trackedWidget, QOb
QScreen* KisScreenMigrationTracker::currentScreen() const
{
- KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_trackedTopLevelWindow, qApp->screens().first());
- return m_trackedTopLevelWindow->screen();
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_connectedTopLevelWindow, qApp->screens().first());
+ return m_connectedTopLevelWindow->screen();
}
QScreen *KisScreenMigrationTracker::currentScreenSafe() const
{
- return m_trackedTopLevelWindow ? m_trackedTopLevelWindow->screen() : qApp->screens().first();
+ return m_connectedTopLevelWindow ? m_connectedTopLevelWindow->screen() : qApp->screens().first();
}
void KisScreenMigrationTracker::connectScreenSignals(QScreen *screen)
@@ -72,27 +48,25 @@ void KisScreenMigrationTracker::connectScreenSignals(QScreen *screen)
this, &KisScreenMigrationTracker::slotScreenLogicalResolutionChanged);
}
-void KisScreenMigrationTracker::connectTopLevelWindow(QWindow *window)
+void KisScreenMigrationTracker::connectToNativeWindow(QWindow *window)
{
KIS_SAFE_ASSERT_RECOVER_RETURN(window);
- connect(window, &QWindow::screenChanged, this, &KisScreenMigrationTracker::slotScreenChanged);
- connectScreenSignals(window->screen());
- Q_EMIT sigScreenChanged(window->screen());
- Q_EMIT sigScreenOrResolutionChanged(window->screen());
-}
+ if (window != m_connectedTopLevelWindow) {
+ m_topLevelWindowConnection =
+ connect(window, &QWindow::screenChanged, this, &KisScreenMigrationTracker::slotScreenChanged);
+ connectScreenSignals(window->screen());
+ m_connectedTopLevelWindow = window;
-bool KisScreenMigrationTracker::eventFilter(QObject *watched, QEvent *event)
-{
- if (watched == m_trackedWidget && event->type() == QEvent::Show) {
- m_trackedTopLevelWindow = findNearestParentWithNativeWindow(m_trackedWidget);
- if (m_trackedTopLevelWindow) {
- connectTopLevelWindow(m_trackedTopLevelWindow);
- m_trackedWidget->removeEventFilter(this);
- }
+ Q_EMIT sigScreenChanged(window->screen());
+ Q_EMIT sigScreenOrResolutionChanged(window->screen());
}
-
- return QObject::eventFilter(watched, event);
+}
+void KisScreenMigrationTracker::disconnectFromNativeWindow()
+{
+ disconnect(m_topLevelWindowConnection);
+ m_connectedTopLevelWindow.clear();
+ m_screenConnections.clear();
}
void KisScreenMigrationTracker::slotScreenChanged(QScreen *screen)
@@ -117,6 +91,11 @@ void KisScreenMigrationTracker::slotScreenLogicalResolutionChanged(qreal value)
void KisScreenMigrationTracker::slotResolutionCompressorTriggered()
{
- KIS_SAFE_ASSERT_RECOVER_RETURN(m_trackedTopLevelWindow);
- Q_EMIT sigScreenOrResolutionChanged(m_trackedTopLevelWindow->screen());
+ if (!m_connectedTopLevelWindow) {
+ // the tracker is not yet initialized, it should happen only
+ // when the widget have not yet been shown at least once
+ KIS_SAFE_ASSERT_RECOVER_NOOP(!trackedWidget()->isVisible());
+ return;
+ }
+ Q_EMIT sigScreenOrResolutionChanged(m_connectedTopLevelWindow->screen());
}
diff --git a/libs/widgetutils/KisScreenMigrationTracker.h b/libs/widgetutils/KisScreenMigrationTracker.h
index ec8e14e41d..c1629aaee4 100644
--- a/libs/widgetutils/KisScreenMigrationTracker.h
+++ b/libs/widgetutils/KisScreenMigrationTracker.h
@@ -7,9 +7,11 @@
#ifndef KISSCREENMIGRATIONTRACKER_H
#define KISSCREENMIGRATIONTRACKER_H
-#include <QObject>
-#include <QPointer>
-#include <kritawidgetutils_export.h>
+#include <KisRootSurfaceTrackerBase.h>
+
+//#include <QObject>
+//#include <QPointer>
+//#include <kritawidgetutils_export.h>
#include <kis_signal_auto_connection.h>
@@ -26,7 +28,7 @@ class KisSignalCompressor;
* the widget is created, then it subscribes to widget's QEvent::Show event
* and waits until the widget is displayed.
*/
-class KRITAWIDGETUTILS_EXPORT KisScreenMigrationTracker : public QObject
+class KRITAWIDGETUTILS_EXPORT KisScreenMigrationTracker : public KisRootSurfaceTrackerBase
{
Q_OBJECT
public:
@@ -65,16 +67,17 @@ Q_SIGNALS:
private:
void connectScreenSignals(QScreen *screen);
- void connectTopLevelWindow(QWindow *window);
protected:
- bool eventFilter(QObject *watched, QEvent *event) override;
+ void connectToNativeWindow(QWindow *window) override;
+ void disconnectFromNativeWindow() override;
private:
Q_DISABLE_COPY_MOVE(KisScreenMigrationTracker)
- QWidget *m_trackedWidget {nullptr};
- QPointer<QWindow> m_trackedTopLevelWindow;
+ QPointer<QWindow> m_connectedTopLevelWindow;
+ QMetaObject::Connection m_topLevelWindowConnection;
+
KisSignalAutoConnectionsStore m_screenConnections;
KisSignalCompressor *m_resolutionChangeCompressor;
};