Avoid crash when accessing the main windget position

This commit is contained in:
Klaus Basan
2019-04-27 14:32:29 +02:00
parent 3171bd5661
commit 242d6137e5
3 changed files with 11 additions and 6 deletions

View File

@@ -659,7 +659,7 @@ namespace BlackGui
QPoint pos = CGuiUtility::mainWidgetGlobalPosition(); QPoint pos = CGuiUtility::mainWidgetGlobalPosition();
if (pos.isNull()) if (pos.isNull())
{ {
pos = sGui->currentScreen()->geometry().center() - this->rect().center(); pos = CGuiApplication::currentScreen()->geometry().center() - this->rect().center();
} }
const int x = pos.x() + m_offsetWhenFloating.x(); const int x = pos.x() + m_offsetWhenFloating.x();

View File

@@ -355,7 +355,8 @@ namespace BlackGui
QRect CGuiApplication::currentScreenGeometry() QRect CGuiApplication::currentScreenGeometry()
{ {
const QScreen *s = currentScreen(); const QScreen *s = currentScreen();
return s->geometry(); if (s) return s->geometry();
return {};
} }
void CGuiApplication::modalWindowToFront() void CGuiApplication::modalWindowToFront()

View File

@@ -317,9 +317,13 @@ namespace BlackGui
QPoint CGuiUtility::mainWidgetGlobalPosition() QPoint CGuiUtility::mainWidgetGlobalPosition()
{ {
CEnableForFramelessWindow *mw = CGuiUtility::mainFramelessEnabledWindow(); QWidget *mw = CGuiUtility::mainApplicationWidget();
if (!mw || !mw->getWidget()) { QPoint(); } if (mw) { return mw->pos(); }
return mw->getWidget()->pos(); // is main window, so not mapToGlobal
// fallback, can be mfw it is not found
CEnableForFramelessWindow *mfw = CGuiUtility::mainFramelessEnabledWindow();
if (!mfw || !mfw->getWidget()) { return QPoint(); }
return mfw->getWidget()->pos(); // is main window, so not mapToGlobal
} }
QString CGuiUtility::replaceTabCountValue(const QString &oldName, int count) QString CGuiUtility::replaceTabCountValue(const QString &oldName, int count)
@@ -353,7 +357,7 @@ namespace BlackGui
delete widget; delete widget;
} }
} }
else {delete item;} else { delete item; }
} }
// then finally // then finally