From fe0c1acd793c2a38946979072000ef2723a906ff Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 17 Mar 2025 10:45:23 +0400 Subject: [PATCH] Fix crash in main menu swipes on macOS. --- .../SourceFiles/window/window_main_menu.cpp | 19 +++++++++++++++---- .../SourceFiles/window/window_main_menu.h | 8 ++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index f61b217a24..b4344d2023 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -1012,6 +1012,19 @@ rpl::producer OtherAccountsUnreadState( }); } +base::EventFilterResult MainMenu::redirectToInnerChecked(not_null e) { + if (_insideEventRedirect) { + return base::EventFilterResult::Continue; + } + const auto weak = Ui::MakeWeak(this); + _insideEventRedirect = true; + QGuiApplication::sendEvent(_inner, e); + if (weak) { + _insideEventRedirect = false; + } + return base::EventFilterResult::Cancel; +} + void MainMenu::setupSwipe() { const auto outer = _controller->widget()->body(); base::install_event_filter(this, outer, [=](not_null e) { @@ -1020,14 +1033,12 @@ void MainMenu::setupSwipe() { || type == QEvent::TouchUpdate || type == QEvent::TouchEnd || type == QEvent::TouchCancel) { - QGuiApplication::sendEvent(_inner, e); - return base::EventFilterResult::Cancel; + return redirectToInnerChecked(e); } else if (type == QEvent::Wheel) { const auto w = static_cast(e.get()); const auto d = Ui::ScrollDeltaF(w); if (std::abs(d.x()) > std::abs(d.y())) { - QGuiApplication::sendEvent(_inner, e); - return base::EventFilterResult::Cancel; + return redirectToInnerChecked(e); } } return base::EventFilterResult::Continue; diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 764803fd0d..36a3087a05 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/swipe_handler_data.h" #include "ui/layers/layer_widget.h" +namespace base { +enum class EventFilterResult; +} // namespace base + namespace Ui { class IconButton; class FlatLabel; @@ -76,6 +80,9 @@ private: void chooseEmojiStatus(); void setupSwipe(); + [[nodiscard]] base::EventFilterResult redirectToInnerChecked( + not_null e); + void drawName(Painter &p); const not_null _controller; @@ -104,6 +111,7 @@ private: Ui::Controls::SwipeBackResult _swipeBackData; rpl::variable _showFinished = false; + bool _insideEventRedirect = false; };