diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 5b32ea14c..744322933 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -958,6 +958,9 @@ void TabbedSelector::beforeHiding() { _beforeHidingCallback(_currentTabType); } } + if (Ui::InFocusChain(this)) { + window()->setFocus(); + } } void TabbedSelector::afterShown() { diff --git a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp index c4cce455f..3a3176908 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp @@ -58,7 +58,16 @@ void PickUntilBox(not_null box, Fn callback) { EmojiStatusPanel::EmojiStatusPanel() = default; -EmojiStatusPanel::~EmojiStatusPanel() = default; +EmojiStatusPanel::~EmojiStatusPanel() { + if (hasFocus()) { + // Panel will try to return focus to the layer widget, the problem is + // we are destroying the layer widget probably right now and focusing + // it will lead to a crash, because it destroys its children (how we + // got here) after it clears focus out of itself. So if you return + // the focus inside a child destructor, it won't be cleared at all. + _panel->window()->setFocus(); + } +} void EmojiStatusPanel::setChooseFilter(Fn filter) { _chooseFilter = std::move(filter); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 6e6fbf8d3..ecd9ad066 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2644,6 +2644,10 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) { if (e->type() == QEvent::FocusIn) { if (widget && relevantForDialogsFocus(widget)) { _dialogs->updateHasFocus(widget); + } else if (widget == window()) { + crl::on_main(this, [=] { + _controller->widget()->setInnerFocus(); + }); } } else if (e->type() == QEvent::MouseButtonPress) { if (widget && (widget->window() == window())) { diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index a33485c11..551d4f33c 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -165,16 +165,7 @@ Cover::Cover( }, _name->lifetime()); } -Cover::~Cover() { - if (_emojiStatusPanel.hasFocus()) { - // Panel will try to return focus to the layer widget, the problem is - // we are destroying the layer widget probably right now and focusing - // it will lead to a crash, because it destroys its children (how we - // got here) after it clears focus out of itself. So if you return - // the focus inside a child destructor, it won't be cleared at all. - window()->setFocus(); - } -} +Cover::~Cover() = default; void Cover::setupChildGeometry() { using namespace rpl::mappers;