Check for null pointer in OSD Pretty

This commit is contained in:
Jonas Kvinge
2020-04-06 22:01:44 +02:00
parent b92961fda0
commit 4a0235c2ed
2 changed files with 22 additions and 11 deletions

View File

@@ -166,13 +166,15 @@ void OSDPretty::showEvent(QShowEvent *e) {
} }
// Get current screen resolution // Get current screen resolution
QRect screenResolution = current_screen()->availableGeometry(); QScreen *screen = current_screen();
if (screen) {
// Leave 200 px for icon QRect resolution = screen->availableGeometry();
ui_->summary->setMaximumWidth(screenResolution.width() - 200); // Leave 200 px for icon
ui_->message->setMaximumWidth(screenResolution.width() - 200); ui_->summary->setMaximumWidth(resolution.width() - 200);
// Set maximum size for the OSD, a little margin here too ui_->message->setMaximumWidth(resolution.width() - 200);
setMaximumSize(screenResolution.width() - 100, screenResolution.height() - 100); // 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); setWindowOpacity(fading_enabled_ ? 0.0 : 1.0);
@@ -489,7 +491,7 @@ void OSDPretty::mouseMoveEvent(QMouseEvent *e) {
void OSDPretty::mouseReleaseEvent(QMouseEvent *) { void OSDPretty::mouseReleaseEvent(QMouseEvent *) {
if (mode_ == Mode_Draggable) { if (current_screen() && mode_ == Mode_Draggable) {
popup_screen_ = current_screen(); popup_screen_ = current_screen();
popup_screen_name_ = current_screen()->name(); popup_screen_name_ = current_screen()->name();
popup_pos_ = current_pos(); 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)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
return QGuiApplication::screenAt(pos()); screen = QGuiApplication::screenAt(pos);
#else #else
return (window() && window()->windowHandle() ? window()->windowHandle()->screen() : nullptr); if (window() && window()->windowHandle()) screen = window()->windowHandle()->screen();
#endif #endif
if (!screen) screen = QGuiApplication::primaryScreen();
return screen;
} }
QScreen *OSDPretty::current_screen() const { return current_screen(pos()); }
QPoint OSDPretty::current_pos() const { QPoint OSDPretty::current_pos() const {
if (current_screen()) { if (current_screen()) {

View File

@@ -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. // 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. // Note that these return invalid values if the popup is hidden.
QScreen *current_screen() const; QScreen *current_screen() const;
QScreen *current_screen(const QPoint &pos) const;
QPoint current_pos() const; QPoint current_pos() const;
// QWidget // QWidget