diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index d51c20db60..b2abd7a817 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -64,13 +64,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_dialogs.h" #include "styles/style_layers.h" // st::boxLabel +#include + namespace Window { namespace { constexpr auto kMaxChatEntryHistorySize = 50; - -// Cache background scaled image after 3s. -constexpr auto kCacheBackgroundTimeout = 3000; +constexpr auto kCacheBackgroundTimeout = 3 * crl::time(1000); +constexpr auto kCacheBackgroundFastTimeout = crl::time(200); } // namespace @@ -1324,7 +1325,8 @@ CachedBackground SessionController::cachedBackground(QRect area) { } if (_willCacheForArea != area || !_cacheBackgroundTimer.isActive()) { _willCacheForArea = area; - _cacheBackgroundTimer.callOnce(kCacheBackgroundTimeout); + _lastAreaChangeTime = crl::now(); + _cacheBackgroundTimer.callOnce(kCacheBackgroundFastTimeout); } return {}; } @@ -1334,6 +1336,12 @@ void SessionController::cacheBackground() { if (background->colorForFill()) { return; } + const auto now = crl::now(); + if (now - _lastAreaChangeTime < kCacheBackgroundTimeout + && QGuiApplication::mouseButtons() != 0) { + _cacheBackgroundTimer.callOnce(kCacheBackgroundFastTimeout); + return; + } const auto gradient = background->gradientForFill(); const auto patternOpacity = background->paper().patternOpacity(); const auto &bg = background->pixmap(); diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index a9acc15dd4..957877cd4e 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -463,6 +463,7 @@ private: CachedBackground _cachedBackground; QRect _willCacheForArea; + crl::time _lastAreaChangeTime = 0; base::Timer _cacheBackgroundTimer; rpl::lifetime _lifetime;