Add hierarchy of GIF pausing inside a window.

GIFs get paused if some other layer is displayed above.
Media preview > Box or layer > Saved GIFs panel > Inline bot results.
If any of those is displayed, GIFs inside message history pause too.
This commit is contained in:
John Preston 2017-04-03 17:13:55 +03:00
parent 6003ac2132
commit ffc9585196
19 changed files with 89 additions and 80 deletions

View File

@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "styles/style_history.h" #include "styles/style_history.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "media/media_clip_reader.h" #include "media/media_clip_reader.h"
#include "mainwindow.h"
namespace { namespace {
@ -330,7 +331,8 @@ void SendFilesBox::paintEvent(QPaintEvent *e) {
} }
if (_gifPreview && _gifPreview->started()) { if (_gifPreview && _gifPreview->started()) {
auto s = QSize(_previewWidth, _previewHeight); auto s = QSize(_previewWidth, _previewHeight);
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, getms()); auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer);
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms());
p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), frame); p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), frame);
} else { } else {
p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), _preview); p.drawPixmap(_previewLeft, st::boxPhotoPadding.top(), _preview);
@ -671,7 +673,8 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) {
} }
if (_gifPreview && _gifPreview->started()) { if (_gifPreview && _gifPreview->started()) {
auto s = QSize(_thumbw, _thumbh); auto s = QSize(_thumbw, _thumbh);
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, getms()); auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Layer);
auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms());
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), frame); p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), frame);
} else { } else {
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb); p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb);

View File

@ -251,13 +251,6 @@ bool isMediaViewShown() {
return false; return false;
} }
bool isInlineItemBeingChosen() {
if (auto main = App::main()) {
return main->ui_isInlineItemBeingChosen();
}
return false;
}
void repaintHistoryItem(const HistoryItem *item) { void repaintHistoryItem(const HistoryItem *item) {
if (auto main = App::main()) { if (auto main = App::main()) {
main->ui_repaintHistoryItem(item); main->ui_repaintHistoryItem(item);
@ -364,10 +357,6 @@ void migrateUpdated(PeerData *peer) {
if (MainWidget *m = App::main()) m->notify_migrateUpdated(peer); if (MainWidget *m = App::main()) m->notify_migrateUpdated(peer);
} }
void clipStopperHidden(ClipStopperType type) {
if (MainWidget *m = App::main()) m->notify_clipStopperHidden(type);
}
void historyItemLayoutChanged(const HistoryItem *item) { void historyItemLayoutChanged(const HistoryItem *item) {
if (MainWidget *m = App::main()) m->notify_historyItemLayoutChanged(item); if (MainWidget *m = App::main()) m->notify_historyItemLayoutChanged(item);
} }

View File

@ -106,7 +106,6 @@ void hideLayer(bool fast = false);
void hideSettingsAndLayer(bool fast = false); void hideSettingsAndLayer(bool fast = false);
bool isLayerShown(); bool isLayerShown();
bool isMediaViewShown(); bool isMediaViewShown();
bool isInlineItemBeingChosen();
void repaintHistoryItem(const HistoryItem *item); void repaintHistoryItem(const HistoryItem *item);
void autoplayMediaInlineAsync(const FullMsgId &msgId); void autoplayMediaInlineAsync(const FullMsgId &msgId);
@ -175,8 +174,6 @@ bool switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot =
void migrateUpdated(PeerData *peer); void migrateUpdated(PeerData *peer);
void clipStopperHidden(ClipStopperType type);
void historyItemLayoutChanged(const HistoryItem *item); void historyItemLayoutChanged(const HistoryItem *item);
void historyMuteUpdated(History *history); void historyMuteUpdated(History *history);

View File

@ -1844,8 +1844,8 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM
auto roundCorners = inWebPage ? ImageRoundCorner::All : ((isBubbleTop() ? (ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight) : ImageRoundCorner::None) auto roundCorners = inWebPage ? ImageRoundCorner::All : ((isBubbleTop() ? (ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight) : ImageRoundCorner::None)
| ((isBubbleBottom() && _caption.isEmpty()) ? (ImageRoundCorner::BottomLeft | ImageRoundCorner::BottomRight) : ImageRoundCorner::None)); | ((isBubbleBottom() && _caption.isEmpty()) ? (ImageRoundCorner::BottomLeft | ImageRoundCorner::BottomRight) : ImageRoundCorner::None));
if (animating) { if (animating) {
auto pauseGif = (Ui::isLayerShown() || Ui::isMediaViewShown() || Ui::isInlineItemBeingChosen() || !App::wnd()->isActive()); auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Any);
p.drawPixmap(rthumb.topLeft(), _gif->current(_thumbw, _thumbh, width, height, roundRadius, roundCorners, pauseGif ? 0 : ms)); p.drawPixmap(rthumb.topLeft(), _gif->current(_thumbw, _thumbh, width, height, roundRadius, roundCorners, paused ? 0 : ms));
} else { } else {
p.drawPixmap(rthumb.topLeft(), _data->thumb->pixBlurredSingle(_thumbw, _thumbh, width, height, roundRadius, roundCorners)); p.drawPixmap(rthumb.topLeft(), _data->thumb->pixBlurredSingle(_thumbw, _thumbh, width, height, roundRadius, roundCorners));
} }

View File

@ -169,6 +169,11 @@ HistoryInner::HistoryInner(HistoryWidget *historyWidget, Ui::ScrollArea *scroll,
subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) { subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) {
itemRemoved(item); itemRemoved(item);
}); });
subscribe(App::wnd()->gifPauseLevelChanged(), [this] {
if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::Any)) {
update();
}
});
} }
void HistoryInner::messagesReceived(PeerData *peer, const QVector<MTPMessage> &messages) { void HistoryInner::messagesReceived(PeerData *peer, const QVector<MTPMessage> &messages) {
@ -3828,10 +3833,6 @@ void HistoryWidget::notify_migrateUpdated(PeerData *peer) {
} }
} }
void HistoryWidget::notify_clipStopperHidden(ClipStopperType type) {
if (_list) _list->update();
}
bool HistoryWidget::cmd_search() { bool HistoryWidget::cmd_search() {
if (!inFocusChain() || !_peer) return false; if (!inFocusChain() || !_peer) return false;
@ -7164,11 +7165,6 @@ void HistoryWidget::onUpdateHistoryItems() {
} }
} }
bool HistoryWidget::ui_isInlineItemBeingChosen() {
return _emojiPanel->ui_isInlineItemBeingChosen()
|| (_inlineResults && _inlineResults->ui_isInlineItemBeingChosen());
}
PeerData *HistoryWidget::ui_getPeerForMouseAction() { PeerData *HistoryWidget::ui_getPeerForMouseAction() {
return _peer; return _peer;
} }

