From 8f076b0c9ea21651aa164ac3381247b834e1cf91 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 4 Jun 2022 09:59:48 +0300 Subject: [PATCH] Added auto-scroll-inactive-chat option. --- Telegram/SourceFiles/history/history_widget.cpp | 14 ++++++++++++++ Telegram/SourceFiles/history/history_widget.h | 2 ++ .../SourceFiles/settings/settings_experimental.cpp | 2 ++ 3 files changed, 18 insertions(+) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cf4889be8..606a98375 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -122,6 +122,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "core/application.h" #include "apiwrap.h" +#include "base/options.h" #include "base/qthelp_regex.h" #include "ui/boxes/report_box.h" #include "ui/chat/pinned_bar.h" @@ -165,6 +166,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +const char kOptionAutoScrollInactiveChat[] = + "auto-scroll-inactive-chat"; + namespace { constexpr auto kMessagesPerPageFirst = 30; @@ -185,6 +189,13 @@ constexpr auto kCommonModifiers = 0 | Qt::ControlModifier; const auto kPsaAboutPrefix = "cloud_lng_about_psa_"; +base::options::toggle AutoScrollInactiveChat({ + .id = kOptionAutoScrollInactiveChat, + .name = "Enable auto-scroll of inactive chat", + .description = "Enable auto-scrolling chat for new messages, " + "even when the window is not in focus.", +}); + [[nodiscard]] crl::time CountToastDuration(const TextWithEntities &text) { return std::clamp( crl::time(1000) * int(text.text.size()) / 14, @@ -5434,6 +5445,9 @@ int HistoryWidget::countAutomaticScrollTop() { Expects(_list != nullptr); if (const auto unread = _history->firstUnreadMessage()) { + if (AutoScrollInactiveChat.value()) { + return ScrollMax; + } const auto firstUnreadTop = _list->itemTop(unread); const auto possibleUnreadBarTop = _scroll->scrollTopMax() + HistoryView::UnreadBar::height() diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 86c4689af..60dd6b3c9 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -122,6 +122,8 @@ class MessageField; class HistoryInner; struct HistoryMessageMarkupButton; +extern const char kOptionAutoScrollInactiveChat[]; + class HistoryWidget final : public Window::AbstractSectionWidget { public: using FieldHistoryAction = Ui::InputField::HistoryAction; diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index 5f4df2175..22f382ff9 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/options.h" #include "core/application.h" #include "chat_helpers/tabbed_panel.h" +#include "history/history_widget.h" #include "lang/lang_keys.h" #include "media/player/media_player_instance.h" #include "webview/webview_embed.h" @@ -137,6 +138,7 @@ void SetupExperimental( addToggle(Media::Player::kOptionDisableAutoplayNext); addToggle(Settings::kOptionMonoSettingsIcons); addToggle(Webview::kOptionWebviewDebugEnabled); + addToggle(kOptionAutoScrollInactiveChat); } } // namespace