Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide to system tray instead of quitting #151

Merged
merged 1 commit into from
Feb 19, 2022
Merged

Conversation

wsipak
Copy link
Contributor

@wsipak wsipak commented Feb 19, 2022

Related issues:
#124
#71

This adds an option to hide the app to system tray with the close button.
The default behaviour remains unchanged.

I've tested it on Linux.

Copy link
Owner

@kraxarn kraxarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! ☺️
Just some minor things, and making sure it works when using the system title bar (Settings > Interface > Title bar > Application title bar).

/**
* Hide to system tray instead of quitting when the close button is pressed
*/
bool hide_to_tray = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "close to tray" is a better name? Feels like it's more obvious what it does, as it could be mixed up as a "minimize to tray". Also applies to all other references.

Suggested change
bool hide_to_tray = false;
bool close_to_tray = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, now this is close_to_tray, and other variables are consistent with this convention.

@@ -360,3 +360,14 @@ void MainToolBar::onMinimize(bool /*checked*/)
auto *mainWindow = MainWindow::find(parentWidget());
mainWindow->minimize();
}

void MainToolBar::onClose(bool /*checked*/)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works with the application title bar right? Maybe some handling in the main window itself would be required to make it work with the system title bar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true.
In order to make it work the same way when it's closed by the system title bar, I've added some logic to MainWindow::closeEvent.
This function also catches every other method of closing like right-click->close or alt+f4, or any other thing available, and they're not distinguishable.
I thought this could be a problem; however, I've checked that other apps that use system tray work the same way, so I expect that It shouldn't be a problem. At least it's not uncommon.

Now, when you select the option to close to system tray, all these methods will result in spotify-qt staying active in tray. In order to quit, one shall right-click the tray icon and select Quit, or use Ctrl+Q inside the app, or use menu->Quit.

@wsipak wsipak force-pushed the master branch 2 times, most recently from 2b75266 to d66dbf9 Compare February 19, 2022 14:45
Copy link
Owner

@kraxarn kraxarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, and again, thank you 👍

@kraxarn kraxarn merged commit 4b5948f into kraxarn:master Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants