From 546a8a06d3eb5285e89a7b6be56f912197e8761c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 5 Apr 2019 02:59:56 +0200 Subject: [PATCH] Ref T592, improved position handling/failover: use screen position if main widget pos. is unavailable --- src/blackgui/dockwidget.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/blackgui/dockwidget.cpp b/src/blackgui/dockwidget.cpp index f5c6a89b9..47bf93738 100644 --- a/src/blackgui/dockwidget.cpp +++ b/src/blackgui/dockwidget.cpp @@ -411,13 +411,7 @@ namespace BlackGui } // and move - QPoint mainWindowPos = BlackGui::CGuiUtility::mainWidgetPosition(); - if (!mainWindowPos.isNull()) - { - int x = mainWindowPos.x() + m_offsetWhenFloating.x(); - int y = mainWindowPos.y() + m_offsetWhenFloating.y(); - this->move(x, y); - } + this->resetPosition(); } QString CDockWidget::windowTitleOrBackup() const @@ -623,6 +617,17 @@ namespace BlackGui { // center on screen when floating if (!this->isFloating()) { return; } - this->move(sGui->currentScreen()->geometry().center() - this->rect().center()); + if (!sGui) { return; } + + // pos can be null during init + QPoint pos = CGuiUtility::mainWidgetGlobalPosition(); + if (pos.isNull()) + { + pos = sGui->currentScreen()->geometry().center() - this->rect().center(); + } + + const int x = pos.x() + m_offsetWhenFloating.x(); + const int y = pos.y() + m_offsetWhenFloating.y(); + this->move(x, y); } } // namespace