diff options
Diffstat (limited to 'facetracknoir')
-rw-r--r-- | facetracknoir/ui.cpp | 22 | ||||
-rw-r--r-- | facetracknoir/ui.h | 7 |
2 files changed, 25 insertions, 4 deletions
diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index edd3a818..44eff98e 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -81,11 +81,13 @@ MainWindow::MainWindow() : ensure_tray(); if (s.tray_enabled) - hide(); + setWindowState(Qt::WindowMinimized); } MainWindow::~MainWindow() { + if (tray) + tray->hide(); stopTracker(); save(); _exit(0); @@ -413,12 +415,28 @@ void MainWindow::shortcutToggled() void MainWindow::ensure_tray() { + if (tray) + tray->hide(); tray = nullptr; if (s.tray_enabled) { tray = std::make_shared<QSystemTrayIcon>(this); tray->setIcon(QIcon(":/images/facetracknoir.png")); tray->show(); - connect(tray.get(), SIGNAL(activated()), this, SLOT(show())); + connect(tray.get(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(restore_from_tray(QSystemTrayIcon::ActivationReason))); } } + +void MainWindow::restore_from_tray(QSystemTrayIcon::ActivationReason) +{ + show(); + setWindowState(Qt::WindowNoState); +} + +void MainWindow::changeEvent(QEvent* e) +{ + if (e->type() == QEvent::WindowStateChange && (windowState() & Qt::WindowMinimized)) + hide(); + QMainWindow::changeEvent(e); +} diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h index 9419936f..4158e29e 100644 --- a/facetracknoir/ui.h +++ b/facetracknoir/ui.h @@ -44,7 +44,7 @@ # include <windows.h> #endif -#include "ui_facetracknoir.h" +#include "ui_main.h" #include "opentrack/options.hpp" #include "opentrack/main-settings.hpp" @@ -85,13 +85,14 @@ class MainWindow : public QMainWindow, private State return modules.filters().value(ui.iconcomboFilter->currentIndex(), nullptr); } + void changeEvent(QEvent* e) override; + void createIconGroupBox(); void load_settings(); void updateButtonState(bool running, bool inertialp); void fill_profile_combobox(); void display_pose(const double* mapped, const double* raw); void ensure_tray(); - public slots: void shortcutRecentered(); void shortcutToggled(); @@ -112,6 +113,8 @@ private slots: void startTracker(); void stopTracker(); + + void restore_from_tray(QSystemTrayIcon::ActivationReason); public: MainWindow(); ~MainWindow(); |