Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/QtTrayMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void QtTrayMenu::onUpdate(struct tray *tray, const bool notify) {
}
}

int QtTrayMenu::loop(int blocking) const {
int QtTrayMenu::loop(int blocking) {
if (!running) {
return -1;
}
Expand All @@ -121,9 +121,11 @@ int QtTrayMenu::loop(int blocking) const {
return -1;
}
if (blocking) {
blockingEventLoop = true;
QApplication::exec();
return -1;
} else {
blockingEventLoop = false;
QApplication::processEvents();
return 0;
}
Expand All @@ -149,6 +151,11 @@ void QtTrayMenu::onExitRequested() {
}
// Unset tray structure
trayStruct = nullptr;

// If we run in a blocking event loop break said loop by quitting the QApplication
if (blockingEventLoop) {
QApplication::quit();
}
}

void QtTrayMenu::updateMenu(struct tray_menu *items) {
Expand Down
3 changes: 2 additions & 1 deletion src/QtTrayMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QtTrayMenu: public QObject {
* @param blocking if true the function call will block until QtTrayMenu exits
* @return 0 on successful processing if non-blocking, -1 otherwise
*/
int loop(int blocking) const;
int loop(int blocking);

/**
* @brief Configure metadata for QApplication
Expand Down Expand Up @@ -135,6 +135,7 @@ class QtTrayMenu: public QObject {
QMenu *trayTopMenu = nullptr;
struct tray *trayStruct = nullptr;
bool running = false;
bool blockingEventLoop = false;
struct tray_menu *getTrayMenuItem(QAction *action);
std::function<void()> notificationCallback = nullptr;

Expand Down
Loading