Skip to content

Commit fe0c1ac

Browse files
committed
Fix crash in main menu swipes on macOS.
1 parent af35bee commit fe0c1ac

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Telegram/SourceFiles/window/window_main_menu.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,19 @@ rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
10121012
});
10131013
}
10141014

1015+
base::EventFilterResult MainMenu::redirectToInnerChecked(not_null<QEvent*> e) {
1016+
if (_insideEventRedirect) {
1017+
return base::EventFilterResult::Continue;
1018+
}
1019+
const auto weak = Ui::MakeWeak(this);
1020+
_insideEventRedirect = true;
1021+
QGuiApplication::sendEvent(_inner, e);
1022+
if (weak) {
1023+
_insideEventRedirect = false;
1024+
}
1025+
return base::EventFilterResult::Cancel;
1026+
}
1027+
10151028
void MainMenu::setupSwipe() {
10161029
const auto outer = _controller->widget()->body();
10171030
base::install_event_filter(this, outer, [=](not_null<QEvent*> e) {
@@ -1020,14 +1033,12 @@ void MainMenu::setupSwipe() {
10201033
|| type == QEvent::TouchUpdate
10211034
|| type == QEvent::TouchEnd
10221035
|| type == QEvent::TouchCancel) {
1023-
QGuiApplication::sendEvent(_inner, e);
1024-
return base::EventFilterResult::Cancel;
1036+
return redirectToInnerChecked(e);
10251037
} else if (type == QEvent::Wheel) {
10261038
const auto w = static_cast<QWheelEvent*>(e.get());
10271039
const auto d = Ui::ScrollDeltaF(w);
10281040
if (std::abs(d.x()) > std::abs(d.y())) {
1029-
QGuiApplication::sendEvent(_inner, e);
1030-
return base::EventFilterResult::Cancel;
1041+
return redirectToInnerChecked(e);
10311042
}
10321043
}
10331044
return base::EventFilterResult::Continue;

Telegram/SourceFiles/window/window_main_menu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ For license and copyright information please follow this link:
1515
#include "ui/controls/swipe_handler_data.h"
1616
#include "ui/layers/layer_widget.h"
1717

18+
namespace base {
19+
enum class EventFilterResult;
20+
} // namespace base
21+
1822
namespace Ui {
1923
class IconButton;
2024
class FlatLabel;
@@ -76,6 +80,9 @@ class MainMenu final : public Ui::LayerWidget {
7680
void chooseEmojiStatus();
7781
void setupSwipe();
7882

83+
[[nodiscard]] base::EventFilterResult redirectToInnerChecked(
84+
not_null<QEvent*> e);
85+
7986
void drawName(Painter &p);
8087

8188
const not_null<SessionController*> _controller;
@@ -104,6 +111,7 @@ class MainMenu final : public Ui::LayerWidget {
104111
Ui::Controls::SwipeBackResult _swipeBackData;
105112

106113
rpl::variable<bool> _showFinished = false;
114+
bool _insideEventRedirect = false;
107115

108116
};
109117

0 commit comments

Comments
 (0)