diff --git a/mainwindow.cpp b/mainwindow.cpp
index 38c3ba7..cf6966a 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -24,10 +24,9 @@ along with TuxClocker. If not, see .*/
#include "nvidia.h"
#include
-
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::MainWindow)
+ ui(new Ui::MainWindow), trayIcon(new QSystemTrayIcon(this))
{
ui->setupUi(this);
@@ -128,6 +127,26 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int)));
connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));
+
+ /*Create tray icon */
+ {
+ auto appIcon = QIcon(":/icons/gpuonfire.svg");
+
+ if (!QSystemTrayIcon::isSystemTrayAvailable())
+ {
+#ifdef dbg
+ std::cout << "Qt: System tray unavailable.\n";
+#endif
+ ignore_closeEvent = false;
+ MainWindow::show();
+ }
+
+ this->trayIcon->setIcon(appIcon);
+ auto menu = this->createMenu();
+ this->trayIcon->setContextMenu(menu);
+ this->trayIcon->setToolTip(QString("TuxClocker"));
+ this->trayIcon->show();
+ }
}
MainWindow::~MainWindow()
@@ -1127,3 +1146,25 @@ void MainWindow::on_GPUComboBox_currentIndexChanged(int index)
curmaxmemclk->setText(1, QString::number(nv->GPUList[index].maxMemClk) + "MHz");
curmaxclk->setText(1, QString::number(nv->GPUList[index].maxCoreClk) + "MHz");
}
+
+QMenu* MainWindow::createMenu()
+{
+ auto menu = new QMenu(this);
+
+ QAction* show = new QAction("&Open settings", this);
+ connect(show, &QAction::triggered, this, [=]{MainWindow::show();});
+ menu->addAction(show);
+
+ QAction* quit = new QAction("&Quit", this);
+ connect(quit, &QAction::triggered, this, [=]{QApplication::quit();});
+ menu->addAction(quit);
+
+ return menu;
+}
+
+
+void MainWindow::closeEvent(QCloseEvent* e)
+{
+ MainWindow::hide();
+ if(ignore_closeEvent) e->ignore();
+}
diff --git a/mainwindow.h b/mainwindow.h
index 8f9686b..8ac89d4 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -251,6 +251,10 @@ private:
plotCmds fanspeedplot;
QVector plotCmdsList;
+ QSystemTrayIcon* trayIcon;
+ QMenu* createMenu();
+ void closeEvent(QCloseEvent *);
+ bool ignore_closeEvent = true;
};
#endif // MAINWINDOW_H