Limit inline results repainting rate.
This commit is contained in:
parent
827ce46d3c
commit
f45c47f3d5
|
@ -35,6 +35,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
namespace InlineBots {
|
namespace InlineBots {
|
||||||
namespace Layout {
|
namespace Layout {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kMinRepaintDelay = crl::time(33);
|
||||||
|
constexpr auto kMinAfterScrollDelay = crl::time(33);
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Inner::Inner(
|
Inner::Inner(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
|
@ -44,7 +50,7 @@ Inner::Inner(
|
||||||
, _pathGradient(std::make_unique<Ui::PathShiftGradient>(
|
, _pathGradient(std::make_unique<Ui::PathShiftGradient>(
|
||||||
st::windowBgRipple,
|
st::windowBgRipple,
|
||||||
st::windowBgOver,
|
st::windowBgOver,
|
||||||
[=] { update(); }))
|
[=] { repaintItems(); }))
|
||||||
, _updateInlineItems([=] { updateInlineItems(); })
|
, _updateInlineItems([=] { updateInlineItems(); })
|
||||||
, _mosaic(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft)
|
, _mosaic(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft)
|
||||||
, _previewTimer([=] { showPreview(); }) {
|
, _previewTimer([=] { showPreview(); }) {
|
||||||
|
@ -55,14 +61,14 @@ Inner::Inner(
|
||||||
|
|
||||||
_controller->session().downloaderTaskFinished(
|
_controller->session().downloaderTaskFinished(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
update();
|
updateInlineItems();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
controller->gifPauseLevelChanged(
|
controller->gifPauseLevelChanged(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (!_controller->isGifPausedAtLeastFor(
|
if (!_controller->isGifPausedAtLeastFor(
|
||||||
Window::GifPauseReason::InlineResults)) {
|
Window::GifPauseReason::InlineResults)) {
|
||||||
update();
|
updateInlineItems();
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
@ -92,7 +98,8 @@ void Inner::visibleTopBottomUpdated(
|
||||||
_visibleBottom = visibleBottom;
|
_visibleBottom = visibleBottom;
|
||||||
if (_visibleTop != visibleTop) {
|
if (_visibleTop != visibleTop) {
|
||||||
_visibleTop = visibleTop;
|
_visibleTop = visibleTop;
|
||||||
_lastScrolled = crl::now();
|
_lastScrolledAt = crl::now();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +117,7 @@ void Inner::checkRestrictedPeer() {
|
||||||
if (_switchPmButton) {
|
if (_switchPmButton) {
|
||||||
_switchPmButton->hide();
|
_switchPmButton->hide();
|
||||||
}
|
}
|
||||||
update();
|
repaintItems();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +127,7 @@ void Inner::checkRestrictedPeer() {
|
||||||
if (_switchPmButton) {
|
if (_switchPmButton) {
|
||||||
_switchPmButton->show();
|
_switchPmButton->show();
|
||||||
}
|
}
|
||||||
update();
|
repaintItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +339,7 @@ void Inner::clearSelection() {
|
||||||
setCursor(style::cur_default);
|
setCursor(style::cur_default);
|
||||||
}
|
}
|
||||||
_selected = _pressed = -1;
|
_selected = _pressed = -1;
|
||||||
update();
|
updateInlineItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inner::hideFinished() {
|
void Inner::hideFinished() {
|
||||||
|
@ -433,7 +440,7 @@ void Inner::refreshSwitchPmButton(const CacheEntry *entry) {
|
||||||
_switchPmButton->hide();
|
_switchPmButton->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
repaintItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntry *entry, bool resultsDeleted) {
|
int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntry *entry, bool resultsDeleted) {
|
||||||
|
@ -485,7 +492,7 @@ int Inner::refreshInlineRows(PeerData *queryPeer, UserData *bot, const CacheEntr
|
||||||
|
|
||||||
auto h = countHeight();
|
auto h = countHeight();
|
||||||
if (h != height()) resize(width(), h);
|
if (h != height()) resize(width(), h);
|
||||||
update();
|
repaintItems();
|
||||||
|
|
||||||
_lastMousePos = QCursor::pos();
|
_lastMousePos = QCursor::pos();
|
||||||
updateSelected();
|
updateSelected();
|
||||||
|
@ -525,12 +532,7 @@ void Inner::inlineItemLayoutChanged(const ItemBase *layout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inner::inlineItemRepaint(const ItemBase *layout) {
|
void Inner::inlineItemRepaint(const ItemBase *layout) {
|
||||||
auto ms = crl::now();
|
updateInlineItems();
|
||||||
if (_lastScrolled + 100 <= ms) {
|
|
||||||
update();
|
|
||||||
} else {
|
|
||||||
_updateInlineItems.callOnce(_lastScrolled + 100 - ms);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Inner::inlineItemVisible(const ItemBase *layout) {
|
bool Inner::inlineItemVisible(const ItemBase *layout) {
|
||||||
|
@ -618,14 +620,24 @@ void Inner::showPreview() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inner::updateInlineItems() {
|
void Inner::updateInlineItems() {
|
||||||
auto ms = crl::now();
|
const auto now = crl::now();
|
||||||
if (_lastScrolled + 100 <= ms) {
|
|
||||||
update();
|
const auto delay = std::max(
|
||||||
} else {
|
_lastScrolledAt + kMinAfterScrollDelay - now,
|
||||||
_updateInlineItems.callOnce(_lastScrolled + 100 - ms);
|
_lastUpdatedAt + kMinRepaintDelay - now);
|
||||||
|
if (delay <= 0) {
|
||||||
|
repaintItems();
|
||||||
|
} else if (!_updateInlineItems.isActive()
|
||||||
|
|| _updateInlineItems.remainingTime() > kMinRepaintDelay) {
|
||||||
|
_updateInlineItems.callOnce(std::max(delay, kMinRepaintDelay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Inner::repaintItems(crl::time now) {
|
||||||
|
_lastUpdatedAt = now ? now : crl::now();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void Inner::switchPm() {
|
void Inner::switchPm() {
|
||||||
if (_inlineBot && _inlineBot->isBot()) {
|
if (_inlineBot && _inlineBot->isBot()) {
|
||||||
_inlineBot->botInfo->startToken = _switchPmStartToken;
|
_inlineBot->botInfo->startToken = _switchPmStartToken;
|
||||||
|
|
|
@ -135,6 +135,7 @@ private:
|
||||||
|
|
||||||
void showPreview();
|
void showPreview();
|
||||||
void updateInlineItems();
|
void updateInlineItems();
|
||||||
|
void repaintItems(crl::time now = 0);
|
||||||
void clearInlineRows(bool resultsDeleted);
|
void clearInlineRows(bool resultsDeleted);
|
||||||
ItemBase *layoutPrepareInlineResult(Result *result);
|
ItemBase *layoutPrepareInlineResult(Result *result);
|
||||||
|
|
||||||
|
@ -154,7 +155,8 @@ private:
|
||||||
|
|
||||||
UserData *_inlineBot = nullptr;
|
UserData *_inlineBot = nullptr;
|
||||||
PeerData *_inlineQueryPeer = nullptr;
|
PeerData *_inlineQueryPeer = nullptr;
|
||||||
crl::time _lastScrolled = 0;
|
crl::time _lastScrolledAt = 0;
|
||||||
|
crl::time _lastUpdatedAt = 0;
|
||||||
base::Timer _updateInlineItems;
|
base::Timer _updateInlineItems;
|
||||||
bool _inlineWithThumb = false;
|
bool _inlineWithThumb = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue