diff options
author | Be <be@mixxx.org> | 2020-07-07 14:11:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 14:11:25 -0500 |
commit | 172aea96ab49aec3164a974973891f6c621bcd71 (patch) | |
tree | 7d6e13d68c89be4fe8ae4293b54bcb7e88b4a913 | |
parent | 3415fc1311d1704bd3450bdef240f48ed4733b12 (diff) | |
parent | 2bcd730feed8bf59e6bb32ae2893aca6da17708d (diff) |
Merge pull request #2860 from Be-ing/widgethelper_crash
widgethelper: hack around crash when right clicking cues
-rw-r--r-- | src/util/widgethelper.cpp | 17 | ||||
-rw-r--r-- | src/util/widgethelper.h | 8 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/util/widgethelper.cpp b/src/util/widgethelper.cpp index 6de2a7beb5..dc35c09bd6 100644 --- a/src/util/widgethelper.cpp +++ b/src/util/widgethelper.cpp @@ -13,7 +13,11 @@ QPoint mapPopupToScreen( const QWidget& widget, const QPoint& popupUpperLeft, const QSize& popupSize) { - const auto screenSize = widget.windowHandle()->screen()->size(); + const auto* pWindow = getWindow(widget); + if (!pWindow) { + return popupUpperLeft; + } + const auto screenSize = pWindow->screen()->size(); // math_clamp() cannot be used, because if the dimensions of // the popup menu are greater than the screen size a debug // assertion would be triggered! @@ -28,6 +32,17 @@ QPoint mapPopupToScreen( return QPoint(adjustedX, adjustedY); } +QWindow* getWindow( + const QWidget& widget) { + if (auto* window = widget.windowHandle()) { + return window; + } + if (auto* nativeParent = widget.nativeParentWidget()) { + return nativeParent->windowHandle(); + } + return nullptr; +} + } // namespace widgethelper } // namespace mixxx diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h index 94a17b77d3..c6ce078a9c 100644 --- a/src/util/widgethelper.h +++ b/src/util/widgethelper.h @@ -16,6 +16,14 @@ QPoint mapPopupToScreen( const QPoint& popupUpperLeft, const QSize& popupSize); +/// Obtains the corresponding window for the given widget. +/// +/// Might return nullptr if no window could be determined. +/// +/// Adopted from windowForWidget() in qtbase/src/widgets/kernel/qapplication_p.h +QWindow* getWindow( + const QWidget& widget); + } // namespace widgethelper } // namespace mixxx |