From 16d09ace07bd083cc6f3898052853f6cfd4cf1a1 Mon Sep 17 00:00:00 2001 From: zan Date: Sun, 1 Nov 2020 14:55:45 -0500 Subject: [PATCH] Fix visibility incongruences --- src/ui/mainwindow.cpp | 17 ++++++++++++----- src/ui/mainwindow.h | 6 ++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 7f72f321c..08032f38b 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -1037,10 +1037,8 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, // Force the window to show in case somehow the config has tray and window set // to hide if (hidden && (!QSystemTrayIcon::isSystemTrayAvailable() || !tray_icon_ || - !tray_icon_->IsVisible())) { - settings_.setValue("hidden", false); + !tray_icon_->IsVisible())) show(); - } #endif QShortcut* close_window_shortcut = new QShortcut(this); @@ -1432,6 +1430,7 @@ void MainWindow::VolumeWheelEvent(int delta) { void MainWindow::ToggleShowHide() { if (settings_.value("hidden").toBool()) { show(); + activateWindow(); SetHiddenInTray(false); } else if (isActiveWindow()) { hide(); @@ -1466,9 +1465,17 @@ void MainWindow::closeEvent(QCloseEvent* event) { QMainWindow::closeEvent(event); } -void MainWindow::SetHiddenInTray(bool hidden) { - settings_.setValue("hidden", hidden); +void MainWindow::hideEvent(QHideEvent* event) { + settings_.setValue("hidden", true); + QMainWindow::hideEvent(event); +} +void MainWindow::showEvent(QShowEvent* event) { + settings_.setValue("hidden", false); + QMainWindow::showEvent(event); +} + +void MainWindow::SetHiddenInTray(bool hidden) { // Some window managers don't remember maximized state between calls to // hide() and show(), so we have to remember it ourself. if (hidden) { diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 2debc8ac0..4a4a74adb 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -131,10 +131,12 @@ class MainWindow : public QMainWindow, public PlatformInterface { void CommandlineOptionsReceived(const CommandlineOptions& options); protected: - void keyPressEvent(QKeyEvent* event); + void keyPressEvent(QKeyEvent*); void changeEvent(QEvent*); void resizeEvent(QResizeEvent*); - void closeEvent(QCloseEvent* event); + void closeEvent(QCloseEvent*); + void hideEvent(QHideEvent*); + void showEvent(QShowEvent*); #ifdef Q_OS_WIN32 bool winEvent(MSG* message, long* result);