From 788747c071f2f26e908eaf6c0b62fa05d8475fa3 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 21 May 2022 19:12:22 +0200 Subject: [PATCH] MainWindow: Remove unnecessary hide() --- src/core/mainwindow.cpp | 23 +++++++++++++++-------- src/core/mainwindow.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index bbc1b32b4..5b9269dfb 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -336,7 +336,8 @@ MainWindow::MainWindow(Application *app, std::shared_ptr tray_ic hidden_(false), exit_(false), exit_count_(0), - delete_files_(false) { + delete_files_(false), + ignore_close_(false) { qLog(Debug) << "Starting"; @@ -962,7 +963,6 @@ MainWindow::MainWindow(Application *app, std::shared_ptr tray_ic break; case BehaviourSettingsPage::Startup_Hide: if (tray_icon_->IsSystemTrayAvailable() && tray_icon_->isVisible()) { - hide(); break; } // fallthrough @@ -982,7 +982,9 @@ MainWindow::MainWindow(Application *app, std::shared_ptr tray_ic } else { hidden_ = settings_.value("hidden", false).toBool(); - setVisible(!hidden_); + if (!hidden_) { + show(); + } } break; } @@ -1224,7 +1226,8 @@ void MainWindow::Exit() { QObject::connect(app_->player()->engine(), &EngineBase::FadeoutFinishedSignal, this, &MainWindow::DoExit); if (app_->player()->GetState() == Engine::Playing) { app_->player()->Stop(); - hide(); + ignore_close_ = true; + close(); if (tray_icon_->IsSystemTrayAvailable()) { tray_icon_->setVisible(false); } @@ -1552,16 +1555,13 @@ void MainWindow::VolumeWheelEvent(const int delta) { void MainWindow::ToggleShowHide() { if (hidden_) { - show(); SetHiddenInTray(false); } else if (isActiveWindow()) { - hide(); setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); SetHiddenInTray(true); } else if (isMinimized()) { - hide(); setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); SetHiddenInTray(false); } @@ -1596,6 +1596,12 @@ void MainWindow::showEvent(QShowEvent *e) { void MainWindow::closeEvent(QCloseEvent *e) { + if (ignore_close_) { + ignore_close_ = false; + QMainWindow::closeEvent(e); + return; + } + if (!exit_) { if (!hidden_ && keep_running_ && tray_icon_->IsSystemTrayAvailable()) { SetHiddenInTray(true); @@ -1618,7 +1624,8 @@ void MainWindow::SetHiddenInTray(const bool hidden) { if (hidden) { was_maximized_ = isMaximized(); was_minimized_ = isMinimized(); - hide(); + ignore_close_ = true; + close(); } else { if (was_minimized_) { diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 5e3a0088c..8b7f27844 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -395,6 +395,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { bool exit_; int exit_count_; bool delete_files_; + bool ignore_close_; };