From b68696d91eac17f972998b7aa70a781a97ce3b95 Mon Sep 17 00:00:00 2001 From: Jahn Date: Sun, 24 Nov 2024 07:35:34 +0100 Subject: [PATCH] feat: add cmdline option to hide system tray icon --- src/main.cc | 6 +++++- src/projecteurapp.cc | 6 ++++-- src/projecteurapp.h | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.cc b/src/main.cc index 26b452f..617acaa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -201,6 +201,7 @@ namespace { const QCommandLineOption logLvlOption_ = {QStringList{ "l", "log-level" }, Main::tr("Set log level (dbg,inf,wrn,err)."), "lvl"}; const QCommandLineOption disableUInputOption_ = {QStringList{ "disable-uinput" }, Main::tr("Disable uinput support.")}; const QCommandLineOption showDlgOnStartOption_ = {QStringList{ "show-dialog" }, Main::tr("Show preferences dialog on start.")}; + const QCommandLineOption hideSysTrayOption_ = {QStringList{ "hide-systray-icon"}, Main::tr("Hide the system tray icon.")}; const QCommandLineOption dialogMinOnlyOption_ = {QStringList{ "m", "minimize-only" }, Main::tr("Only allow minimizing the dialog.")}; const QCommandLineOption disableOverlayOption_ = {QStringList{ "disable-overlay" }, Main::tr("Disable spotlight overlay completely.")}; const QCommandLineOption additionalDeviceOption_ = {QStringList{ "D", "additional-device"}, @@ -215,7 +216,7 @@ namespace { parser.addOptions({versionOption_, helpOption_, fullHelpOption_, commandOption_, cfgFileOption_, fullVersionOption_, deviceInfoOption_, logLvlOption_, disableUInputOption_, showDlgOnStartOption_, dialogMinOnlyOption_, - disableOverlayOption_, additionalDeviceOption_}); + disableOverlayOption_, additionalDeviceOption_, hideSysTrayOption_}); } // --------------------------------------------------------------------------------------------- @@ -236,6 +237,7 @@ namespace { auto cfgFileOptionValue() const { return parser.value(cfgFileOption_); } bool logLvlOptionSet() const { return parser.isSet(logLvlOption_); } auto logLvlOptionValue() const { return parser.value(logLvlOption_); } + bool hideSysTrayOptionSet() const { return parser.isSet(hideSysTrayOption_); } // --------------------------------------------------------------------------------------------- void processArgs(int argc, char** argv) @@ -282,6 +284,7 @@ namespace { if (fullHelp) { print() << " --disable-uinput " << disableUInputOption_.description(); print() << " --show-dialog " << showDlgOnStartOption_.description(); + print() << " --hide-systray-icon " << hideSysTrayOption_.description(); print() << " -m, --minimize-only " << dialogMinOnlyOption_.description(); } print() << " -c COMMAND|PROPERTY " << commandOption_.description() << std::endl; @@ -388,6 +391,7 @@ int main(int argc, char *argv[]) options.showPreferencesOnStart = parser.showDlgOnStartOptionSet(); options.dialogMinimizeOnly = parser.dialogMinOnlyOptionSet(); options.disableOverlay = parser.disableOverlayOptionSet(); + options.hideSysTrayIcon = parser.hideSysTrayOptionSet(); if (parser.logLvlOptionSet()) { const auto lvl = logging::levelFromName(parser.logLvlOptionValue()); diff --git a/src/projecteurapp.cc b/src/projecteurapp.cc index 378b3c6..cd2043f 100644 --- a/src/projecteurapp.cc +++ b/src/projecteurapp.cc @@ -148,7 +148,7 @@ ProjecteurApplication::ProjecteurApplication(int &argc, char **argv, const Optio connect(this, &ProjecteurApplication::screenRemoved, this, [this](){ setupScreenOverlays(); }); // Setup the tray icon and menu - setupTrayIcon(); + setupTrayIcon(options); connect(this, &ProjecteurApplication::aboutToQuit, this, [this](){ for (const auto window : m_overlayWindows) { window->close(); } @@ -275,7 +275,7 @@ void ProjecteurApplication::setupSpotlight() } // ------------------------------------------------------------------------------------------------- -void ProjecteurApplication::setupTrayIcon() +void ProjecteurApplication::setupTrayIcon(Options const& options) { // add and connect 'Preferences' tray menu action const auto actionPref = m_trayMenu->addAction(tr("&Preferences...")); @@ -341,6 +341,8 @@ void ProjecteurApplication::setupTrayIcon() logDebug(mainapp) << tr("Exit request from preferences dialog."); actionQuit->trigger(); }); + + m_trayIcon->setVisible(!options.hideSysTrayIcon); } // ------------------------------------------------------------------------------------------------- diff --git a/src/projecteurapp.h b/src/projecteurapp.h index e3ab04a..60a8c0d 100644 --- a/src/projecteurapp.h +++ b/src/projecteurapp.h @@ -37,6 +37,7 @@ class ProjecteurApplication : public QApplication bool showPreferencesOnStart = false; bool dialogMinimizeOnly = false; bool disableOverlay = false; + bool hideSysTrayIcon = false; std::vector additionalDevices; }; @@ -71,7 +72,7 @@ private slots: QPoint currentCursorPos() const; void setCurrentCursorPos(const QPoint& pos); - void setupTrayIcon(); + void setupTrayIcon(Options const& options); void setupSpotlight(); private: