diff --git a/src/main.cpp b/src/main.cpp index baab1f558..7fbf61682 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,6 +110,7 @@ int main(int argc, char *argv[]) IPC ipc; ipc.registerEventHandler(&toxURIEventHandler); ipc.registerEventHandler(&toxSaveEventHandler); + ipc.registerEventHandler(&toxActivateEventHandler); if (parser.positionalArguments().size() > 0) { @@ -152,9 +153,16 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } } + else if(!ipc.isCurrentOwner()) + { + time_t event = ipc.postEvent("$activate"); + ipc.waitUntilProcessed(event); + if (!ipc.isCurrentOwner()) + return EXIT_SUCCESS; + } // Run - Widget* w = Widget::getInstance(); + Widget* w = Widget::getInstance(); int errorcode = a.exec(); delete w; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 3caaecd44..5293462aa 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -51,6 +51,14 @@ #include #include +void toxActivateEventHandler(const QByteArray& data) +{ + if(data != "$activate") + return; + Widget::getInstance()->show(); + Widget::getInstance()->activateWindow(); +} + Widget *Widget::instance{nullptr}; Widget::Widget(QWidget *parent) @@ -563,7 +571,10 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason) switch (reason) { case QSystemTrayIcon::Trigger: if(this->isHidden() == true) + { this->show(); + this->activateWindow(); + } else this->hide(); case QSystemTrayIcon::DoubleClick: diff --git a/src/widget/widget.h b/src/widget/widget.h index 057704e7e..2f7c408e2 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -168,4 +168,6 @@ private: QTranslator* translator; }; +void toxActivateEventHandler(const QByteArray& data); + #endif // WIDGET_H