From 0e16a50bbcbb5ea99554fb47d3b405109d8a5f78 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 21 Apr 2022 22:33:27 +0300 Subject: [PATCH] Completely removed common and platform code for tray from main window. --- Telegram/SourceFiles/core/application.cpp | 4 +- Telegram/SourceFiles/mainwindow.cpp | 103 +----------------- Telegram/SourceFiles/mainwindow.h | 13 --- .../platform/linux/main_window_linux.cpp | 16 --- .../platform/linux/main_window_linux.h | 13 --- .../platform/linux/specific_linux.cpp | 1 + .../platform/mac/main_window_mac.h | 15 --- .../platform/mac/main_window_mac.mm | 15 --- .../platform/win/main_window_win.cpp | 16 --- .../platform/win/main_window_win.h | 17 --- Telegram/SourceFiles/window/main_window.cpp | 14 --- Telegram/SourceFiles/window/main_window.h | 21 ---- 12 files changed, 4 insertions(+), 244 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index fa91af4c00..a507433fac 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -433,9 +433,9 @@ void Application::startTray() { _tray->showFromTrayRequests( ) | rpl::start_with_next([=] { const auto last = _lastActiveWindow; - enumerate([&](WindowRaw w) { w->widget()->showFromTrayMenu(); }); + enumerate([&](WindowRaw w) { w->widget()->showFromTray(); }); if (last) { - last->widget()->showFromTrayMenu(); + last->widget()->showFromTray(); } }, _primaryWindow->widget()->lifetime()); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index c05ceb3832..c6ec4b9e0b 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -123,9 +123,6 @@ void MainWindow::initHook() { } } -void MainWindow::createTrayIconMenu() { -} - void MainWindow::applyInitialWorkMode() { const auto workMode = Core::App().settings().workMode(); workmodeUpdated(workMode); @@ -150,7 +147,6 @@ void MainWindow::applyInitialWorkMode() { } void MainWindow::finishFirstShow() { - createTrayIconMenu(); applyInitialWorkMode(); createGlobalMenu(); @@ -634,15 +630,6 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) { return Platform::MainWindow::eventFilter(object, e); } -void MainWindow::updateTrayMenu() { - if (!trayIconMenu) { - return; - } - _updateTrayMenuTextActions.fire({}); - - psTrayMenuUpdated(); -} - bool MainWindow::takeThirdSectionFromLayer() { return _layer ? _layer->takeToThirdSection() : false; } @@ -654,91 +641,6 @@ void MainWindow::fixOrder() { if (_testingThemeWarning) _testingThemeWarning->raise(); } -void MainWindow::handleTrayIconActication( - QSystemTrayIcon::ActivationReason reason) { - updateIsActive(); - if (Platform::IsMac() && isActive()) { - if (trayIcon && !trayIcon->contextMenu()) { - showFromTray(); - } - return; - } - if (reason == QSystemTrayIcon::Context) { - updateTrayMenu(); - InvokeQueued(this, [=] { - psShowTrayMenu(); - }); - } else if (!skipTrayClick()) { - if (isActiveForTrayMenu()) { - minimizeToTray(); - } else { - showFromTray(); - } - _lastTrayClickTime = crl::now(); - } -} - -bool MainWindow::skipTrayClick() const { - return (_lastTrayClickTime > 0) - && (crl::now() - _lastTrayClickTime - < QApplication::doubleClickInterval()); -} - -void MainWindow::toggleDisplayNotifyFromTray() { - if (controller().locked()) { - if (!isActive()) showFromTray(); - Ui::show(Ui::MakeInformBox(tr::lng_passcode_need_unblock())); - return; - } - if (!sessionController()) { - return; - } - - auto soundNotifyChanged = false; - auto flashBounceNotifyChanged = false; - auto &settings = Core::App().settings(); - settings.setDesktopNotify(!settings.desktopNotify()); - if (settings.desktopNotify()) { - if (settings.rememberedSoundNotifyFromTray() - && !settings.soundNotify()) { - settings.setSoundNotify(true); - settings.setRememberedSoundNotifyFromTray(false); - soundNotifyChanged = true; - } - if (settings.rememberedFlashBounceNotifyFromTray() - && !settings.flashBounceNotify()) { - settings.setFlashBounceNotify(true); - settings.setRememberedFlashBounceNotifyFromTray(false); - flashBounceNotifyChanged = true; - } - } else { - if (settings.soundNotify()) { - settings.setSoundNotify(false); - settings.setRememberedSoundNotifyFromTray(true); - soundNotifyChanged = true; - } else { - settings.setRememberedSoundNotifyFromTray(false); - } - if (settings.flashBounceNotify()) { - settings.setFlashBounceNotify(false); - settings.setRememberedFlashBounceNotifyFromTray(true); - flashBounceNotifyChanged = true; - } else { - settings.setRememberedFlashBounceNotifyFromTray(false); - } - } - Core::App().saveSettingsDelayed(); - using Change = Window::Notifications::ChangeType; - auto ¬ifications = Core::App().notifications(); - notifications.notifySettingsChanged(Change::DesktopEnabled); - if (soundNotifyChanged) { - notifications.notifySettingsChanged(Change::SoundEnabled); - } - if (flashBounceNotifyChanged) { - notifications.notifySettingsChanged(Change::FlashBounceEnabled); - } -} - void MainWindow::closeEvent(QCloseEvent *e) { if (Core::Sandbox::Instance().isSavingSession() || Core::Quitting()) { e->accept(); @@ -807,10 +709,7 @@ void MainWindow::activeChangedHook() { } } -MainWindow::~MainWindow() { - delete trayIcon; - delete trayIconMenu; -} +MainWindow::~MainWindow() = default; namespace App { diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 5bcd1ee827..37d636924f 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -80,7 +80,6 @@ public: } void showMainMenu(); - void updateTrayMenu() override; void fixOrder() override; void showLayer( @@ -119,12 +118,6 @@ protected: void clearWidgetsHook() override; private: - [[nodiscard]] bool skipTrayClick() const; - - void createTrayIconMenu(); - void handleTrayIconActication( - QSystemTrayIcon::ActivationReason reason) override; - void applyInitialWorkMode(); void ensureLayerCreated(); void destroyLayer(); @@ -139,15 +132,11 @@ private: void themeUpdated(const Window::Theme::BackgroundUpdate &data); - void toggleDisplayNotifyFromTray(); - QPixmap grabInner(); std::unique_ptr _mediaControlsManager; - crl::time _lastTrayClickTime = 0; QPoint _lastMousePosition; - bool _activeForTrayIconAction = true; object_ptr _passcodeLock = { nullptr }; object_ptr _intro = { nullptr }; @@ -157,8 +146,6 @@ private: object_ptr _testingThemeWarning = { nullptr }; - rpl::event_stream<> _updateTrayMenuTextActions; - }; namespace App { diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 4ab527c81d..58d1165c9b 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -255,24 +255,11 @@ void MainWindow::initHook() { LOG(("System tray available: %1").arg(Logs::b(TrayIconSupported()))); } -bool MainWindow::hasTrayIcon() const { - return trayIcon; -} - bool MainWindow::isActiveForTrayMenu() { updateIsActive(); return Platform::IsWayland() ? isVisible() : isActive(); } -void MainWindow::psShowTrayMenu() { -} - -void MainWindow::psTrayMenuUpdated() { -} - -void MainWindow::psSetupTrayIcon() { -} - void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) { if (!TrayIconSupported()) { return; @@ -329,9 +316,6 @@ void MainWindow::updateIconCounters() { #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } -void MainWindow::initTrayMenuHook() { -} - void MainWindow::createGlobalMenu() { const auto ensureWindowShown = [=] { if (isHidden()) { diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index afcaabd289..de64966605 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -22,8 +22,6 @@ class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null controller); - void psShowTrayMenu(); - bool isActiveForTrayMenu() override; ~MainWindow(); @@ -35,21 +33,10 @@ protected: void unreadCounterChangedHook() override; void updateGlobalMenuHook() override; - void initTrayMenuHook() override; - bool hasTrayIcon() const override; - void workmodeUpdated(Core::Settings::WorkMode mode) override; void createGlobalMenu() override; - QSystemTrayIcon *trayIcon = nullptr; - QMenu *trayIconMenu = nullptr; - - void psTrayMenuUpdated(); - void psSetupTrayIcon(); - private: - base::unique_qptr _trayIconMenuXEmbed; - QMenuBar *psMainMenu = nullptr; QAction *psLogout = nullptr; QAction *psUndo = nullptr; diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index d64ebd320a..5450495000 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #include +#include #include #include #include diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index 40dbdc8b97..065e747cdf 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -30,8 +30,6 @@ public: void updateWindowIcon() override; - void psShowTrayMenu(); - bool preventsQuit(Core::QuitReason reason) override; class Private; @@ -39,25 +37,12 @@ public: protected: bool eventFilter(QObject *obj, QEvent *evt) override; - void handleActiveChangedHook() override; void stateChangedHook(Qt::WindowState state) override; void initHook() override; void unreadCounterChangedHook() override; - bool hasTrayIcon() const override { - return trayIcon; - } - void updateGlobalMenuHook() override; - void workmodeUpdated(Core::Settings::WorkMode mode) override; - - QSystemTrayIcon *trayIcon = nullptr; - QMenu *trayIconMenu = nullptr; - - void psTrayMenuUpdated(); - void psSetupTrayIcon(); - void closeWithoutDestroy() override; void createGlobalMenu() override; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 23d6fea9f8..40d662bb0e 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -237,9 +237,6 @@ void MainWindow::stateChangedHook(Qt::WindowState state) { } } -void MainWindow::handleActiveChangedHook() { -} - void MainWindow::initHook() { _customTitleHeight = 0; if (auto view = reinterpret_cast(winId())) { @@ -260,9 +257,6 @@ void MainWindow::hideAndDeactivate() { hide(); } -void MainWindow::psShowTrayMenu() { -} - bool MainWindow::preventsQuit(Core::QuitReason reason) { // Thanks Chromium, see // chromium.org/developers/design-documents/confirm-to-quit-experiment @@ -276,15 +270,6 @@ bool MainWindow::preventsQuit(Core::QuitReason reason) { Platform::ConfirmQuit::QuitKeysString())); } -void MainWindow::psTrayMenuUpdated() { -} - -void MainWindow::psSetupTrayIcon() { -} - -void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) { -} - void MainWindow::unreadCounterChangedHook() { updateIconCounters(); } diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 9c4120d657..ee1cfc5c69 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -215,9 +215,6 @@ void MainWindow::shadowsDeactivate() { _hasActiveFrame = false; } -void MainWindow::psShowTrayMenu() { -} - void MainWindow::destroyedFromSystem() { Core::Quit(); } @@ -247,15 +244,6 @@ void MainWindow::forceIconRefresh() { updateIconCounters(); } -void MainWindow::psTrayMenuUpdated() { -} - -void MainWindow::psSetupTrayIcon() { -} - -void MainWindow::showTrayTooltip() { -} - void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) { using WorkMode = Core::Settings::WorkMode; @@ -515,10 +503,6 @@ void MainWindow::validateWindowTheme(bool native, bool night) { SendMessage(_hWnd, WM_NCACTIVATE, _hasActiveFrame ? 1 : 0, 0); } -void MainWindow::showFromTrayMenu() { - showFromTray(); -} - HWND MainWindow::psHwnd() const { return _hWnd; } diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index 09a8015240..baab0669ab 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -21,8 +21,6 @@ class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null controller); - void showFromTrayMenu() override; - HWND psHwnd() const; void updateWindowIcon() override; @@ -34,8 +32,6 @@ public: [[nodiscard]] bool hasTabletView() const; - void psShowTrayMenu(); - void destroyedFromSystem(); ~MainWindow(); @@ -45,18 +41,6 @@ protected: int32 screenNameChecksum(const QString &name) const override; void unreadCounterChangedHook() override; - bool hasTrayIcon() const override { - return trayIcon; - } - - QSystemTrayIcon *trayIcon = nullptr; - Ui::PopupMenu *trayIconMenu = nullptr; - - void psTrayMenuUpdated(); - void psSetupTrayIcon(); - - void showTrayTooltip() override; - void workmodeUpdated(Core::Settings::WorkMode mode) override; bool initGeometryFromSystem() override; @@ -83,7 +67,6 @@ private: // Workarounds for activation from tray icon. crl::time _lastDeactivateTime = 0; - rpl::lifetime _showFromTrayLifetime; bool _hasActiveFrame = false; diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index e9d26d211f..0d72f3d256 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -491,9 +491,6 @@ void MainWindow::handleActiveChanged() { if (isActiveWindow()) { Core::App().checkMediaViewActivation(); } - InvokeQueued(this, [=] { - handleActiveChangedHook(); - }); } void MainWindow::handleVisibleChanged(bool visible) { @@ -765,16 +762,6 @@ void MainWindow::setPositionInited() { _positionInited = true; } -void MainWindow::attachToTrayIcon(not_null icon) { - icon->setToolTip(AppName.utf16()); - connect(icon, &QSystemTrayIcon::activated, this, [=]( - QSystemTrayIcon::ActivationReason reason) { - Core::Sandbox::Instance().customEnterFromEventLoop([&] { - handleTrayIconActication(reason); - }); - }); -} - rpl::producer<> MainWindow::leaveEvents() const { return _leaveEvents.events(); } @@ -903,7 +890,6 @@ bool MainWindow::minimizeToTray() { closeWithoutDestroy(); controller().updateIsActiveBlur(); updateGlobalMenu(); - showTrayTooltip(); return true; } diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 70a886ddd5..72f4f208b3 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/core_settings.h" #include "base/required.h" -#include - namespace Main { class Session; class Account; @@ -75,9 +73,6 @@ public: void showFromTray(); void quitFromTray(); void activate(); - virtual void showFromTrayMenu() { - showFromTray(); - } [[nodiscard]] QRect desktopRect() const; @@ -107,8 +102,6 @@ public: // Returns how much could the window get extended. int tryToExtendWidthBy(int addToWidth); - virtual void updateTrayMenu() { - } virtual void fixOrder() { } virtual void setInnerFocus() { @@ -156,9 +149,6 @@ protected: virtual void activeChangedHook() { } - virtual void handleActiveChangedHook() { - } - virtual void handleVisibleChangedHook(bool visible) { } @@ -178,14 +168,6 @@ protected: virtual void updateGlobalMenuHook() { } - virtual void initTrayMenuHook() { - } - virtual bool hasTrayIcon() const { - return false; - } - virtual void showTrayTooltip() { - } - virtual void workmodeUpdated(Core::Settings::WorkMode mode) { } @@ -200,9 +182,6 @@ protected: virtual int32 screenNameChecksum(const QString &name) const; void setPositionInited(); - void attachToTrayIcon(not_null icon); - virtual void handleTrayIconActication( - QSystemTrayIcon::ActivationReason reason) = 0; void updateUnreadCounter(); virtual QRect computeDesktopRect() const;