diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index d7aeedd..9208ed9 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -863,9 +863,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { //setAttribute(Qt::WA_TranslucentBackground); //setStyleSheet("background-color: rgba(255,182,193,60%);"); setWindowTitle(STRING_TITLE); - connect(qApp, &QGuiApplication::applicationStateChanged, this, [=](Qt::ApplicationState state){ - if(state == Qt::ApplicationState::ApplicationInactive) hide(); -}); /* * Registering needed custom events */ @@ -880,6 +877,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { /* This spacer provides proper spacing when window vertically > widgets. */ lastRowSpacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); ewsUpdateTimer = new QTimer(this); + recentlyClosedTimer = new QTimer(this); widget = new QWidget(); widgetLayout = new QGridLayout(); trayIcon = new QSystemTrayIcon(); @@ -890,6 +888,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ewsUpdateTimer->setSingleShot(true); ewsUpdateTimer->setInterval(ewsUpdateTimerFrequency); connect(ewsUpdateTimer, &QTimer::timeout, this, &MainWindow::reorderEndpointWidgetCollection); + + recentlyClosedTimer->setSingleShot(true); + recentlyClosedTimer->setInterval(recentlyClosedTimerFrequency); + connect(recentlyClosedTimer, &QTimer::timeout, this, [=]() { this->recentlyClosed = false; }); //widget->setMinimumSize(QSize(300,300)); //widget->setLayout(widgetLayout); /* @@ -936,7 +938,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { trayIcon->setToolTip(STRING_TITLE); trayIcon->setContextMenu(trayIconMenu); connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated); - + connect(qApp, &QGuiApplication::applicationStateChanged, this, [=](Qt::ApplicationState state){ + if(state == Qt::ApplicationState::ApplicationInactive) { + this->hide(); + //This recentlyClosed... kinda campy. + this->recentlyClosed = true; + this->recentlyClosedTimer->start(); + } + }); /* * Set of function callback definitons for EndpointSituationCallback */ @@ -1034,9 +1043,12 @@ void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { switch (reason) { case QSystemTrayIcon::Trigger: - this->compose(); - this->showNormal(); - this->activateWindow(); + if (!this->isVisible() && !recentlyClosed) { + log_to_file("Recently Closed: %d \n", recentlyClosed); + this->compose(); + this->showNormal(); + this->activateWindow(); + } break; default: break; diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index adcb8b1..48dd06b 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -261,6 +261,9 @@ private: QTimer *ewsUpdateTimer; static constexpr uint64_t ewsUpdateTimerFrequency = 500; double widthRatio = 0.28; + bool recentlyClosed = false; + uint8_t recentlyClosedTimerFrequency = 1000; + QTimer *recentlyClosedTimer; QScrollArea *scrollArea; HeaderWidget* hw;