diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 774081836..bb3407afd 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -55,6 +55,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_send_action.h" #include "chat_helpers/emoji_interactions.h" #include "base/unixtime.h" +#include "base/event_filter.h" #include "support/support_helper.h" #include "apiwrap.h" #include "api/api_chat_participants.h" @@ -230,6 +231,16 @@ TopBarWidget::TopBarWidget( updateConnectingState(); }, lifetime()); + base::install_event_filter( + this, + window()->windowHandle(), + [=](not_null e) { + if (e->type() == QEvent::Expose) { + updateConnectingState(); + } + return base::EventFilterResult::Continue; + }); + setCursor(style::cur_pointer); } @@ -241,7 +252,8 @@ Main::Session &TopBarWidget::session() const { void TopBarWidget::updateConnectingState() { const auto state = _controller->session().mtp().dcstate(); - if (state == MTP::ConnectedState) { + const auto exposed = window()->windowHandle()->isExposed(); + if (state == MTP::ConnectedState || !exposed) { if (_connecting) { _connecting = nullptr; update(); diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index 3d3a5d2a3..d045b153c 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/window_connecting_widget.h" +#include "base/event_filter.h" #include "ui/widgets/buttons.h" #include "ui/effects/radial_animation.h" #include "ui/painter.h" @@ -207,6 +208,14 @@ ConnectionState::ConnectionState( rpl::producer shown) : _account(account) , _parent(parent) +, _exposeFilter(base::install_event_filter( + parent->window()->windowHandle(), + [=](not_null e) { + if (e->type() == QEvent::Expose) { + refreshState(); + } + return base::EventFilterResult::Continue; + })) , _refreshTimer([=] { refreshState(); }) , _currentLayout(computeLayout(_state)) { rpl::combine( @@ -290,6 +299,7 @@ void ConnectionState::setBottomSkip(int skip) { void ConnectionState::refreshState() { using Checker = Core::UpdateChecker; const auto state = [&]() -> State { + const auto exposed = _parent->window()->windowHandle()->isExposed(); const auto under = _widget && _widget->isOver(); const auto ready = (Checker().state() == Checker::State::Ready); const auto state = _account->mtp().dcstate(); @@ -297,18 +307,18 @@ void ConnectionState::refreshState() { if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) { - return { State::Type::Connecting, proxy, under, ready }; + return { State::Type::Connecting, proxy, exposed, under, ready }; } else if (state < 0 && state >= -kMinimalWaitingStateDuration && _state.type != State::Type::Waiting) { - return { State::Type::Connecting, proxy, under, ready }; + return { State::Type::Connecting, proxy, exposed, under, ready }; } else if (state < 0) { const auto wait = ((-state) / 1000) + 1; - return { State::Type::Waiting, proxy, under, ready, wait }; + return { State::Type::Waiting, proxy, exposed, under, ready, wait }; } - return { State::Type::Connected, proxy, under, ready }; + return { State::Type::Connected, proxy, exposed, under, ready }; }(); - if (state.waitTillRetry > 0) { + if (state.exposed && state.waitTillRetry > 0) { _refreshTimer.callOnce(kRefreshTimeout); } if (state == _state) { @@ -421,7 +431,8 @@ auto ConnectionState::computeLayout(const State &state) const -> Layout { auto result = Layout(); result.proxyEnabled = state.useProxy; result.progressShown = (state.type != State::Type::Connected); - result.visible = !state.updateReady + result.visible = state.exposed + && !state.updateReady && (state.useProxy || state.type == State::Type::Connecting || state.type == State::Type::Waiting); diff --git a/Telegram/SourceFiles/window/window_connecting_widget.h b/Telegram/SourceFiles/window/window_connecting_widget.h index 5c391a9a6..7813ce5ad 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.h +++ b/Telegram/SourceFiles/window/window_connecting_widget.h @@ -46,6 +46,7 @@ private: }; Type type = Type::Connected; bool useProxy = false; + bool exposed = false; bool underCursor = false; bool updateReady = false; int waitTillRetry = 0; @@ -79,6 +80,7 @@ private: const not_null _account; not_null _parent; + base::unique_qptr _exposeFilter; rpl::variable _bottomSkip; base::unique_qptr _widget; bool _forceHidden = false;