diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp index 2c98bc987b..361c41e22f 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.cpp +++ b/Telegram/SourceFiles/info/info_layer_widget.cpp @@ -250,6 +250,12 @@ bool LayerWidget::closeByOutsideClick() const { return _contentWrap ? _contentWrap->closeByOutsideClick() : true; } +bool LayerWidget::closeByBackButton() { + return _contentWrap + ? _contentWrap->closeByBackButton() + : Ui::LayerWidget::closeByBackButton(); +} + int LayerWidget::MinimalSupportedWidth() { const auto minimalMargins = 2 * st::infoMinimalLayerMargin; return st::infoMinimalWidth + minimalMargins; diff --git a/Telegram/SourceFiles/info/info_layer_widget.h b/Telegram/SourceFiles/info/info_layer_widget.h index 403c04271c..07c3cab8e4 100644 --- a/Telegram/SourceFiles/info/info_layer_widget.h +++ b/Telegram/SourceFiles/info/info_layer_widget.h @@ -41,6 +41,7 @@ public: const Window::SectionShow ¶ms) override; bool closeByOutsideClick() const override; + bool closeByBackButton() override; static int MinimalSupportedWidth(); diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index a2f15f1418..8c4f524745 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -1037,16 +1037,27 @@ void WrapWidget::resizeEvent(QResizeEvent *e) { void WrapWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Back) { - checkBeforeCloseByEscape((hasStackHistory() || wrap() != Wrap::Layer) - ? Fn([=] { _controller->showBackFromStack(); }) - : Fn([=] { - _controller->parentController()->hideSpecialLayer(); - })); + if (!closeByBackButton()) { + checkBeforeCloseByEscape( + [=] { _controller->showBackFromStack(); }); + } return; } SectionWidget::keyPressEvent(e); } +bool WrapWidget::closeByBackButton() { + if (!hasStackHistory() && wrap() != Wrap::Layer) { + return false; + } + checkBeforeCloseByEscape(hasStackHistory() + ? Fn([=] { _controller->showBackFromStack(); }) + : Fn([=] { + _controller->parentController()->hideSpecialLayer(); + })); + return true; +} + void WrapWidget::updateContentGeometry() { if (_content) { if (_topBar) { diff --git a/Telegram/SourceFiles/info/info_wrap_widget.h b/Telegram/SourceFiles/info/info_wrap_widget.h index 1924368169..02a55092eb 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.h +++ b/Telegram/SourceFiles/info/info_wrap_widget.h @@ -117,6 +117,7 @@ public: not_null memento, const Window::SectionShow ¶ms) override; bool showBackFromStackInternal(const Window::SectionShow ¶ms); + bool closeByBackButton(); void removeFromStack(const std::vector
§ions); std::shared_ptr createMemento() override; [[nodiscard]] SendMenu::Details sendMenuDetails() const override; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index af5e899b62..cff1ca835d 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2824,6 +2824,7 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) { const auto event = static_cast(e); if (event->button() == Qt::BackButton) { if (!Core::App().hideMediaView() + && !_controller->window().closeLayerByBackButton() && (!_dialogs || !_dialogs->cancelSearchByMouseBack())) { handleHistoryBack(); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 3fd3d9ad77..28a96e0e2b 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -512,6 +512,10 @@ rpl::producer MainWindow::ui_boxShownValue() const { return _boxShown.value(); } +bool MainWindow::closeLayerByBackButton() { + return _layer && _layer->closeCurrentByBackButton(); +} + bool MainWindow::showMediaPreview( Data::FileOrigin origin, not_null document) { diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 9f04a76e6a..571294c8af 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -103,6 +103,7 @@ public: void ui_removeLayerBlackout(); [[nodiscard]] bool ui_isLayerShown() const; [[nodiscard]] rpl::producer ui_boxShownValue() const; + bool closeLayerByBackButton(); bool showMediaPreview( Data::FileOrigin origin, not_null document); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index c925818269..bd1a1f2e22 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -463,6 +463,10 @@ void Controller::hideSettingsAndLayer(anim::type animated) { _widget.ui_hideSettingsAndLayer(animated); } +bool Controller::closeLayerByBackButton() { + return _widget.closeLayerByBackButton(); +} + bool Controller::isLayerShown() const { return _widget.ui_isLayerShown(); } diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index 29fb373430..4062108f6b 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -98,6 +98,7 @@ public: void hideLayer(anim::type animated = anim::type::normal); void hideSettingsAndLayer(anim::type animated = anim::type::normal); + bool closeLayerByBackButton(); [[nodiscard]] bool isLayerShown() const; [[nodiscard]] rpl::producer boxShownValue() const; diff --git a/Telegram/lib_ui b/Telegram/lib_ui index b826b08644..c345248e04 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit b826b0864418ed91bd73b51d13a9041196bf916f +Subproject commit c345248e04a11750fd1c4427e722867f6c9bff60