From 8706a3955940c1fa340497ab179c111a11d2dd92 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sun, 29 Mar 2020 10:58:47 -0700 Subject: [PATCH] OSDPretty: Consolidate current_screen code in OSDPretty --- src/widgets/osdpretty.cpp | 14 +++++--------- src/widgets/osdpretty.h | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/widgets/osdpretty.cpp b/src/widgets/osdpretty.cpp index f253d2f58..d59929ddf 100644 --- a/src/widgets/osdpretty.cpp +++ b/src/widgets/osdpretty.cpp @@ -423,13 +423,7 @@ void OSDPretty::mouseMoveEvent(QMouseEvent* e) { QPoint new_pos = original_window_pos_ + delta; // Keep it to the bounds of the desktop -#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - QScreen* screen = QGuiApplication::screenAt(e->globalPos()); -#else - QScreen* screen = (window() && window()->windowHandle() - ? window()->windowHandle()->screen() - : QGuiApplication::primaryScreen()); -#endif + QScreen* screen = current_screen(e->globalPos()); if (!screen) return; QRect geometry = screen->availableGeometry(); @@ -452,9 +446,9 @@ void OSDPretty::mouseMoveEvent(QMouseEvent* e) { } } -QScreen* OSDPretty::current_screen() const { +QScreen* OSDPretty::current_screen(const QPoint& pos) const { #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - return QGuiApplication::screenAt(pos()); + return QGuiApplication::screenAt(pos); #else return (window() && window()->windowHandle() ? window()->windowHandle()->screen() @@ -462,6 +456,8 @@ QScreen* OSDPretty::current_screen() const { #endif } +QScreen* OSDPretty::current_screen() const { return current_screen(pos()); } + QPoint OSDPretty::current_pos() const { if (current_screen()) { QRect geometry = current_screen()->availableGeometry(); diff --git a/src/widgets/osdpretty.h b/src/widgets/osdpretty.h index ec5ea7354..b7ea14ba7 100644 --- a/src/widgets/osdpretty.h +++ b/src/widgets/osdpretty.h @@ -77,6 +77,7 @@ class OSDPretty : public QWidget { // 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