Fix crash in main menu swipes on macOS.

This commit is contained in:
John Preston 2025-03-17 10:45:23 +04:00
parent af35beefc2
commit fe0c1acd79
2 changed files with 23 additions and 4 deletions

View file

@ -1012,6 +1012,19 @@ rpl::producer<OthersUnreadState> OtherAccountsUnreadState(
});
}
base::EventFilterResult MainMenu::redirectToInnerChecked(not_null<QEvent*> 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<QEvent*> 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<QWheelEvent*>(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;

View file

@ -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<QEvent*> e);
void drawName(Painter &p);
const not_null<SessionController*> _controller;
@ -104,6 +111,7 @@ private:
Ui::Controls::SwipeBackResult _swipeBackData;
rpl::variable<bool> _showFinished = false;
bool _insideEventRedirect = false;
};