From 92c58b0b600835973a9b611507c9a78999575f20 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 7 Sep 2025 15:46:26 +0200 Subject: [PATCH] Fix showing error dialog minimized when main window is not active Fixes #1739 --- src/core/mainwindow.cpp | 35 +++++++++++++++++++++++------------ src/core/mainwindow.h | 7 ++++--- src/dialogs/errordialog.cpp | 29 ++++++++++++++++++++++------- src/dialogs/errordialog.h | 6 ++++-- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index c4f5a9af3..756b45eba 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -2,7 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2013-2021, Jonas Kvinge + * Copyright 2013-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -296,6 +296,9 @@ MainWindow::MainWindow(Application *app, #ifdef HAVE_DISCORD_RPC discord_rich_presence_(discord_rich_presence), #endif + error_dialog_([this]() { + return new ErrorDialog(this); + }), console_([app, this]() { Console *console = new Console(app->database()); QObject::connect(console, &Console::Error, this, &MainWindow::ShowErrorDialog); @@ -1684,17 +1687,6 @@ void MainWindow::StopAfterCurrent() { Q_EMIT StopAfterToggled(app_->playlist_manager()->active()->stop_after_current()); } -void MainWindow::showEvent(QShowEvent *e) { - - if (error_dialog_ && error_dialog_->isVisible() && error_dialog_->isMinimized()) { - error_dialog_->raise(); - error_dialog_->activateWindow(); - } - - QMainWindow::showEvent(e); - -} - void MainWindow::hideEvent(QHideEvent *e) { // Some window managers don't remember maximized state between @@ -1717,6 +1709,16 @@ void MainWindow::closeEvent(QCloseEvent *e) { } +void MainWindow::changeEvent(QEvent *e) { + + if (e->type() == QEvent::Show || e->type() == QEvent::WindowStateChange || e->type() == QEvent::WindowActivate) { + CheckShowErrorDialog(); + } + + QMainWindow::changeEvent(e); + +} + void MainWindow::SetHiddenInTray(const bool hidden) { if (hidden && isVisible()) { @@ -1737,6 +1739,7 @@ void MainWindow::SetHiddenInTray(const bool hidden) { else { show(); } + CheckShowErrorDialog(); } } @@ -2990,6 +2993,14 @@ void MainWindow::ShowErrorDialog(const QString &message) { error_dialog_->ShowMessage(message); } +void MainWindow::CheckShowErrorDialog() { + + if (isVisible() && !isMinimized() && error_dialog_ && error_dialog_->isVisible() && !error_dialog_->isActiveWindow()) { + error_dialog_->ShowDialog(); + } + +} + void MainWindow::CheckFullRescanRevisions() { int from = app_->database()->startup_schema_version(); diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 883d44d36..b3d83ef4b 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -2,7 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2013-2021, Jonas Kvinge + * Copyright 2013-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -124,9 +124,9 @@ class MainWindow : public QMainWindow, public PlatformInterface { void CommandlineOptionsReceived(const CommandlineOptions &options); protected: - void showEvent(QShowEvent *e) override; void hideEvent(QHideEvent *e) override; void closeEvent(QCloseEvent *e) override; + void changeEvent(QEvent *e) override; void keyPressEvent(QKeyEvent *e) override; #ifdef Q_OS_WIN32 bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; @@ -236,6 +236,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { void ShowAboutDialog(); void ShowErrorDialog(const QString &message); + void CheckShowErrorDialog(); void ShowTranscodeDialog(); SettingsDialog *CreateSettingsDialog(); EditTagDialog *CreateEditTagDialog(); @@ -315,6 +316,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { #ifdef HAVE_DISCORD_RPC discord::RichPresence *discord_rich_presence_; #endif + Lazy error_dialog_; Lazy about_dialog_; Lazy console_; Lazy edit_tag_dialog_; @@ -329,7 +331,6 @@ class MainWindow : public QMainWindow, public PlatformInterface { PlaylistListContainer *playlist_list_; QueueView *queue_view_; - Lazy error_dialog_; Lazy settings_dialog_; Lazy cover_manager_; SharedPtr equalizer_; diff --git a/src/dialogs/errordialog.cpp b/src/dialogs/errordialog.cpp index e5b505732..564560f4b 100644 --- a/src/dialogs/errordialog.cpp +++ b/src/dialogs/errordialog.cpp @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2017-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,14 +33,16 @@ #include #include +#include "utilities/screenutils.h" + #include "errordialog.h" #include "ui_errordialog.h" using namespace Qt::Literals::StringLiterals; -ErrorDialog::ErrorDialog(QWidget *parent) +ErrorDialog::ErrorDialog(QWidget *mainwindow, QWidget *parent) : QDialog(parent), - parent_(parent), + mainwindow_(mainwindow), ui_(new Ui_ErrorDialog) { ui_->setupUi(this); @@ -59,6 +62,18 @@ ErrorDialog::~ErrorDialog() { delete ui_; } +void ErrorDialog::ShowDialog() { + + if (screen() && mainwindow_->screen() && screen() != mainwindow_->screen()) { + Utilities::CenterWidgetOnScreen(mainwindow_->screen(), this); + } + setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); + show(); + raise(); + activateWindow(); + +} + void ErrorDialog::ShowMessage(const QString &message) { if (message.isEmpty()) return; @@ -66,11 +81,11 @@ void ErrorDialog::ShowMessage(const QString &message) { current_messages_ << message; UpdateContent(); - show(); - - if (parent_ && parent_->isMaximized()) { - raise(); - activateWindow(); + if (mainwindow_->isActiveWindow()) { + ShowDialog(); + } + else if (!isVisible()) { + showMinimized(); } } diff --git a/src/dialogs/errordialog.h b/src/dialogs/errordialog.h index 494741f15..e9e84bba8 100644 --- a/src/dialogs/errordialog.h +++ b/src/dialogs/errordialog.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2017-2025, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,10 +37,11 @@ class ErrorDialog : public QDialog { Q_OBJECT public: - explicit ErrorDialog(QWidget *parent = nullptr); + explicit ErrorDialog(QWidget *mainwindow, QWidget *parent = nullptr); ~ErrorDialog() override; public Q_SLOTS: + void ShowDialog(); void ShowMessage(const QString &message); protected: @@ -48,7 +50,7 @@ class ErrorDialog : public QDialog { private: void UpdateContent(); - QWidget *parent_; + QWidget *mainwindow_; Ui_ErrorDialog *ui_; QStringList current_messages_;