Update exposed state for connecting widgets without QWindow events

This commit is contained in:
Ilya Fedin 2024-06-21 14:35:26 +04:00 committed by John Preston
parent b58ece3a38
commit d2d5226dc7
3 changed files with 23 additions and 25 deletions

View file

@ -55,7 +55,6 @@ 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"
@ -233,16 +232,6 @@ TopBarWidget::TopBarWidget(
updateConnectingState();
}, lifetime());
base::install_event_filter(
this,
window()->windowHandle(),
[=](not_null<QEvent*> e) {
if (e->type() == QEvent::Expose) {
updateConnectingState();
}
return base::EventFilterResult::Continue;
});
setCursor(style::cur_pointer);
}
@ -254,7 +243,8 @@ Main::Session &TopBarWidget::session() const {
void TopBarWidget::updateConnectingState() {
const auto state = _controller->session().mtp().dcstate();
const auto exposed = window()->windowHandle()->isExposed();
const auto exposed = window()->windowHandle()
&& window()->windowHandle()->isExposed();
if (state == MTP::ConnectedState || !exposed) {
if (_connecting) {
_connecting = nullptr;
@ -271,6 +261,7 @@ void TopBarWidget::updateConnectingState() {
void TopBarWidget::connectingAnimationCallback() {
if (!anim::Disabled()) {
updateConnectingState();
update();
}
}
@ -436,6 +427,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) {
if (_animatingMode) {
return;
}
updateConnectingState();
Painter p(this);
const auto selectedButtonsTop = countSelectedButtonsTop(

View file

@ -7,7 +7,6 @@ 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"
@ -37,6 +36,8 @@ class Progress : public Ui::RpWidget {
public:
Progress(QWidget *parent);
rpl::producer<> animationStepRequests() const;
protected:
void paintEvent(QPaintEvent *e) override;
@ -44,6 +45,7 @@ private:
void animationStep();
Ui::InfiniteRadialAnimation _animation;
rpl::event_stream<> _animationStepRequests;
};
@ -71,10 +73,15 @@ void Progress::paintEvent(QPaintEvent *e) {
void Progress::animationStep() {
if (!anim::Disabled()) {
_animationStepRequests.fire({});
update();
}
}
rpl::producer<> Progress::animationStepRequests() const {
return _animationStepRequests.events();
}
} // namespace
class ConnectionState::Widget : public Ui::AbstractButton {
@ -109,7 +116,7 @@ private:
const not_null<Main::Account*> _account;
Layout _currentLayout;
base::unique_qptr<Ui::LinkButton> _retry;
QPointer<Ui::RpWidget> _progress;
QPointer<Progress> _progress;
QPointer<ProxyIcon> _proxyIcon;
rpl::event_stream<> _refreshStateRequests;
@ -210,14 +217,6 @@ ConnectionState::ConnectionState(
rpl::producer<bool> shown)
: _account(account)
, _parent(parent)
, _exposeFilter(base::install_event_filter(
parent->window()->windowHandle(),
[=](not_null<QEvent*> e) {
if (e->type() == QEvent::Expose) {
refreshState();
}
return base::EventFilterResult::Continue;
}))
, _refreshTimer([=] { refreshState(); })
, _currentLayout(computeLayout(_state)) {
rpl::combine(
@ -241,7 +240,9 @@ ConnectionState::ConnectionState(
}, _lifetime);
}
Core::App().settings().proxy().connectionTypeValue(
rpl::combine(
Core::App().settings().proxy().connectionTypeValue(),
rpl::single(QRect()) | rpl::then(_parent->paintRequest())
) | rpl::start_with_next([=] {
refreshState();
}, _lifetime);
@ -301,7 +302,8 @@ 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 exposed = _parent->window()->windowHandle()
&& _parent->window()->windowHandle()->isExposed();
const auto under = _widget && _widget->isOver();
const auto ready = (Checker().state() == Checker::State::Ready);
const auto state = _account->mtp().dcstate();
@ -501,6 +503,11 @@ ConnectionState::Widget::Widget(
addClickHandler([=] {
Ui::show(ProxiesBoxController::CreateOwningBox(account));
});
_progress->animationStepRequests(
) | rpl::start_with_next([=] {
_refreshStateRequests.fire({});
}, _progress->lifetime());
}
void ConnectionState::Widget::onStateChanged(

View file

@ -80,7 +80,6 @@ private:
const not_null<Main::Account*> _account;
not_null<Ui::RpWidget*> _parent;
base::unique_qptr<QObject> _exposeFilter;
rpl::variable<int> _bottomSkip;
base::unique_qptr<Widget> _widget;
bool _forceHidden = false;