View File

@ -716,7 +716,6 @@ public:
void app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col); void app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col);
void ui_repaintHistoryItem(const HistoryItem *item); void ui_repaintHistoryItem(const HistoryItem *item);
bool ui_isInlineItemBeingChosen();
PeerData *ui_getPeerForMouseAction(); PeerData *ui_getPeerForMouseAction();
void notify_historyItemLayoutChanged(const HistoryItem *item); void notify_historyItemLayoutChanged(const HistoryItem *item);
@ -727,7 +726,6 @@ public:
bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo); bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
void notify_userIsBotChanged(UserData *user); void notify_userIsBotChanged(UserData *user);
void notify_migrateUpdated(PeerData *peer); void notify_migrateUpdated(PeerData *peer);
void notify_clipStopperHidden(ClipStopperType type);
void notify_handlePendingHistoryUpdate(); void notify_handlePendingHistoryUpdate();
bool cmd_search(); bool cmd_search();

View File

@ -160,7 +160,8 @@ void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) cons
QRect r(0, 0, _width, height); QRect r(0, 0, _width, height);
if (animating) { if (animating) {
if (!_thumb.isNull()) _thumb = QPixmap(); if (!_thumb.isNull()) _thumb = QPixmap();
p.drawPixmap(r.topLeft(), _gif->current(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, ImageRoundCorner::None, context->paused ? 0 : context->ms)); auto pixmap = _gif->current(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, ImageRoundCorner::None, context->paused ? 0 : context->ms);
p.drawPixmap(r.topLeft(), pixmap);
} else { } else {
prepareThumb(_width, height, frame); prepareThumb(_width, height, frame);
if (_thumb.isNull()) { if (_thumb.isNull()) {

View File

@ -60,11 +60,11 @@ Inner::Inner(QWidget *parent) : TWidget(parent) {
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] {
update(); update();
}); });
} subscribe(App::wnd()->gifPauseLevelChanged(), [this] {
if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults)) {
void Inner::setMaxHeight(int maxHeight) { update();
_maxHeight = maxHeight; }
resize(st::emojiPanWidth - st::emojiScroll.width - st::buttonRadius, countHeight()); });
} }
void Inner::setVisibleTopBottom(int visibleTop, int visibleBottom) { void Inner::setVisibleTopBottom(int visibleTop, int visibleBottom) {
@ -107,7 +107,7 @@ void Inner::paintInlineItems(Painter &p, const QRect &r) {
p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center); p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center);
return; return;
} }
auto gifPaused = Ui::isLayerShown() || Ui::isMediaViewShown() || _previewShown || !App::wnd()->isActive(); auto gifPaused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults);
InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false); InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false);
auto top = st::stickerPanPadding; auto top = st::stickerPanPadding;
@ -547,10 +547,6 @@ bool Inner::inlineItemVisible(const ItemBase *layout) {
return (top < _visibleTop + _maxHeight) && (top + _rows[row].items[col]->height() > _visibleTop); return (top < _visibleTop + _maxHeight) && (top + _rows[row].items[col]->height() > _visibleTop);
} }
bool Inner::ui_isInlineItemBeingChosen() {
return true;
}
void Inner::updateSelected() { void Inner::updateSelected() {
if (_pressed >= 0 && !_previewShown) { if (_pressed >= 0 && !_previewShown) {
return; return;
@ -890,6 +886,8 @@ Widget::~Widget() = default;
void Widget::hideFinished() { void Widget::hideFinished() {
hide(); hide();
App::wnd()->disableGifPauseReason(Window::GifPauseReason::InlineResults);
_inner->hideFinish(true); _inner->hideFinish(true);
_a_show.finish(); _a_show.finish();
_showAnimation.reset(); _showAnimation.reset();
@ -898,8 +896,6 @@ void Widget::hideFinished() {
_hiding = false; _hiding = false;
_scroll->scrollToY(0); _scroll->scrollToY(0);
Notify::clipStopperHidden(ClipStopperSavedGifsPanel);
} }
void Widget::showAnimated() { void Widget::showAnimated() {
@ -912,19 +908,13 @@ void Widget::showStarted() {
_inner->preloadImages(); _inner->preloadImages();
moveByBottom(); moveByBottom();
show(); show();
App::wnd()->enableGifPauseReason(Window::GifPauseReason::InlineResults);
startShowAnimation(); startShowAnimation();
} else if (_hiding) { } else if (_hiding) {
startOpacityAnimation(false); startOpacityAnimation(false);
} }
} }
bool Widget::ui_isInlineItemBeingChosen() {
if (!isHidden()) {
return _inner->ui_isInlineItemBeingChosen();
}
return false;
}
void Widget::onScroll() { void Widget::onScroll() {
auto st = _scroll->scrollTop(); auto st = _scroll->scrollTop();
if (st + _scroll->height() > _scroll->scrollTopMax()) { if (st + _scroll->height() > _scroll->scrollTopMax()) {

View File

@ -77,7 +77,6 @@ public:
void inlineItemLayoutChanged(const ItemBase *layout) override; void inlineItemLayoutChanged(const ItemBase *layout) override;
void inlineItemRepaint(const ItemBase *layout) override; void inlineItemRepaint(const ItemBase *layout) override;
bool inlineItemVisible(const ItemBase *layout) override; bool inlineItemVisible(const ItemBase *layout) override;
bool ui_isInlineItemBeingChosen();
int countHeight(bool plain = false); int countHeight(bool plain = false);
@ -179,8 +178,6 @@ public:
bool overlaps(const QRect &globalRect) const; bool overlaps(const QRect &globalRect) const;
bool ui_isInlineItemBeingChosen();
void showAnimated(); void showAnimated();
void hideAnimated(); void hideAnimated();

View File

@ -537,6 +537,7 @@ void LayerStackWidget::showBox(object_ptr<BoxContent> box) {
void LayerStackWidget::prepareForAnimation() { void LayerStackWidget::prepareForAnimation() {
if (isHidden()) { if (isHidden()) {
show(); show();
App::wnd()->enableGifPauseReason(Window::GifPauseReason::Layer);
} }
if (_mainMenu) { if (_mainMenu) {
_mainMenu->hide(); _mainMenu->hide();
@ -565,6 +566,7 @@ void LayerStackWidget::animationDone() {
} }
if (hidden) { if (hidden) {
App::wnd()->layerFinishedHide(this); App::wnd()->layerFinishedHide(this);
App::wnd()->disableGifPauseReason(Window::GifPauseReason::Layer);
} else { } else {
showFinished(); showFinished();
} }
@ -734,6 +736,7 @@ void MediaPreviewWidget::paintEvent(QPaintEvent *e) {
if (!_a_shown.animating()) { if (!_a_shown.animating()) {
if (_hiding) { if (_hiding) {
hide(); hide();
App::wnd()->disableGifPauseReason(Window::GifPauseReason::MediaPreview);
return; return;
} }
} else { } else {
@ -788,7 +791,10 @@ void MediaPreviewWidget::showPreview(PhotoData *photo) {
void MediaPreviewWidget::startShow() { void MediaPreviewWidget::startShow() {
_cache = QPixmap(); _cache = QPixmap();
if (isHidden() || _a_shown.animating()) { if (isHidden() || _a_shown.animating()) {
if (isHidden()) show(); if (isHidden()) {
show();
App::wnd()->enableGifPauseReason(Window::GifPauseReason::MediaPreview);
}
_hiding = false; _hiding = false;
_a_shown.start([this] { update(); }, 0., 1., st::stickerPreviewDuration); _a_shown.start([this] { update(); }, 0., 1., st::stickerPreviewDuration);
} else { } else {
@ -920,8 +926,9 @@ QPixmap MediaPreviewWidget::currentImage() const {
} }
} }
if (_gif && _gif->started()) { if (_gif && _gif->started()) {
QSize s = currentDimensions(); auto s = currentDimensions();
return _gif->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, getms()); auto paused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::MediaPreview);
return _gif->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, ImageRoundCorner::None, paused ? 0 : getms());
} }
if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) { if (_cacheStatus != CacheThumbLoaded && _document->thumb->loaded()) {
QSize s = currentDimensions(); QSize s = currentDimensions();

View File

@ -540,10 +540,6 @@ void MainWidget::notify_migrateUpdated(PeerData *peer) {
_history->notify_migrateUpdated(peer); _history->notify_migrateUpdated(peer);
} }
void MainWidget::notify_clipStopperHidden(ClipStopperType type) {
_history->notify_clipStopperHidden(type);
}
void MainWidget::ui_repaintHistoryItem(const HistoryItem *item) { void MainWidget::ui_repaintHistoryItem(const HistoryItem *item) {
_history->ui_repaintHistoryItem(item); _history->ui_repaintHistoryItem(item);
if (item->history()->lastMsg == item) { if (item->history()->lastMsg == item) {
@ -554,10 +550,6 @@ void MainWidget::ui_repaintHistoryItem(const HistoryItem *item) {
if (_overview) _overview->ui_repaintHistoryItem(item); if (_overview) _overview->ui_repaintHistoryItem(item);
} }
bool MainWidget::ui_isInlineItemBeingChosen() {
return _history->ui_isInlineItemBeingChosen();
}
void MainWidget::notify_historyItemLayoutChanged(const HistoryItem *item) { void MainWidget::notify_historyItemLayoutChanged(const HistoryItem *item) {
_history->notify_historyItemLayoutChanged(item); _history->notify_historyItemLayoutChanged(item);
if (_overview) _overview->notify_historyItemLayoutChanged(item); if (_overview) _overview->notify_historyItemLayoutChanged(item);

View File

@ -383,7 +383,6 @@ public:
void app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col); void app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col);
void ui_repaintHistoryItem(const HistoryItem *item); void ui_repaintHistoryItem(const HistoryItem *item);
bool ui_isInlineItemBeingChosen();
void ui_showPeerHistory(quint64 peer, qint32 msgId, Ui::ShowWay way); void ui_showPeerHistory(quint64 peer, qint32 msgId, Ui::ShowWay way);
PeerData *ui_getPeerForMouseAction(); PeerData *ui_getPeerForMouseAction();
@ -395,7 +394,6 @@ public:
void notify_userIsBotChanged(UserData *bot); void notify_userIsBotChanged(UserData *bot);
void notify_userIsContactChanged(UserData *user, bool fromThisApp); void notify_userIsContactChanged(UserData *user, bool fromThisApp);
void notify_migrateUpdated(PeerData *peer); void notify_migrateUpdated(PeerData *peer);
void notify_clipStopperHidden(ClipStopperType type);
void notify_historyItemLayoutChanged(const HistoryItem *item); void notify_historyItemLayoutChanged(const HistoryItem *item);
void notify_historyMuteUpdated(History *history); void notify_historyMuteUpdated(History *history);
void notify_handlePendingHistoryUpdate(); void notify_handlePendingHistoryUpdate();

View File

@ -2662,7 +2662,6 @@ void MediaView::setVisible(bool visible) {
stopGif(); stopGif();
destroyThemePreview(); destroyThemePreview();
_radial.stop(); _radial.stop();
Notify::clipStopperHidden(ClipStopperMediaview);
} }
} }
@ -2903,6 +2902,6 @@ void MediaView::updateHeader() {
} }
float64 MediaView::overLevel(OverState control) const { float64 MediaView::overLevel(OverState control) const {
ShowingOpacities::const_iterator i = _animOpacities.constFind(control); auto i = _animOpacities.constFind(control);
return (i == _animOpacities.cend()) ? (_over == control ? 1 : 0) : i->current(); return (i == _animOpacities.cend()) ? (_over == control ? 1 : 0) : i->current();
} }

View File

@ -688,8 +688,6 @@ void EmojiPanel::hideFinished() {
_hiding = false; _hiding = false;
scrollToY(0); scrollToY(0);
Notify::clipStopperHidden(ClipStopperSavedGifsPanel);
} }
void EmojiPanel::showAnimated() { void EmojiPanel::showAnimated() {
@ -745,10 +743,6 @@ void EmojiPanel::setInlineQueryPeer(PeerData *peer) {
gifs()->setInlineQueryPeer(peer); gifs()->setInlineQueryPeer(peer);
} }
bool EmojiPanel::ui_isInlineItemBeingChosen() {
return (_currentTabType == TabType::Gifs && !isHidden());
}
void EmojiPanel::showAll() { void EmojiPanel::showAll() {
currentTab()->footer()->show(); currentTab()->footer()->show();
_scroll->show(); _scroll->show();
@ -827,9 +821,6 @@ void EmojiPanel::switchTab() {
currentTab()->returnWidget(std::move(widget)); currentTab()->returnWidget(std::move(widget));
_currentTabType = newTabType; _currentTabType = newTabType;
if (_currentTabType == TabType::Gifs) {
Notify::clipStopperHidden(ClipStopperSavedGifsPanel);
}
currentTab()->widget()->refreshRecent(); currentTab()->widget()->refreshRecent();
currentTab()->widget()->preloadImages(); currentTab()->widget()->preloadImages();
setWidgetToScrollArea(); setWidgetToScrollArea();

View File

@ -62,8 +62,6 @@ public:
bool overlaps(const QRect &globalRect) const; bool overlaps(const QRect &globalRect) const;
void setInlineQueryPeer(PeerData *peer); void setInlineQueryPeer(PeerData *peer);
bool ui_isInlineItemBeingChosen();
void showAnimated(); void showAnimated();
void hideAnimated(); void hideAnimated();

View File

@ -131,6 +131,11 @@ GifsListWidget::GifsListWidget(QWidget *parent) : Inner(parent)
subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] {
update(); update();
}); });
subscribe(App::wnd()->gifPauseLevelChanged(), [this] {
if (!App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs)) {
update();
}
});
} }
object_ptr<EmojiPanel::InnerFooter> GifsListWidget::createFooter() { object_ptr<EmojiPanel::InnerFooter> GifsListWidget::createFooter() {
@ -240,7 +245,7 @@ void GifsListWidget::paintInlineItems(Painter &p, QRect clip) {
p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center); p.drawText(QRect(0, 0, width(), (height() / 3) * 2 + st::normalFont->height), lang(lng_inline_bot_no_results), style::al_center);
return; return;
} }
auto gifPaused = Ui::isLayerShown() || Ui::isMediaViewShown() || _previewShown || !App::wnd()->isActive(); auto gifPaused = App::wnd()->isGifPausedAtLeastFor(Window::GifPauseReason::SavedGifs);
InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false); InlineBots::Layout::PaintContext context(getms(), false, gifPaused, false);
auto top = st::stickerPanPadding; auto top = st::stickerPanPadding;
@ -375,6 +380,7 @@ EmojiPanel::InnerFooter *GifsListWidget::getFooter() const {
void GifsListWidget::processHideFinished() { void GifsListWidget::processHideFinished() {
clearSelection(); clearSelection();
App::wnd()->disableGifPauseReason(Window::GifPauseReason::SavedGifs);
} }
void GifsListWidget::processPanelHideFinished() { void GifsListWidget::processPanelHideFinished() {
@ -735,6 +741,7 @@ void GifsListWidget::afterShown() {
if (_footer) { if (_footer) {
_footer->stealFocus(); _footer->stealFocus();
} }
App::wnd()->enableGifPauseReason(Window::GifPauseReason::SavedGifs);
} }
void GifsListWidget::beforeHiding() { void GifsListWidget::beforeHiding() {

View File

@ -372,6 +372,32 @@ PeerData *MainWindow::ui_getPeerForMouseAction() {
return nullptr; return nullptr;
} }
void MainWindow::enableGifPauseReason(GifPauseReason reason) {
if (!(_gifPauseReasons & reason)) {
auto notify = (static_cast<int>(_gifPauseReasons) < static_cast<int>(reason));
_gifPauseReasons |= reason;
if (notify) {
_gifPauseLevelChanged.notify();
}
}
}
void MainWindow::disableGifPauseReason(GifPauseReason reason) {
if (_gifPauseReasons & reason) {
_gifPauseReasons &= ~qFlags(reason);
if (static_cast<int>(_gifPauseReasons) < static_cast<int>(reason)) {
_gifPauseLevelChanged.notify();
}
}
}
bool MainWindow::isGifPausedAtLeastFor(GifPauseReason reason) const {
if (reason == GifPauseReason::Any) {
return (_gifPauseReasons != 0) || !isActive();
}
return (static_cast<int>(_gifPauseReasons) >= 2 * static_cast<int>(reason)) || !isActive();
}
MainWindow::~MainWindow() = default; MainWindow::~MainWindow() = default;
} // namespace Window } // namespace Window

View File

@ -26,6 +26,16 @@ class MediaView;
namespace Window { namespace Window {
enum class GifPauseReason {
Any = 0,
InlineResults = (1 << 0),
SavedGifs = (1 << 1),
Layer = (1 << 2),
MediaPreview = (1 << 3),
};
Q_DECLARE_FLAGS(GifPauseReasons, GifPauseReason);
Q_DECLARE_OPERATORS_FOR_FLAGS(GifPauseReasons);
class TitleWidget; class TitleWidget;
class MainWindow : public QWidget, protected base::Subscriber { class MainWindow : public QWidget, protected base::Subscriber {
@ -84,6 +94,13 @@ public:
} }
virtual PeerData *ui_getPeerForMouseAction(); virtual PeerData *ui_getPeerForMouseAction();
void enableGifPauseReason(GifPauseReason reason);
void disableGifPauseReason(GifPauseReason reason);
base::Observable<void> &gifPauseLevelChanged() {
return _gifPauseLevelChanged;
}
bool isGifPausedAtLeastFor(GifPauseReason reason) const;
public slots: public slots:
bool minimizeToTray(); bool minimizeToTray();
void updateGlobalMenu() { void updateGlobalMenu() {
@ -169,6 +186,9 @@ private:
object_ptr<MediaView> _mediaView = { nullptr }; object_ptr<MediaView> _mediaView = { nullptr };
GifPauseReasons _gifPauseReasons = { 0 };
base::Observable<void> _gifPauseLevelChanged;
}; };
} // namespace Window } // namespace Window

View File

@ -353,7 +353,7 @@ Widget::Widget(Manager *manager, QPoint startPosition, int shift, Direction shif
, _a_shift(animation(this, &Widget::step_shift)) { , _a_shift(animation(this, &Widget::step_shift)) {
setWindowOpacity(0.); setWindowOpacity(0.);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint | Qt::NoDropShadowWindowHint); setWindowFlags(qFlags(Qt::Tool) | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint | Qt::NoDropShadowWindowHint);
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_MacAlwaysShowToolWindow); setAttribute(Qt::WA_MacAlwaysShowToolWindow);