Skip to content

Commit

Permalink
feat: add cmdline option to hide system tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jahnf committed Nov 24, 2024
1 parent e93343a commit b68696d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -215,7 +216,7 @@ namespace {
parser.addOptions({versionOption_, helpOption_, fullHelpOption_, commandOption_,
cfgFileOption_, fullVersionOption_, deviceInfoOption_, logLvlOption_,
disableUInputOption_, showDlgOnStartOption_, dialogMinOnlyOption_,
disableOverlayOption_, additionalDeviceOption_});
disableOverlayOption_, additionalDeviceOption_, hideSysTrayOption_});
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions src/projecteurapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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..."));
Expand Down Expand Up @@ -341,6 +341,8 @@ void ProjecteurApplication::setupTrayIcon()
logDebug(mainapp) << tr("Exit request from preferences dialog.");
actionQuit->trigger();
});

m_trayIcon->setVisible(!options.hideSysTrayIcon);
}

// -------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/projecteurapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProjecteurApplication : public QApplication
bool showPreferencesOnStart = false;
bool dialogMinimizeOnly = false;
bool disableOverlay = false;
bool hideSysTrayIcon = false;
std::vector<SupportedDevice> additionalDevices;
};

Expand Down Expand Up @@ -71,7 +72,7 @@ private slots:
QPoint currentCursorPos() const;
void setCurrentCursorPos(const QPoint& pos);

void setupTrayIcon();
void setupTrayIcon(Options const& options);
void setupSpotlight();

private:
Expand Down

0 comments on commit b68696d

Please sign in to comment.