Don't collapse chats list on window unfocus.

This commit is contained in:
John Preston 2024-04-08 15:52:45 +04:00
parent 39658ffe52
commit 11e4c45969
3 changed files with 22 additions and 8 deletions

View file

@ -358,8 +358,11 @@ Widget::Widget(
applySearchUpdate(); applySearchUpdate();
}, _search->lifetime()); }, _search->lifetime());
_search->focusedChanges() | rpl::start_with_next([=](bool focused) { _search->focusedChanges(
updateForceDisplayWide(); ) | rpl::start_with_next([=](bool focused) {
if (focused) {
updateHasFocus(_search.data());
}
}, _search->lifetime()); }, _search->lifetime());
_search->submits( _search->submits(
@ -1020,7 +1023,7 @@ void Widget::updateControlsVisibility(bool fast) {
updateLoadMoreChatsVisibility(); updateLoadMoreChatsVisibility();
_scroll->show(); _scroll->show();
updateStoriesVisibility(); updateStoriesVisibility();
if ((_openedFolder || _openedForum) && _search->hasFocus()) { if ((_openedFolder || _openedForum) && _searchHasFocus.current()) {
setInnerFocus(); setInnerFocus();
} }
if (_updateTelegram) { if (_updateTelegram) {
@ -1059,7 +1062,7 @@ void Widget::updateControlsVisibility(bool fast) {
if (_hideChildListCanvas) { if (_hideChildListCanvas) {
_hideChildListCanvas->show(); _hideChildListCanvas->show();
} }
if (_childList && _search->hasFocus()) { if (_childList && _searchHasFocus.current()) {
setInnerFocus(); setInnerFocus();
} }
updateLockUnlockPosition(); updateLockUnlockPosition();
@ -1081,6 +1084,11 @@ void Widget::updateLockUnlockPosition() {
st::dialogsFilterPadding.y()); st::dialogsFilterPadding.y());
} }
void Widget::updateHasFocus(not_null<QWidget*> focused) {
_searchHasFocus = (focused == _search.data());
updateForceDisplayWide();
}
void Widget::changeOpenedSubsection( void Widget::changeOpenedSubsection(
FnMut<void()> change, FnMut<void()> change,
bool fromRight, bool fromRight,
@ -1637,7 +1645,7 @@ void Widget::slideFinished() {
_shownProgressValue = 1.; _shownProgressValue = 1.;
updateControlsVisibility(true); updateControlsVisibility(true);
if ((!_subsectionTopBar || !_subsectionTopBar->searchHasFocus()) if ((!_subsectionTopBar || !_subsectionTopBar->searchHasFocus())
&& !_search->hasFocus()) { && !_searchHasFocus.current()) {
controller()->widget()->setInnerFocus(); controller()->widget()->setInnerFocus();
} }
} }
@ -2479,7 +2487,7 @@ void Widget::applySearchUpdate(bool force) {
} }
void Widget::updateForceDisplayWide() { void Widget::updateForceDisplayWide() {
controller()->setChatsForceDisplayWide(_search->hasFocus() controller()->setChatsForceDisplayWide(_searchHasFocus.current()
|| !_search->getLastText().isEmpty() || !_search->getLastText().isEmpty()
|| _searchInChat); || _searchInChat);
} }
@ -3203,7 +3211,7 @@ bool Widget::cancelSearch() {
_inner->clearFilter(); _inner->clearFilter();
clearSearchField(); clearSearchField();
applySearchUpdate(); applySearchUpdate();
if (!_searchInChat && _search->hasFocus()) { if (!_searchInChat && _searchHasFocus.current()) {
setFocus(); setFocus();
} }
return clearingQuery || clearingInChat; return clearingQuery || clearingInChat;

View file

@ -123,6 +123,7 @@ public:
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const; [[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const; [[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
void updateHasFocus(not_null<QWidget*> focused);
// Float player interface. // Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e) override; bool floatPlayerHandleWheelEvent(QEvent *e) override;
@ -296,6 +297,7 @@ private:
std::vector<Data::ReactionId> _searchTags; std::vector<Data::ReactionId> _searchTags;
rpl::lifetime _searchTagsLifetime; rpl::lifetime _searchTagsLifetime;
QString _lastSearchText; QString _lastSearchText;
rpl::variable<bool> _searchHasFocus = false;
rpl::event_stream<rpl::producer<Stories::Content>> _storiesContents; rpl::event_stream<rpl::producer<Stories::Content>> _storiesContents;
base::flat_map<PeerId, Ui::PeerUserpicView> _storiesUserpicsViewsHidden; base::flat_map<PeerId, Ui::PeerUserpicView> _storiesUserpicsViewsHidden;

View file

@ -2624,7 +2624,11 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) {
const auto widget = o->isWidgetType() const auto widget = o->isWidgetType()
? static_cast<QWidget*>(o) ? static_cast<QWidget*>(o)
: nullptr; : nullptr;
if (e->type() == QEvent::MouseButtonPress) { if (e->type() == QEvent::FocusIn) {
if (widget && _dialogs && widget->window() == window()) {
_dialogs->updateHasFocus(widget);
}
} else if (e->type() == QEvent::MouseButtonPress) {
if (widget && (widget->window() == window())) { if (widget && (widget->window() == window())) {
const auto event = static_cast<QMouseEvent*>(e); const auto event = static_cast<QMouseEvent*>(e);
if (event->button() == Qt::BackButton) { if (event->button() == Qt::BackButton) {