diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 5e05896f8d..880ed72db7 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -405,43 +405,18 @@ uint djbStringHash(const std::string &string) { } // namespace -class MainWindow::Private : public QObject { +class MainWindow::Private { public: - explicit Private(not_null window) - : _public(window) { - QCoreApplication::instance()->installEventFilter(this); - } - base::unique_qptr trayIconMenuXEmbed; #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION Glib::RefPtr dbusConnection; #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - -protected: - bool eventFilter(QObject *obj, QEvent *e) override; - -private: - not_null _public; }; -bool MainWindow::Private::eventFilter(QObject *obj, QEvent *e) { - if (obj->objectName() == qstr("QSystemTrayIconSys") - && e->type() == QEvent::MouseButtonPress) { - const auto ee = static_cast(e); - if (ee->button() == Qt::RightButton) { - Core::Sandbox::Instance().customEnterFromEventLoop([&] { - _public->handleTrayIconActication(QSystemTrayIcon::Context); - }); - return true; - } - } - return QObject::eventFilter(obj, e); -} - MainWindow::MainWindow(not_null controller) : Window::MainWindow(controller) -, _private(std::make_unique(this)) { +, _private(std::make_unique()) { } void MainWindow::initHook() { @@ -860,6 +835,27 @@ void MainWindow::updateGlobalMenuHook() { ForceDisabled(psClearFormat, !markdownEnabled); } +bool MainWindow::eventFilter(QObject *obj, QEvent *evt) { + QEvent::Type t = evt->type(); + if (t == QEvent::MouseButtonPress + && obj->objectName() == qstr("QSystemTrayIconSys")) { + const auto ee = static_cast(evt); + if (ee->button() == Qt::RightButton) { + Core::Sandbox::Instance().customEnterFromEventLoop([&] { + handleTrayIconActication(QSystemTrayIcon::Context); + }); + return true; + } + } else if (t == QEvent::FocusIn || t == QEvent::FocusOut) { + if (qobject_cast(obj) + || qobject_cast(obj) + || dynamic_cast(obj)) { + updateGlobalMenu(); + } + } + return Window::MainWindow::eventFilter(obj, evt); +} + void MainWindow::handleNativeSurfaceChanged(bool exist) { if (exist) { SkipTaskbar( diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index 561804e5f7..4091f09567 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -24,6 +24,8 @@ public: ~MainWindow(); protected: + bool eventFilter(QObject *obj, QEvent *evt) override; + void initHook() override; void unreadCounterChangedHook() override; void updateGlobalMenuHook() override;