diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 367502ab9..8583ea5d4 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -56,8 +56,7 @@ void toxActivateEventHandler(const QByteArray& data) { if (data != "$activate") return; - Widget::getInstance()->show(); - Widget::getInstance()->activateWindow(); + Widget::getInstance()->forceShow(); } Widget *Widget::instance{nullptr}; @@ -113,7 +112,8 @@ void Widget::init() this, SLOT(onIconClick(QSystemTrayIcon::ActivationReason))); - if (Settings::getInstance().getShowSystemTray()){ + if (Settings::getInstance().getShowSystemTray()) + { icon->show(); if (Settings::getInstance().getAutostartInTray() == false) this->show(); @@ -570,6 +570,13 @@ void Widget::setWindowTitle(const QString& title) QMainWindow::setWindowTitle("qTox - " + title); } +void Widget::forceShow() +{ + hide(); // Workaround to force minimized window to be restored + show(); + activateWindow(); +} + void Widget::onAddClicked() { hideMainForms(); @@ -592,21 +599,30 @@ void Widget::onTransferClicked() void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason) { - switch (reason) { + switch (reason) + { case QSystemTrayIcon::Trigger: - if (this->isHidden() == true) { - this->show(); - this->activateWindow(); + if (isHidden()) + { + show(); + activateWindow(); + } + else if (isMinimized() || !isActiveWindow()) + forceShow(); + else + hide(); + + break; } - else - this->hide(); - case QSystemTrayIcon::DoubleClick: + case QSystemTrayIcon::DoubleClick: + forceShow(); break; case QSystemTrayIcon::MiddleClick: + hide(); break; default: - ; + break; } } diff --git a/src/widget/widget.h b/src/widget/widget.h index e1a39f89e..df3586773 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -81,6 +81,7 @@ public: public slots: void onSettingsClicked(); void setWindowTitle(const QString& title); + void forceShow(); signals: void friendRequestAccepted(const QString& userId);