From 6e5dfc79d406b2744731238405f5b76a649d873f Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 18 Jan 2023 15:36:32 +0400 Subject: [PATCH] Fix mouse BackButton with more than one window. Fixes #24704. --- .../SourceFiles/history/history_widget.cpp | 2 - Telegram/SourceFiles/mainwidget.cpp | 51 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 341fff2c6c..ca34da436f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2979,7 +2979,6 @@ void HistoryWidget::unreadCountUpdated() { crl::on_main(this, [=, history = _history] { if (history == _history) { closeCurrent(); - _cancelRequests.fire({}); } }); } else { @@ -5969,7 +5968,6 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { e->ignore(); } else if (e->key() == Qt::Key_Back) { - controller()->showBackFromStack(); _cancelRequests.fire({}); } else if (e->key() == Qt::Key_PageDown) { _scroll->keyPressEvent(e); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 497ed5b7ef..40b1dbef8b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1845,13 +1845,14 @@ bool MainWidget::preventsCloseSection( void MainWidget::showBackFromStack( const SectionShow ¶ms) { - if (preventsCloseSection([=] { showBackFromStack(params); }, params)) { return; } if (_stack.empty()) { - _controller->clearSectionStack(params); + if (isPrimary()) { + _controller->clearSectionStack(params); + } crl::on_main(this, [=] { _controller->widget()->setInnerFocus(); }); @@ -2521,28 +2522,40 @@ void MainWidget::returnTabbedSelector() { } bool MainWidget::eventFilter(QObject *o, QEvent *e) { + const auto widget = o->isWidgetType() + ? static_cast(o) + : nullptr; if (e->type() == QEvent::FocusIn) { - if (o->isWidgetType()) { - const auto widget = static_cast(o); + if (widget && (widget->window() == window())) { if (_history == widget || _history->isAncestorOf(widget) - || (_mainSection && (_mainSection == widget || _mainSection->isAncestorOf(widget))) - || (_thirdSection && (_thirdSection == widget || _thirdSection->isAncestorOf(widget)))) { + || (_mainSection + && (_mainSection == widget + || _mainSection->isAncestorOf(widget))) + || (_thirdSection + && (_thirdSection == widget + || _thirdSection->isAncestorOf(widget)))) { _controller->setDialogsListFocused(false); } else if (_dialogs - && (_dialogs == widget || _dialogs->isAncestorOf(widget))) { + && (_dialogs == widget + || _dialogs->isAncestorOf(widget))) { _controller->setDialogsListFocused(true); } } } else if (e->type() == QEvent::MouseButtonPress) { - if (static_cast(e)->button() == Qt::BackButton) { - if (!Core::App().hideMediaView()) { - handleHistoryBack(); + if (widget && (widget->window() == window())) { + const auto event = static_cast(e); + if (event->button() == Qt::BackButton) { + if (!Core::App().hideMediaView()) { + handleHistoryBack(); + } + return true; } - return true; } } else if (e->type() == QEvent::Wheel) { - if (const auto result = floatPlayerFilterWheelEvent(o, e)) { - return *result; + if (widget && (widget->window() == window())) { + if (const auto result = floatPlayerFilterWheelEvent(o, e)) { + return *result; + } } } return RpWidget::eventFilter(o, e); @@ -2559,10 +2572,6 @@ void MainWidget::handleAdaptiveLayoutUpdate() { } void MainWidget::handleHistoryBack() { - // #TODO windows - if (!_dialogs) { - return; - } const auto openedFolder = _controller->openedFolder().current(); const auto openedForum = _controller->shownForum().current(); const auto rootPeer = !_stack.empty() @@ -2579,10 +2588,12 @@ void MainWidget::handleHistoryBack() { if (openedForum && (!rootPeer || rootPeer->forum() != openedForum)) { _controller->closeForum(); } else if (!openedFolder - || rootFolder == openedFolder - || _dialogs->isHidden()) { + || (rootFolder == openedFolder) + || (!_dialogs || _dialogs->isHidden())) { _controller->showBackFromStack(); - _dialogs->setInnerFocus(); + if (_dialogs) { + _dialogs->setInnerFocus(); + } } else { _controller->closeFolder(); }