From d358a52e6124b528fb0bc09eaf4d28c8215e07e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Sun, 30 Jun 2019 16:48:30 -0400 Subject: Always toggle window visibility when clicking on the systray icon Left-clicking on the system tray icon should always result in toggling the visibility of the main window; if the icon is visible and clickble, then the window can always be hidden via --hide, or on startup via the "Startup hidden in system tray" option. (In the latter case, this previously resulted in a hidden and inaccessible window, as reported in issue #121.) --- src/gui/mphoneform.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gui/mphoneform.cpp b/src/gui/mphoneform.cpp index 6c447a8..b829be8 100644 --- a/src/gui/mphoneform.cpp +++ b/src/gui/mphoneform.cpp @@ -3239,12 +3239,7 @@ void MphoneForm::whatsThis() void MphoneForm::sysTrayIconClicked(QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick) - { - if (sys_config->get_gui_hide_on_close()) - setVisible(!isVisible()); - else - activateWindow(); - } + setVisible(!isVisible()); } bool MphoneForm::event(QEvent * event) -- cgit v1.2.3 From 3377008db04ac8d7e4928b7abfbe84a4c694d6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Sun, 30 Jun 2019 17:00:34 -0400 Subject: Add a "Show/Hide window" entry to the systray icon menu It's customary for applications embedding themselves in the system tray to offer a "Show/Hide window" menu entry on right-click, even for those applications which offer the same functionality via a single left-click. (Thanks to qBittorrent for the idea of using QMenu::aboutToShow to update the label of this menu entry.) --- src/gui/mphoneform.cpp | 21 ++++++++++++++++++++- src/gui/mphoneform.h | 2 ++ src/gui/mphoneform.ui | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/gui/mphoneform.cpp b/src/gui/mphoneform.cpp index b829be8..a724eb0 100644 --- a/src/gui/mphoneform.cpp +++ b/src/gui/mphoneform.cpp @@ -200,6 +200,12 @@ void MphoneForm::init() connect(sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayIconClicked(QSystemTrayIcon::ActivationReason))); + connect(menu, &QMenu::aboutToShow, this, &MphoneForm::updateTrayIconMenu); + + // Toggle window visibility + menu->addAction(toggleWindowAction); + + menu->addSeparator(); // Call menu menu->addAction(callInvite); @@ -3239,7 +3245,20 @@ void MphoneForm::whatsThis() void MphoneForm::sysTrayIconClicked(QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick) - setVisible(!isVisible()); + toggleWindow(); +} + +void MphoneForm::toggleWindow() +{ + setVisible(!isVisible()); +} + +void MphoneForm::updateTrayIconMenu() +{ + if (isVisible()) + toggleWindowAction->setText(tr("Hide window")); + else + toggleWindowAction->setText(tr("Show window")); } bool MphoneForm::event(QEvent * event) diff --git a/src/gui/mphoneform.h b/src/gui/mphoneform.h index 1527e8d..508072d 100644 --- a/src/gui/mphoneform.h +++ b/src/gui/mphoneform.h @@ -172,6 +172,8 @@ public slots: void DiamondcardAdminCenter(); void whatsThis(); void sysTrayIconClicked(QSystemTrayIcon::ActivationReason); + void toggleWindow(); + void updateTrayIconMenu(); void osdMuteClicked(); diff --git a/src/gui/mphoneform.ui b/src/gui/mphoneform.ui index 196b098..8857394 100644 --- a/src/gui/mphoneform.ui +++ b/src/gui/mphoneform.ui @@ -1822,6 +1822,11 @@ actgrActivateLine + + + Toggle window visibility + + @@ -2503,6 +2508,12 @@ + + toggleWindowAction + triggered() + MphoneForm + toggleWindow() + doMessageBuddy(QTreeWidgetItem*) -- cgit v1.2.3