diff --git a/libs/ui/KisMainWindow.h b/libs/ui/KisMainWindow.h --- a/libs/ui/KisMainWindow.h +++ b/libs/ui/KisMainWindow.h @@ -419,6 +419,7 @@ void showManual(); void switchTab(int index); + void windowScreenChanged(QScreen *screen); protected: @@ -431,8 +432,6 @@ void dragMoveEvent(QDragMoveEvent * event) override; void dragLeaveEvent(QDragLeaveEvent * event) override; - void moveEvent(QMoveEvent *e) override; - private: diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp --- a/libs/ui/KisMainWindow.cpp +++ b/libs/ui/KisMainWindow.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -536,6 +537,9 @@ menuBar()->setVisible(true); } + this->winId(); // Ensures the native window has been created. + QWindow *window = this->windowHandle(); + connect(window, SIGNAL(screenChanged(QScreen *)), this, SLOT(windowScreenChanged(QScreen *))); } @@ -2638,42 +2642,12 @@ QDesktopServices::openUrl(QUrl("https://docs.krita.org")); } -void KisMainWindow::moveEvent(QMoveEvent *e) +void KisMainWindow::windowScreenChanged(QScreen *screen) { - /** - * For checking if the display number has changed or not we should always use - * positional overload, not using QWidget overload. Otherwise we might get - * inconsistency, because screenNumber(widget) can return -1, but screenNumber(pos) - * will always return the nearest screen. - */ - - const int oldScreen = qApp->desktop()->screenNumber(e->oldPos()); - const int newScreen = qApp->desktop()->screenNumber(e->pos()); - - if (oldScreen != newScreen) { - emit screenChanged(); - } - - if (d->screenConnectionsStore.isEmpty() || oldScreen != newScreen) { - - d->screenConnectionsStore.clear(); - - QScreen *newScreenObject = 0; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) - newScreenObject = qApp->screenAt(e->pos()); -#else - // TODO: i'm not sure if this pointer already has a correct value - // by the moment we get the event. It might not work on older - // versions of Qt - newScreenObject = qApp->primaryScreen(); -#endif - - if (newScreenObject) { - d->screenConnectionsStore.addConnection(newScreenObject, SIGNAL(physicalDotsPerInchChanged(qreal)), - this, SIGNAL(screenChanged())); - } - } + emit screenChanged(); + d->screenConnectionsStore.clear(); + d->screenConnectionsStore.addConnection(screen, SIGNAL(physicalDotsPerInchChanged(qreal)), + this, SIGNAL(screenChanged())); }