mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Hide connection widget when the window is not exposed
This commit is contained in:
parent
1e98e19aaf
commit
333ef9b48a
3 changed files with 32 additions and 7 deletions
|
@ -55,6 +55,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_send_action.h"
|
#include "data/data_send_action.h"
|
||||||
#include "chat_helpers/emoji_interactions.h"
|
#include "chat_helpers/emoji_interactions.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "support/support_helper.h"
|
#include "support/support_helper.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_chat_participants.h"
|
#include "api/api_chat_participants.h"
|
||||||
|
@ -230,6 +231,16 @@ TopBarWidget::TopBarWidget(
|
||||||
updateConnectingState();
|
updateConnectingState();
|
||||||
}, lifetime());
|
}, 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);
|
setCursor(style::cur_pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +252,8 @@ Main::Session &TopBarWidget::session() const {
|
||||||
|
|
||||||
void TopBarWidget::updateConnectingState() {
|
void TopBarWidget::updateConnectingState() {
|
||||||
const auto state = _controller->session().mtp().dcstate();
|
const auto state = _controller->session().mtp().dcstate();
|
||||||
if (state == MTP::ConnectedState) {
|
const auto exposed = window()->windowHandle()->isExposed();
|
||||||
|
if (state == MTP::ConnectedState || !exposed) {
|
||||||
if (_connecting) {
|
if (_connecting) {
|
||||||
_connecting = nullptr;
|
_connecting = nullptr;
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "window/window_connecting_widget.h"
|
#include "window/window_connecting_widget.h"
|
||||||
|
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/effects/radial_animation.h"
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
|
@ -207,6 +208,14 @@ ConnectionState::ConnectionState(
|
||||||
rpl::producer<bool> shown)
|
rpl::producer<bool> shown)
|
||||||
: _account(account)
|
: _account(account)
|
||||||
, _parent(parent)
|
, _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(); })
|
, _refreshTimer([=] { refreshState(); })
|
||||||
, _currentLayout(computeLayout(_state)) {
|
, _currentLayout(computeLayout(_state)) {
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
|
@ -290,6 +299,7 @@ void ConnectionState::setBottomSkip(int skip) {
|
||||||
void ConnectionState::refreshState() {
|
void ConnectionState::refreshState() {
|
||||||
using Checker = Core::UpdateChecker;
|
using Checker = Core::UpdateChecker;
|
||||||
const auto state = [&]() -> State {
|
const auto state = [&]() -> State {
|
||||||
|
const auto exposed = _parent->window()->windowHandle()->isExposed();
|
||||||
const auto under = _widget && _widget->isOver();
|
const auto under = _widget && _widget->isOver();
|
||||||
const auto ready = (Checker().state() == Checker::State::Ready);
|
const auto ready = (Checker().state() == Checker::State::Ready);
|
||||||
const auto state = _account->mtp().dcstate();
|
const auto state = _account->mtp().dcstate();
|
||||||
|
@ -297,18 +307,18 @@ void ConnectionState::refreshState() {
|
||||||
if (state == MTP::ConnectingState
|
if (state == MTP::ConnectingState
|
||||||
|| state == MTP::DisconnectedState
|
|| state == MTP::DisconnectedState
|
||||||
|| (state < 0 && state > -600)) {
|
|| (state < 0 && state > -600)) {
|
||||||
return { State::Type::Connecting, proxy, under, ready };
|
return { State::Type::Connecting, proxy, exposed, under, ready };
|
||||||
} else if (state < 0
|
} else if (state < 0
|
||||||
&& state >= -kMinimalWaitingStateDuration
|
&& state >= -kMinimalWaitingStateDuration
|
||||||
&& _state.type != State::Type::Waiting) {
|
&& _state.type != State::Type::Waiting) {
|
||||||
return { State::Type::Connecting, proxy, under, ready };
|
return { State::Type::Connecting, proxy, exposed, under, ready };
|
||||||
} else if (state < 0) {
|
} else if (state < 0) {
|
||||||
const auto wait = ((-state) / 1000) + 1;
|
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);
|
_refreshTimer.callOnce(kRefreshTimeout);
|
||||||
}
|
}
|
||||||
if (state == _state) {
|
if (state == _state) {
|
||||||
|
@ -421,7 +431,8 @@ auto ConnectionState::computeLayout(const State &state) const -> Layout {
|
||||||
auto result = Layout();
|
auto result = Layout();
|
||||||
result.proxyEnabled = state.useProxy;
|
result.proxyEnabled = state.useProxy;
|
||||||
result.progressShown = (state.type != State::Type::Connected);
|
result.progressShown = (state.type != State::Type::Connected);
|
||||||
result.visible = !state.updateReady
|
result.visible = state.exposed
|
||||||
|
&& !state.updateReady
|
||||||
&& (state.useProxy
|
&& (state.useProxy
|
||||||
|| state.type == State::Type::Connecting
|
|| state.type == State::Type::Connecting
|
||||||
|| state.type == State::Type::Waiting);
|
|| state.type == State::Type::Waiting);
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
};
|
};
|
||||||
Type type = Type::Connected;
|
Type type = Type::Connected;
|
||||||
bool useProxy = false;
|
bool useProxy = false;
|
||||||
|
bool exposed = false;
|
||||||
bool underCursor = false;
|
bool underCursor = false;
|
||||||
bool updateReady = false;
|
bool updateReady = false;
|
||||||
int waitTillRetry = 0;
|
int waitTillRetry = 0;
|
||||||
|
@ -79,6 +80,7 @@ private:
|
||||||
|
|
||||||
const not_null<Main::Account*> _account;
|
const not_null<Main::Account*> _account;
|
||||||
not_null<Ui::RpWidget*> _parent;
|
not_null<Ui::RpWidget*> _parent;
|
||||||
|
base::unique_qptr<QObject> _exposeFilter;
|
||||||
rpl::variable<int> _bottomSkip;
|
rpl::variable<int> _bottomSkip;
|
||||||
base::unique_qptr<Widget> _widget;
|
base::unique_qptr<Widget> _widget;
|
||||||
bool _forceHidden = false;
|
bool _forceHidden = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue