diff --git a/src/widgets/osdpretty.cpp b/src/widgets/osdpretty.cpp index 567f5d6ba..a85ab0b60 100644 --- a/src/widgets/osdpretty.cpp +++ b/src/widgets/osdpretty.cpp @@ -166,13 +166,15 @@ void OSDPretty::showEvent(QShowEvent *e) { } // Get current screen resolution - QRect screenResolution = current_screen()->availableGeometry(); - - // Leave 200 px for icon - ui_->summary->setMaximumWidth(screenResolution.width() - 200); - ui_->message->setMaximumWidth(screenResolution.width() - 200); - // Set maximum size for the OSD, a little margin here too - setMaximumSize(screenResolution.width() - 100, screenResolution.height() - 100); + QScreen *screen = current_screen(); + if (screen) { + QRect resolution = screen->availableGeometry(); + // Leave 200 px for icon + ui_->summary->setMaximumWidth(resolution.width() - 200); + ui_->message->setMaximumWidth(resolution.width() - 200); + // Set maximum size for the OSD, a little margin here too + setMaximumSize(resolution.width() - 100, resolution.height() - 100); + } setWindowOpacity(fading_enabled_ ? 0.0 : 1.0); @@ -489,7 +491,7 @@ void OSDPretty::mouseMoveEvent(QMouseEvent *e) { void OSDPretty::mouseReleaseEvent(QMouseEvent *) { - if (mode_ == Mode_Draggable) { + if (current_screen() && mode_ == Mode_Draggable) { popup_screen_ = current_screen(); popup_screen_name_ = current_screen()->name(); popup_pos_ = current_pos(); @@ -497,14 +499,22 @@ void OSDPretty::mouseReleaseEvent(QMouseEvent *) { } -QScreen *OSDPretty::current_screen() const { +QScreen *OSDPretty::current_screen(const QPoint &pos) const { + + QScreen *screen(nullptr); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - return QGuiApplication::screenAt(pos()); + screen = QGuiApplication::screenAt(pos); #else - return (window() && window()->windowHandle() ? window()->windowHandle()->screen() : nullptr); + if (window() && window()->windowHandle()) screen = window()->windowHandle()->screen(); #endif + if (!screen) screen = QGuiApplication::primaryScreen(); + + return screen; + } +QScreen *OSDPretty::current_screen() const { return current_screen(pos()); } + QPoint OSDPretty::current_pos() const { if (current_screen()) { diff --git a/src/widgets/osdpretty.h b/src/widgets/osdpretty.h index b74e0af88..b8a761e22 100644 --- a/src/widgets/osdpretty.h +++ b/src/widgets/osdpretty.h @@ -98,6 +98,7 @@ class OSDPretty : public QWidget { // When the user has been moving the popup, use these to get its current position and screen. // Note that these return invalid values if the popup is hidden. QScreen *current_screen() const; + QScreen *current_screen(const QPoint &pos) const; QPoint current_pos() const; // QWidget