Use rpl for Window::Theme::Background updates.

This commit is contained in:
John Preston 2021-07-15 14:12:38 +03:00
parent 7e83088a84
commit 4276b6cce0
66 changed files with 203 additions and 262 deletions

View file

@ -37,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_cloud_themes.h" #include "data/data_cloud_themes.h"
#include "data/data_chat_filters.h" #include "data/data_chat_filters.h"
#include "data/data_histories.h" #include "data/data_histories.h"
#include "data/data_wall_paper.h"
#include "data/stickers/data_stickers.h" #include "data/stickers/data_stickers.h"
#include "dialogs/dialogs_key.h" #include "dialogs/dialogs_key.h"
#include "core/core_cloud_password.h" #include "core/core_cloud_password.h"
@ -62,7 +63,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "window/window_lock_widgets.h" #include "window/window_lock_widgets.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/themes/window_theme.h"
#include "inline_bots/inline_bot_result.h" #include "inline_bots/inline_bot_result.h"
#include "chat_helpers/message_field.h" #include "chat_helpers/message_field.h"
#include "ui/item_text_options.h" #include "ui/item_text_options.h"

View file

@ -108,7 +108,7 @@ QString RequestKey(Types &&...values) {
} // namespace Api } // namespace Api
class ApiWrap : public MTP::Sender, private base::Subscriber { class ApiWrap final : public MTP::Sender {
public: public:
using SendAction = Api::SendAction; using SendAction = Api::SendAction;
using MessageToSend = Api::MessageToSend; using MessageToSend = Api::MessageToSend;

View file

@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_location_manager.h" #include "history/history_location_manager.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_element.h"
#include "media/audio/media_audio.h" #include "media/audio/media_audio.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/update_checker.h" #include "core/update_checker.h"
#include "core/sandbox.h" #include "core/sandbox.h"
#include "core/application.h" #include "core/application.h"
#include "window/themes/window_theme.h"
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "platform/platform_notifications_manager.h" #include "platform/platform_notifications_manager.h"
@ -99,16 +98,6 @@ namespace App {
void initMedia() { void initMedia() {
Ui::StartCachedCorners(); Ui::StartCachedCorners();
using Update = Window::Theme::BackgroundUpdate;
static auto subscription = Window::Theme::Background()->add_subscription([](const Update &update) {
if (update.paletteChanged()) {
if (const auto m = App::main()) { // multi good
m->updateScrollColors();
}
HistoryView::serviceColorsUpdated();
}
});
} }
void deinitMedia() { void deinitMedia() {

View file

@ -145,9 +145,7 @@ private:
}; };
class SetupChannelBox final class SetupChannelBox final : public Ui::BoxContent {
: public Ui::BoxContent
, private base::Subscriber {
public: public:
SetupChannelBox( SetupChannelBox(
QWidget*, QWidget*,
@ -244,9 +242,7 @@ private:
}; };
class RevokePublicLinkBox final class RevokePublicLinkBox final : public Ui::BoxContent {
: public Ui::BoxContent
, private base::Subscriber {
public: public:
RevokePublicLinkBox( RevokePublicLinkBox(
QWidget*, QWidget*,

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/background_preview_box.h" #include "boxes/background_preview_box.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/themes/window_theme.h"
#include "styles/style_overview.h" #include "styles/style_overview.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -55,9 +56,7 @@ QImage TakeMiddleSample(QImage original, QSize size) {
} // namespace } // namespace
class BackgroundBox::Inner final class BackgroundBox::Inner final : public Ui::RpWidget {
: public Ui::RpWidget
, private base::Subscriber {
public: public:
Inner( Inner(
QWidget *parent, QWidget *parent,
@ -203,16 +202,22 @@ BackgroundBox::Inner::Inner(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
update(); update();
}, lifetime()); }, lifetime());
style::PaletteChanged(
) | rpl::start_with_next([=] {
_check->invalidateCache();
}, lifetime());
using Update = Window::Theme::BackgroundUpdate; using Update = Window::Theme::BackgroundUpdate;
subscribe(Window::Theme::Background(), [=](const Update &update) { Window::Theme::Background()->updates(
if (update.paletteChanged()) { ) | rpl::start_with_next([=](const Update &update) {
_check->invalidateCache(); if (update.type == Update::Type::New) {
} else if (update.type == Update::Type::New) {
sortPapers(); sortPapers();
requestPapers(); requestPapers();
this->update(); this->update();
} }
}); }, lifetime());
setMouseTracking(true); setMouseTracking(true);
} }

View file

@ -99,12 +99,10 @@ private:
}; };
ServiceCheck::Generator::Generator() { ServiceCheck::Generator::Generator() {
*_lifetime.make_state<base::Subscription>() = Window::Theme::Background( style::PaletteChanged(
)->add_subscription([=](const Window::Theme::BackgroundUpdate &update) { ) | rpl::start_with_next([=] {
if (update.paletteChanged()) { invalidate();
invalidate(); }, _lifetime);
}
});
} }
auto ServiceCheck::Generator::framesForStyle( auto ServiceCheck::Generator::framesForStyle(

View file

@ -9,11 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "base/binary_guard.h" #include "base/binary_guard.h"
#include "window/themes/window_theme.h"
#include "history/admin_log/history_admin_log_item.h" #include "history/admin_log/history_admin_log_item.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
#include "data/data_wall_paper.h"
namespace Data { namespace Data {
class DocumentMedia; class DocumentMedia;
@ -29,8 +29,7 @@ class Checkbox;
class BackgroundPreviewBox class BackgroundPreviewBox
: public Ui::BoxContent : public Ui::BoxContent
, private HistoryView::SimpleElementDelegate , private HistoryView::SimpleElementDelegate {
, private base::Subscriber {
public: public:
BackgroundPreviewBox( BackgroundPreviewBox(
QWidget*, QWidget*,

View file

@ -141,7 +141,7 @@ public:
}; };
class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { class MaxInviteBox final : public Ui::BoxContent {
public: public:
MaxInviteBox(QWidget*, not_null<ChannelData*> channel); MaxInviteBox(QWidget*, not_null<ChannelData*> channel);

View file

@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "window/themes/window_theme.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
@ -738,11 +737,11 @@ PeerListContent::PeerListContent(
} }
}, lifetime()); }, lifetime());
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { style::PaletteChanged(
if (update.paletteChanged()) { ) | rpl::start_with_next([=] {
invalidatePixmapsCache(); invalidatePixmapsCache();
} }, lifetime());
});
_repaintByStatus.setCallback([this] { update(); }); _repaintByStatus.setCallback([this] { update(); });
} }

View file

@ -527,9 +527,7 @@ struct PeerListState {
QString searchQuery; QString searchQuery;
}; };
class PeerListContent class PeerListContent : public Ui::RpWidget {
: public Ui::RpWidget
, private base::Subscriber {
public: public:
PeerListContent( PeerListContent(
QWidget *parent, QWidget *parent,

View file

@ -73,7 +73,6 @@ private:
// with search + contacts search + global search. // with search + contacts search + global search.
class AddSpecialBoxController class AddSpecialBoxController
: public PeerListController : public PeerListController
, private base::Subscriber
, public base::has_weak_ptr { , public base::has_weak_ptr {
public: public:
using Role = ParticipantsBoxController::Role; using Role = ParticipantsBoxController::Role;
@ -146,9 +145,7 @@ protected:
}; };
// Finds chat/channel members, then contacts, then global search results. // Finds chat/channel members, then contacts, then global search results.
class AddSpecialBoxSearchController class AddSpecialBoxSearchController : public PeerListSearchController {
: public PeerListSearchController
, private base::Subscriber {
public: public:
using Role = ParticipantsBoxController::Role; using Role = ParticipantsBoxController::Role;

View file

@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/view/history_view_schedule_box.h" #include "history/view/history_view_schedule_box.h"
#include "window/themes/window_theme.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "boxes/peer_list_box.h" #include "boxes/peer_list_box.h"
#include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/emoji_suggestions_widget.h"
@ -42,7 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
class ShareBox::Inner final : public Ui::RpWidget, private base::Subscriber { class ShareBox::Inner final : public Ui::RpWidget {
public: public:
Inner(QWidget *parent, const Descriptor &descriptor); Inner(QWidget *parent, const Descriptor &descriptor);
@ -598,11 +597,10 @@ ShareBox::Inner::Inner(QWidget *parent, const Descriptor &descriptor)
update(); update();
}, lifetime()); }, lifetime());
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { style::PaletteChanged(
if (update.paletteChanged()) { ) | rpl::start_with_next([=] {
invalidateCache(); invalidateCache();
} }, lifetime());
});
} }
void ShareBox::Inner::invalidateCache() { void ShareBox::Inner::invalidateCache() {

View file

@ -55,7 +55,7 @@ using SetFlag = Data::StickersSetFlag;
} // namespace } // namespace
class StickerSetBox::Inner : public Ui::RpWidget, private base::Subscriber { class StickerSetBox::Inner final : public Ui::RpWidget {
public: public:
Inner( Inner(
QWidget *parent, QWidget *parent,

View file

@ -49,7 +49,7 @@ namespace Stickers {
class Set; class Set;
} // namespace Stickers } // namespace Stickers
class StickersBox final : public Ui::BoxContent, private base::Subscriber { class StickersBox final : public Ui::BoxContent {
public: public:
enum class Section { enum class Section {
Installed, Installed,

View file

@ -16,7 +16,7 @@ class SessionController;
namespace Calls { namespace Calls {
class BoxController : public PeerListController, private base::Subscriber { class BoxController : public PeerListController {
public: public:
explicit BoxController(not_null<Window::SessionController*> window); explicit BoxController(not_null<Window::SessionController*> window);

View file

@ -43,7 +43,7 @@ class GroupCall;
class Panel; class Panel;
struct DhConfig; struct DhConfig;
class Instance : private base::Subscriber, public base::has_weak_ptr { class Instance final : public base::has_weak_ptr {
public: public:
Instance(); Instance();
~Instance(); ~Instance();

View file

@ -44,10 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
class FieldAutocomplete::Inner final class FieldAutocomplete::Inner final : public Ui::RpWidget {
: public Ui::RpWidget
, private base::Subscriber {
public: public:
struct ScrollTo { struct ScrollTo {
int top; int top;

View file

@ -43,9 +43,7 @@ namespace ChatHelpers {
struct StickerIcon; struct StickerIcon;
class StickersListWidget class StickersListWidget final : public TabbedSelector::Inner {
: public TabbedSelector::Inner
, private base::Subscriber {
public: public:
StickersListWidget( StickersListWidget(
QWidget *parent, QWidget *parent,

View file

@ -51,7 +51,7 @@ class EmojiListWidget;
class StickersListWidget; class StickersListWidget;
class GifsListWidget; class GifsListWidget;
class TabbedSelector : public Ui::RpWidget, private base::Subscriber { class TabbedSelector : public Ui::RpWidget {
public: public:
struct FileChosen { struct FileChosen {
not_null<DocumentData*> document; not_null<DocumentData*> document;

View file

@ -143,7 +143,7 @@ std::map<int, const char*> BetaLogs() {
"- Use Direct3D 9 backend in ANGLE by default (Windows).\n" "- Use Direct3D 9 backend in ANGLE by default (Windows).\n"
"- Fix \"Show in Finder\" not focusing the Finder window (macOS).\n" "- Fix \"Show in Finder\" not focusing the Finder window (macOS).\n"
"- Use GTK from a child process (Linux).\n" "- Use GTK from a child process (Linux).\n"
}, },
}; };

View file

@ -18,7 +18,7 @@ namespace Core {
[[nodiscard]] QString FormatVersionDisplay(int version); [[nodiscard]] QString FormatVersionDisplay(int version);
[[nodiscard]] QString FormatVersionPrecise(int version); [[nodiscard]] QString FormatVersionPrecise(int version);
class Changelogs : public base::has_weak_ptr, private base::Subscriber { class Changelogs final : public base::has_weak_ptr {
public: public:
Changelogs(not_null<Main::Session*> session, int oldVersion); Changelogs(not_null<Main::Session*> session, int oldVersion);

View file

@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/send_files_box.h" #include "boxes/send_files_box.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "storage/serialize_common.h" #include "storage/serialize_common.h"
#include "window/themes/window_theme.h"
#include "window/section_widget.h" #include "window/section_widget.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "webrtc/webrtc_create_adm.h" #include "webrtc/webrtc_create_adm.h"

View file

@ -63,8 +63,7 @@ void CloudThemes::setupReload() {
if (needReload()) { if (needReload()) {
_reloadCurrentTimer.callOnce(kFirstReloadTimeout); _reloadCurrentTimer.callOnce(kFirstReloadTimeout);
} }
base::ObservableViewer( Background()->updates(
*Background()
) | rpl::filter([](const BackgroundUpdate &update) { ) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme); return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}) | rpl::map([=] { }) | rpl::map([=] {

View file

@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/audio/media_audio.h" #include "media/audio/media_audio.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "passport/passport_form_controller.h" #include "passport/passport_form_controller.h"
#include "window/themes/window_theme.h"
#include "lang/lang_keys.h" // tr::lng_deleted(tr::now) in user name #include "lang/lang_keys.h" // tr::lng_deleted(tr::now) in user name
#include "data/stickers/data_stickers.h" #include "data/stickers/data_stickers.h"
#include "data/data_changes.h" #include "data/data_changes.h"
@ -48,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_web_page.h" #include "data/data_web_page.h"
#include "data/data_wall_paper.h"
#include "data/data_game.h" #include "data/data_game.h"
#include "data/data_poll.h" #include "data/data_poll.h"
#include "data/data_chat_filters.h" #include "data/data_chat_filters.h"

View file

@ -38,7 +38,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h" #include "mainwidget.h"
#include "storage/storage_account.h" #include "storage/storage_account.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "window/themes/window_theme.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "window/notifications_manager.h" #include "window/notifications_manager.h"

View file

@ -62,7 +62,7 @@ enum class WidgetState {
Filtered, Filtered,
}; };
class InnerWidget final : public Ui::RpWidget, private base::Subscriber { class InnerWidget final : public Ui::RpWidget {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -45,7 +45,10 @@ inline bool operator!=(const FilterValue &a, const FilterValue &b) {
class Widget final : public Window::SectionWidget { class Widget final : public Window::SectionWidget {
public: public:
Widget(QWidget *parent, not_null<Window::SessionController*> controller, not_null<ChannelData*> channel); Widget(
QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<ChannelData*> channel);
not_null<ChannelData*> channel() const; not_null<ChannelData*> channel() const;
Dialogs::RowDescriptor activeChat() const override; Dialogs::RowDescriptor activeChat() const override;

View file

@ -111,7 +111,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/unread_badge.h" #include "ui/unread_badge.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "window/themes/window_theme.h"
#include "window/notifications_manager.h" #include "window/notifications_manager.h"
#include "window/window_adaptive.h" #include "window/window_adaptive.h"
#include "window/window_controller.h" #include "window/window_controller.h"
@ -304,7 +303,10 @@ HistoryWidget::HistoryWidget(
_scroll->hide(); _scroll->hide();
_kbScroll->hide(); _kbScroll->hide();
updateScrollColors(); style::PaletteChanged(
) | rpl::start_with_next([=] {
_scroll->updateBars();
}, lifetime());
_historyDown->installEventFilter(this); _historyDown->installEventFilter(this);
_unreadMentions->installEventFilter(this); _unreadMentions->installEventFilter(this);
@ -4698,10 +4700,6 @@ void HistoryWidget::itemEdited(not_null<HistoryItem*> item) {
} }
} }
void HistoryWidget::updateScrollColors() {
_scroll->updateBars();
}
MsgId HistoryWidget::replyToId() const { MsgId HistoryWidget::replyToId() const {
return _replyToId ? _replyToId : (_kbReplyTo ? _kbReplyTo->id : 0); return _replyToId ? _replyToId : (_kbReplyTo ? _kbReplyTo->id : 0);
} }

View file

@ -188,8 +188,6 @@ public:
MessageIdsList getSelectedItems() const; MessageIdsList getSelectedItems() const;
void itemEdited(not_null<HistoryItem*> item); void itemEdited(not_null<HistoryItem*> item);
void updateScrollColors();
void replyToMessage(FullMsgId itemId); void replyToMessage(FullMsgId itemId);
void replyToMessage(not_null<HistoryItem*> item); void replyToMessage(not_null<HistoryItem*> item);
void editMessage(FullMsgId itemId); void editMessage(FullMsgId itemId);

View file

@ -43,6 +43,15 @@ enum CornerHorizontalSide {
class ServiceMessageStyleData : public Data::AbstractStructure { class ServiceMessageStyleData : public Data::AbstractStructure {
public: public:
ServiceMessageStyleData() {
style::PaletteChanged(
) | rpl::start_with_next([=] {
for (auto &corner : corners) {
corner = QPixmap();
}
}, _lifetime);
}
// circle[CircleMask value] // circle[CircleMask value]
QImage circle[2]; QImage circle[2];
@ -50,6 +59,10 @@ public:
QPixmap corners[8]; QPixmap corners[8];
base::flat_map<std::pair<int, uint32>, QPixmap> overridenCorners; base::flat_map<std::pair<int, uint32>, QPixmap> overridenCorners;
private:
rpl::lifetime _lifetime;
}; };
Data::GlobalStructurePointer<ServiceMessageStyleData> serviceMessageStyle; Data::GlobalStructurePointer<ServiceMessageStyleData> serviceMessageStyle;
@ -420,14 +433,6 @@ QVector<int> ServiceMessagePainter::countLineWidths(const Ui::Text::String &text
return lineWidths; return lineWidths;
} }
void serviceColorsUpdated() {
if (serviceMessageStyle) {
for (auto &corner : serviceMessageStyle->corners) {
corner = QPixmap();
}
}
}
Service::Service( Service::Service(
not_null<ElementDelegate*> delegate, not_null<ElementDelegate*> delegate,
not_null<HistoryService*> data, not_null<HistoryService*> data,

View file

@ -126,6 +126,4 @@ private:
}; };
void serviceColorsUpdated();
} // namespace HistoryView } // namespace HistoryView

View file

@ -35,7 +35,7 @@ namespace HistoryView {
class SendActionPainter; class SendActionPainter;
class TopBarWidget : public Ui::RpWidget, private base::Subscriber { class TopBarWidget final : public Ui::RpWidget {
public: public:
struct SelectedState { struct SelectedState {
bool textSelected = false; bool textSelected = false;

View file

@ -16,11 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document_media.h" #include "data/data_document_media.h"
#include "data/data_file_click_handler.h" #include "data/data_file_click_handler.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_wall_paper.h"
#include "base/qthelp_url.h" #include "base/qthelp_url.h"
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "window/themes/window_theme.h"
#include "layout.h" // FullSelection #include "layout.h" // FullSelection
#include "styles/style_chat.h" #include "styles/style_chat.h"

View file

@ -27,7 +27,7 @@ namespace {
constexpr auto kCommonGroupsPerPage = 40; constexpr auto kCommonGroupsPerPage = 40;
constexpr auto kCommonGroupsSearchAfter = 20; constexpr auto kCommonGroupsSearchAfter = 20;
class ListController : public PeerListController , private base::Subscriber { class ListController final : public PeerListController {
public: public:
ListController( ListController(
not_null<Controller*> controller, not_null<Controller*> controller,

View file

@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "window/themes/window_theme.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_peer_menu.h" #include "window/window_peer_menu.h"
#include "ui/widgets/popup_menu.h" #include "ui/widgets/popup_menu.h"
@ -626,12 +625,9 @@ Main::Session &ListWidget::session() const {
void ListWidget::start() { void ListWidget::start() {
_controller->setSearchEnabledByContent(false); _controller->setSearchEnabledByContent(false);
ObservableViewer( style::PaletteChanged(
*Window::Theme::Background() ) | rpl::start_with_next([=] {
) | rpl::start_with_next([this](const auto &update) { invalidatePaletteCache();
if (update.paletteChanged()) {
invalidatePaletteCache();
}
}, lifetime()); }, lifetime());
session().downloaderTaskFinished( session().downloaderTaskFinished(

View file

@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_chat_filters.h" #include "data/data_chat_filters.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "window/themes/window_theme.h"
#include "styles/style_intro.h" #include "styles/style_intro.h"
#include "styles/style_window.h" #include "styles/style_window.h"
@ -75,11 +74,8 @@ Step::Step(
? st::introCoverDescription ? st::introCoverDescription
: st::introDescription)) { : st::introDescription)) {
hide(); hide();
base::ObservableViewer( style::PaletteChanged(
*Window::Theme::Background() ) | rpl::start_with_next([=] {
) | rpl::filter([](const Window::Theme::BackgroundUpdate &update) {
return update.paletteChanged();
}) | rpl::start_with_next([=] {
if (!_coverMask.isNull()) { if (!_coverMask.isNull()) {
_coverMask = QPixmap(); _coverMask = QPixmap();
prepareCoverMask(); prepareCoverMask();

View file

@ -28,8 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/stickers/data_stickers.h" #include "data/stickers/data_stickers.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_lock_widgets.h" #include "window/window_lock_widgets.h"
#include "window/themes/window_theme.h"
//#include "platform/platform_specific.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "calls/calls_instance.h" #include "calls/calls_instance.h"
#include "support/support_helper.h" #include "support/support_helper.h"

View file

@ -59,9 +59,7 @@ class Account;
class Domain; class Domain;
class SessionSettings; class SessionSettings;
class Session final class Session final : public base::has_weak_ptr {
: public base::has_weak_ptr
, private base::Subscriber {
public: public:
Session( Session(
not_null<Account*> account, not_null<Account*> account,

View file

@ -242,7 +242,6 @@ MainWidget::MainWidget(
, _cacheBackgroundTimer([=] { cacheBackground(); }) , _cacheBackgroundTimer([=] { cacheBackground(); })
, _viewsIncrementTimer([=] { viewsIncrement(); }) , _viewsIncrementTimer([=] { viewsIncrement(); })
, _changelogs(Core::Changelogs::Create(&controller->session())) { , _changelogs(Core::Changelogs::Create(&controller->session())) {
updateScrollColors();
setupConnectingWidget(); setupConnectingWidget();
connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
@ -347,11 +346,13 @@ MainWidget::MainWidget(
QCoreApplication::instance()->installEventFilter(this); QCoreApplication::instance()->installEventFilter(this);
using Update = Window::Theme::BackgroundUpdate; using Update = Window::Theme::BackgroundUpdate;
subscribe(Window::Theme::Background(), [this](const Update &update) { Window::Theme::Background()->updates(
if (update.type == Update::Type::New || update.type == Update::Type::Changed) { ) | rpl::start_with_next([=](const Update &update) {
if (update.type == Update::Type::New
|| update.type == Update::Type::Changed) {
clearCachedBackground(); clearCachedBackground();
} }
}); }, lifetime());
subscribe(Media::Player::instance()->playerWidgetOver(), [this](bool over) { subscribe(Media::Player::instance()->playerWidgetOver(), [this](bool over) {
if (over) { if (over) {
@ -1173,10 +1174,6 @@ QPixmap MainWidget::cachedBackground(const QRect &forRect, int &x, int &y) {
return QPixmap(); return QPixmap();
} }
void MainWidget::updateScrollColors() {
_history->updateScrollColors();
}
void MainWidget::setChatBackground( void MainWidget::setChatBackground(
const Data::WallPaper &background, const Data::WallPaper &background,
QImage &&image) { QImage &&image) {
@ -1197,8 +1194,7 @@ void MainWidget::setChatBackground(
checkChatBackground(); checkChatBackground();
const auto tile = Data::IsLegacy1DefaultWallPaper(background); const auto tile = Data::IsLegacy1DefaultWallPaper(background);
using Update = Window::Theme::BackgroundUpdate; Window::Theme::Background()->downloadingStarted(tile);
Window::Theme::Background()->notify(Update(Update::Type::Start, tile));
} }
bool MainWidget::isReadyChatBackground( bool MainWidget::isReadyChatBackground(

View file

@ -190,7 +190,6 @@ public:
void searchMessages(const QString &query, Dialogs::Key inChat); void searchMessages(const QString &query, Dialogs::Key inChat);
QPixmap cachedBackground(const QRect &forRect, int &x, int &y); QPixmap cachedBackground(const QRect &forRect, int &x, int &y);
void updateScrollColors();
void setChatBackground( void setChatBackground(
const Data::WallPaper &background, const Data::WallPaper &background,

View file

@ -98,9 +98,12 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { using Window::Theme::BackgroundUpdate;
Window::Theme::Background()->updates(
) | rpl::start_with_next([=](const BackgroundUpdate &data) {
themeUpdated(data); themeUpdated(data);
}); }, lifetime());
Core::App().passcodeLockChanges( Core::App().passcodeLockChanges(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
updateGlobalMenu(); updateGlobalMenu();
@ -571,7 +574,7 @@ void MainWindow::themeUpdated(const Window::Theme::BackgroundUpdate &data) {
using Type = Window::Theme::BackgroundUpdate::Type; using Type = Window::Theme::BackgroundUpdate::Type;
// We delay animating theme warning because we want all other // We delay animating theme warning because we want all other
// subscribers to receive paltte changed notification before any // subscribers to receive palette changed notification before any
// animations (that include pixmap caches with old palette values). // animations (that include pixmap caches with old palette values).
if (data.type == Type::TestingTheme) { if (data.type == Type::TestingTheme) {
if (!_testingThemeWarning) { if (!_testingThemeWarning) {

View file

@ -25,7 +25,7 @@ class SessionController;
namespace Media { namespace Media {
namespace Player { namespace Player {
class VolumeController : public Ui::RpWidget, private base::Subscriber { class VolumeController final : public Ui::RpWidget {
public: public:
VolumeController( VolumeController(
QWidget *parent, QWidget *parent,

View file

@ -15,7 +15,7 @@ class Session;
namespace MTP { namespace MTP {
class WeakInstance : private QObject, private base::Subscriber { class WeakInstance final : private QObject {
public: public:
explicit WeakInstance(base::weak_ptr<Main::Session> session); explicit WeakInstance(base::weak_ptr<Main::Session> session);

View file

@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/notifications_manager_default.h" #include "window/notifications_manager_default.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "window/themes/window_theme.h"
#include "platform/mac/touchbar/mac_touchbar_manager.h" #include "platform/mac/touchbar/mac_touchbar_manager.h"
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "platform/platform_notifications_manager.h" #include "platform/platform_notifications_manager.h"
@ -451,11 +450,10 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
_hideAfterFullScreenTimer.setCallback([this] { hideAndDeactivate(); }); _hideAfterFullScreenTimer.setCallback([this] { hideAndDeactivate(); });
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { style::PaletteChanged(
if (data.paletteChanged()) { ) | rpl::start_with_next([=] {
_private->updateNativeTitle(); _private->updateNativeTitle();
} }, lifetime());
});
} }
void MainWindow::closeWithoutDestroy() { void MainWindow::closeWithoutDestroy() {

View file

@ -30,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "window/themes/window_theme.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
@ -718,11 +717,8 @@ TimeId CalculateOnlineTill(not_null<PeerData*> peer) {
const auto localGuard = _lifetime.make_state<base::has_weak_ptr>(); const auto localGuard = _lifetime.make_state<base::has_weak_ptr>();
base::ObservableViewer( style::PaletteChanged(
*Window::Theme::Background() ) | rpl::start_with_next([=] {
) | rpl::filter([](const Window::Theme::BackgroundUpdate &update) {
return update.paletteChanged();
}) | rpl::start_with_next([=] {
crl::on_main(&(*localGuard), [=] { crl::on_main(&(*localGuard), [=] {
updateOnlineColor(); updateOnlineColor();
if (const auto f = _session->data().folderLoaded(ArchiveId)) { if (const auto f = _session->data().folderLoaded(ArchiveId)) {

View file

@ -122,11 +122,12 @@ MainWindow::MainWindow(not_null<Window::Controller*> controller)
if (!kTaskbarCreatedMsgId) { if (!kTaskbarCreatedMsgId) {
kTaskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); kTaskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated");
} }
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { style::PaletteChanged(
if (_shadow && update.paletteChanged()) { ) | rpl::start_with_next([=] {
if (_shadow) {
_shadow->setColor(st::windowShadowFg->c); _shadow->setColor(st::windowShadowFg->c);
} }
}); }, lifetime());
setupNativeWindowFrame(); setupNativeWindowFrame();
using namespace rpl::mappers; using namespace rpl::mappers;
@ -145,8 +146,7 @@ void MainWindow::setupNativeWindowFrame() {
); );
using BackgroundUpdate = Window::Theme::BackgroundUpdate; using BackgroundUpdate = Window::Theme::BackgroundUpdate;
auto paletteChanges = base::ObservableViewer( auto themeChanges = Window::Theme::Background()->updates(
*Window::Theme::Background()
) | rpl::filter([=](const BackgroundUpdate &update) { ) | rpl::filter([=](const BackgroundUpdate &update) {
return update.type == BackgroundUpdate::Type::ApplyingTheme; return update.type == BackgroundUpdate::Type::ApplyingTheme;
}) | rpl::to_empty; }) | rpl::to_empty;
@ -154,7 +154,7 @@ void MainWindow::setupNativeWindowFrame() {
auto nightMode = rpl::single( auto nightMode = rpl::single(
rpl::empty_value() rpl::empty_value()
) | rpl::then( ) | rpl::then(
std::move(paletteChanges) std::move(themeChanges)
) | rpl::map([=] { ) | rpl::map([=] {
return Window::Theme::IsNightMode(); return Window::Theme::IsNightMode();
}) | rpl::distinct_until_changed(); }) | rpl::distinct_until_changed();

View file

@ -15,7 +15,7 @@ class Session;
namespace Profile { namespace Profile {
class BackButton final : public Ui::AbstractButton, private base::Subscriber { class BackButton final : public Ui::AbstractButton {
public: public:
BackButton( BackButton(
QWidget *parent, QWidget *parent,

View file

@ -14,7 +14,7 @@ namespace Profile {
class SectionMemento; class SectionMemento;
class BlockWidget : public Ui::RpWidget, protected base::Subscriber { class BlockWidget : public Ui::RpWidget {
public: public:
BlockWidget(QWidget *parent, PeerData *peer, const QString &title); BlockWidget(QWidget *parent, PeerData *peer, const QString &title);

View file

@ -424,8 +424,7 @@ BackgroundRow::BackgroundRow(
}); });
using Update = const Window::Theme::BackgroundUpdate; using Update = const Window::Theme::BackgroundUpdate;
base::ObservableViewer( Window::Theme::Background()->updates(
*Window::Theme::Background()
) | rpl::filter([](const Update &update) { ) | rpl::filter([](const Update &update) {
return (update.type == Update::Type::New return (update.type == Update::Type::New
|| update.type == Update::Type::Start || update.type == Update::Type::Start
@ -958,8 +957,7 @@ void SetupChatBackground(
}, tile->lifetime()); }, tile->lifetime());
using Update = const Window::Theme::BackgroundUpdate; using Update = const Window::Theme::BackgroundUpdate;
base::ObservableViewer( Window::Theme::Background()->updates(
*Window::Theme::Background()
) | rpl::filter([](const Update &update) { ) | rpl::filter([](const Update &update) {
return (update.type == Update::Type::Changed); return (update.type == Update::Type::Changed);
}) | rpl::map([] { }) | rpl::map([] {
@ -1089,8 +1087,7 @@ void SetupDefaultThemes(
refreshColorizer(scheme.type); refreshColorizer(scheme.type);
} }
base::ObservableViewer( Background()->updates(
*Background()
) | rpl::filter([](const BackgroundUpdate &update) { ) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme); return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}) | rpl::map([=] { }) | rpl::map([=] {
@ -1254,9 +1251,9 @@ void SetupCloudThemes(
editWrap->toggleOn(rpl::single(BackgroundUpdate( editWrap->toggleOn(rpl::single(BackgroundUpdate(
BackgroundUpdate::Type::ApplyingTheme, BackgroundUpdate::Type::ApplyingTheme,
Background()->tile() Background()->tile()
)) | rpl::then(base::ObservableViewer( )) | rpl::then(
*Background() Background()->updates()
)) | rpl::filter([](const BackgroundUpdate &update) { ) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme); return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}) | rpl::map([=] { }) | rpl::map([=] {
const auto userId = controller->session().userId(); const auto userId = controller->session().userId();

View file

@ -47,9 +47,7 @@ namespace {
constexpr auto kBlockedPerPage = 40; constexpr auto kBlockedPerPage = 40;
class BlockPeerBoxController class BlockPeerBoxController final : public ChatsListBoxController {
: public ChatsListBoxController
, private base::Subscriber {
public: public:
explicit BlockPeerBoxController(not_null<Main::Session*> session); explicit BlockPeerBoxController(not_null<Main::Session*> session);

View file

@ -18,9 +18,7 @@ class SessionController;
namespace Settings { namespace Settings {
class BlockedBoxController class BlockedBoxController : public PeerListController {
: public PeerListController
, private base::Subscriber {
public: public:
explicit BlockedBoxController( explicit BlockedBoxController(
not_null<Window::SessionController*> window); not_null<Window::SessionController*> window);

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "ui/effects/round_checkbox.h" #include "ui/effects/round_checkbox.h"
#include "window/themes/window_theme.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
@ -22,9 +21,12 @@ class CheckCaches : public QObject {
public: public:
CheckCaches(QObject *parent) : QObject(parent) { CheckCaches(QObject *parent) : QObject(parent) {
Expects(parent != nullptr); Expects(parent != nullptr);
}
void clear(); style::PaletteChanged(
) | rpl::start_with_next([=] {
_data.clear();
}, _lifetime);
}
QPixmap frame( QPixmap frame(
const style::RoundCheckbox *st, const style::RoundCheckbox *st,
@ -54,6 +56,7 @@ private:
float64 progress); float64 progress);
std::map<const style::RoundCheckbox *, Frames> _data; std::map<const style::RoundCheckbox *, Frames> _data;
rpl::lifetime _lifetime;
}; };
@ -134,10 +137,6 @@ QRect WideDestRect(
return QRect(iconLeft, iconTop, iconSize, iconSize); return QRect(iconLeft, iconTop, iconSize, iconSize);
} }
void CheckCaches::clear() {
_data.clear();
}
int CheckCaches::countFramesCount(const style::RoundCheckbox *st) { int CheckCaches::countFramesCount(const style::RoundCheckbox *st) {
return (st->duration / AnimationTimerDelta) + 1; return (st->duration / AnimationTimerDelta) + 1;
} }
@ -248,13 +247,6 @@ CheckCaches *FrameCaches() {
} }
const auto result = new CheckCaches(QCoreApplication::instance()); const auto result = new CheckCaches(QCoreApplication::instance());
Instance = result; Instance = result;
const auto subscription = Ui::CreateChild<base::Subscription>(result);
*subscription = Window::Theme::Background()->add_subscription([=](
const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged()) {
FrameCaches()->clear();
}
});
return result; return result;
} }

View file

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "ui/platform/ui_platform_utility.h" #include "ui/platform/ui_platform_utility.h"
#include "history/history.h" #include "history/history.h"
#include "window/themes/window_theme.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_lock_widgets.h" #include "window/window_lock_widgets.h"
#include "window/window_outdated_bar.h" #include "window/window_outdated_bar.h"
@ -165,12 +164,10 @@ MainWindow::MainWindow(not_null<Controller*> controller)
, _outdated(CreateOutdatedBar(this)) , _outdated(CreateOutdatedBar(this))
, _body(this) , _body(this)
, _titleText(qsl("Telegram")) { , _titleText(qsl("Telegram")) {
subscribe(Theme::Background(), [=]( style::PaletteChanged(
const Theme::BackgroundUpdate &data) { ) | rpl::start_with_next([=] {
if (data.paletteChanged()) { updatePalette();
updatePalette(); }, lifetime());
}
});
Core::App().unreadBadgeChanges( Core::App().unreadBadgeChanges(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {

View file

@ -37,7 +37,7 @@ QImage LoadLogoNoMargin();
QIcon CreateIcon(Main::Session *session = nullptr); QIcon CreateIcon(Main::Session *session = nullptr);
void ConvertIconToBlack(QImage &image); void ConvertIconToBlack(QImage &image);
class MainWindow : public Ui::RpWidget, protected base::Subscriber { class MainWindow : public Ui::RpWidget {
public: public:
explicit MainWindow(not_null<Controller*> controller); explicit MainWindow(not_null<Controller*> controller);
virtual ~MainWindow(); virtual ~MainWindow();

View file

@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "dialogs/dialogs_layout.h" #include "dialogs/dialogs_layout.h"
#include "window/themes/window_theme.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "storage/file_download.h" #include "storage/file_download.h"
#include "main/main_session.h" #include "main/main_session.h"
@ -641,18 +640,17 @@ Notification::Notification(
prepareActionsCache(); prepareActionsCache();
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { style::PaletteChanged(
if (data.paletteChanged()) { ) | rpl::start_with_next([=] {
updateNotifyDisplay(); updateNotifyDisplay();
if (!_buttonsCache.isNull()) { if (!_buttonsCache.isNull()) {
prepareActionsCache(); prepareActionsCache();
}
update();
if (_background) {
_background->update();
}
} }
}); update();
if (_background) {
_background->update();
}
}, lifetime());
show(); show();
} }
@ -1077,11 +1075,10 @@ HideAllButton::HideAllButton(
hide(); hide();
createWinId(); createWinId();
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) { style::PaletteChanged(
if (data.paletteChanged()) { ) | rpl::start_with_next([=] {
update(); update();
} }, lifetime());
});
show(); show();
} }

View file

@ -132,7 +132,7 @@ private:
namespace internal { namespace internal {
class Widget : public Ui::RpWidget, protected base::Subscriber { class Widget : public Ui::RpWidget {
public: public:
enum class Direction { enum class Direction {
Up, Up,

View file

@ -551,11 +551,12 @@ void ChatBackground::initialRead() {
void ChatBackground::start() { void ChatBackground::start() {
saveAdjustableColors(); saveAdjustableColors();
subscribe(this, [=](const BackgroundUpdate &update) { _updates.events(
) | rpl::start_with_next([=](const BackgroundUpdate &update) {
if (update.paletteChanged()) { if (update.paletteChanged()) {
style::NotifyPaletteChanged(); style::NotifyPaletteChanged();
} }
}); }, _lifetime);
initialRead(); initialRead();
@ -620,7 +621,7 @@ void ChatBackground::checkUploadWallPaper() {
if (const auto paper = Data::WallPaper::Create(_session, result)) { if (const auto paper = Data::WallPaper::Create(_session, result)) {
setPaper(*paper); setPaper(*paper);
writeNewBackgroundSettings(); writeNewBackgroundSettings();
notify(BackgroundUpdate(BackgroundUpdate::Type::New, tile())); _updates.fire({ BackgroundUpdate::Type::New, tile() });
} }
}).send(); }).send();
}); });
@ -705,10 +706,10 @@ void ChatBackground::set(const Data::WallPaper &paper, QImage image) {
&& !_pixmap.isNull() && !_pixmap.isNull()
&& !_pixmapForTiled.isNull())); && !_pixmapForTiled.isNull()));
notify(BackgroundUpdate(BackgroundUpdate::Type::New, tile())); _updates.fire({ BackgroundUpdate::Type::New, tile() }); // delayed?
if (needResetAdjustable) { if (needResetAdjustable) {
notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() });
notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() });
} }
checkUploadWallPaper(); checkUploadWallPaper();
} }
@ -883,7 +884,7 @@ void ChatBackground::setTile(bool tile) {
&& !Data::details::IsTestingDefaultWallPaper(_paper)) { && !Data::details::IsTestingDefaultWallPaper(_paper)) {
Local::writeSettings(); Local::writeSettings();
} }
notify(BackgroundUpdate(BackgroundUpdate::Type::Changed, tile)); _updates.fire({ BackgroundUpdate::Type::Changed, tile }); // delayed?
} }
} }
@ -927,8 +928,8 @@ void ChatBackground::reset() {
} else { } else {
set(Data::ThemeWallPaper()); set(Data::ThemeWallPaper());
restoreAdjustableColors(); restoreAdjustableColors();
notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() });
notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() });
} }
writeNewBackgroundSettings(); writeNewBackgroundSettings();
} }
@ -990,7 +991,7 @@ void ChatBackground::setTestingTheme(Instance &&theme) {
// Apply current background image so that service bg colors are recounted. // Apply current background image so that service bg colors are recounted.
set(_paper, std::move(_original)); set(_paper, std::move(_original));
} }
notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() });
} }
void ChatBackground::setTestingDefaultTheme() { void ChatBackground::setTestingDefaultTheme() {
@ -1000,7 +1001,7 @@ void ChatBackground::setTestingDefaultTheme() {
saveForRevert(); saveForRevert();
set(Data::details::TestingDefaultWallPaper()); set(Data::details::TestingDefaultWallPaper());
setTile(false); setTile(false);
notify(BackgroundUpdate(BackgroundUpdate::Type::TestingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::TestingTheme, tile() });
} }
void ChatBackground::keepApplied(const Object &object, bool write) { void ChatBackground::keepApplied(const Object &object, bool write) {
@ -1027,7 +1028,7 @@ void ChatBackground::keepApplied(const Object &object, bool write) {
writeNewBackgroundSettings(); writeNewBackgroundSettings();
} }
} }
notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::ApplyingTheme, tile() });
} }
bool ChatBackground::isNonDefaultThemeOrBackground() { bool ChatBackground::isNonDefaultThemeOrBackground() {
@ -1068,7 +1069,15 @@ void ChatBackground::revert() {
// Apply current background image so that service bg colors are recounted. // Apply current background image so that service bg colors are recounted.
set(_paper, std::move(_original)); set(_paper, std::move(_original));
} }
notify(BackgroundUpdate(BackgroundUpdate::Type::RevertingTheme, tile()), true); _updates.fire({ BackgroundUpdate::Type::RevertingTheme, tile() });
}
void ChatBackground::appliedEditedPalette() {
_updates.fire({ BackgroundUpdate::Type::ApplyingEdit, tile() });
}
void ChatBackground::downloadingStarted(bool tile) {
_updates.fire({ BackgroundUpdate::Type::Start, tile });
} }
void ChatBackground::setNightModeValue(bool nightMode) { void ChatBackground::setNightModeValue(bool nightMode) {
@ -1225,7 +1234,7 @@ bool ApplyEditedPalette(const QByteArray &content) {
return false; return false;
} }
style::main_palette::apply(out.palette); style::main_palette::apply(out.palette);
Background()->notify(BackgroundUpdate(BackgroundUpdate::Type::ApplyingEdit, Background()->tile()), true); Background()->appliedEditedPalette();
return true; return true;
} }

View file

@ -131,12 +131,14 @@ enum class ClearEditing {
KeepChanges, KeepChanges,
}; };
class ChatBackground class ChatBackground final {
: public base::Observable<BackgroundUpdate>
, private base::Subscriber {
public: public:
ChatBackground(); ChatBackground();
[[nodiscard]] rpl::producer<BackgroundUpdate> updates() const {
return _updates.events();
}
void start(); void start();
// This method is allowed to (and should) be called before start(). // This method is allowed to (and should) be called before start().
@ -159,6 +161,9 @@ public:
void setTestingDefaultTheme(); void setTestingDefaultTheme();
void revert(); void revert();
void appliedEditedPalette();
void downloadingStarted(bool tile);
[[nodiscard]] Data::WallPaper paper() const { [[nodiscard]] Data::WallPaper paper() const {
return _paper; return _paper;
} }
@ -227,6 +232,7 @@ private:
friend bool IsNonDefaultBackground(); friend bool IsNonDefaultBackground();
Main::Session *_session = nullptr; Main::Session *_session = nullptr;
rpl::event_stream<BackgroundUpdate> _updates;
Data::WallPaper _paper = Data::details::UninitializedWallPaper(); Data::WallPaper _paper = Data::details::UninitializedWallPaper();
std::optional<QColor> _paperColor; std::optional<QColor> _paperColor;
QImage _original; QImage _original;
@ -259,7 +265,7 @@ private:
}; };
ChatBackground *Background(); [[nodiscard]] ChatBackground *Background();
void ComputeBackgroundRects(QRect wholeFill, QSize imageSize, QRect &to, QRect &from); void ComputeBackgroundRects(QRect wholeFill, QSize imageSize, QRect &to, QRect &from);

View file

@ -197,7 +197,7 @@ QString bytesToUtf8(QLatin1String bytes) {
} // namespace } // namespace
class Editor::Inner : public TWidget, private base::Subscriber { class Editor::Inner : public Ui::RpWidget, private base::Subscriber {
public: public:
Inner(QWidget *parent, const QString &path); Inner(QWidget *parent, const QString &path);
@ -387,7 +387,8 @@ QByteArray StripCloudTextFields(const QByteArray &text) {
return (start > 0) ? text.mid(start) : text; return (start > 0) ? text.mid(start) : text;
} }
Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent) Editor::Inner::Inner(QWidget *parent, const QString &path)
: RpWidget(parent)
, _path(path) , _path(path)
, _existingRows(this, EditorBlock::Type::Existing, &_context) , _existingRows(this, EditorBlock::Type::Existing, &_context)
, _newRows(this, EditorBlock::Type::New, &_context) { , _newRows(this, EditorBlock::Type::New, &_context) {
@ -410,7 +411,8 @@ Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent)
_scrollCallback(top, top + data.height); _scrollCallback(top, top + data.height);
} }
}); });
subscribe(Background(), [this](const BackgroundUpdate &update) { Background()->updates(
) | rpl::start_with_next([=](const BackgroundUpdate &update) {
if (_applyingUpdate || !Background()->editingTheme()) { if (_applyingUpdate || !Background()->editingTheme()) {
return; return;
} }
@ -422,7 +424,7 @@ Editor::Inner::Inner(QWidget *parent, const QString &path) : TWidget(parent)
tr::lng_theme_editor_cant_change_theme(tr::now))); tr::lng_theme_editor_cant_change_theme(tr::now)));
}); });
} }
}); }, lifetime());
} }
void Editor::Inner::recreateRows() { void Editor::Inner::recreateRows() {

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "window/themes/window_theme_preview.h" #include "window/themes/window_theme_preview.h"
#include "window/themes/window_theme.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "platform/platform_window_title.h" #include "platform/platform_window_title.h"
#include "ui/text/text_options.h" #include "ui/text/text_options.h"

View file

@ -30,8 +30,8 @@ WarningWidget::WarningWidget(QWidget *parent)
, _secondsLeft(kWaitBeforeRevertMs / 1000) , _secondsLeft(kWaitBeforeRevertMs / 1000)
, _keepChanges(this, tr::lng_theme_keep_changes(), st::defaultBoxButton) , _keepChanges(this, tr::lng_theme_keep_changes(), st::defaultBoxButton)
, _revert(this, tr::lng_theme_revert(), st::defaultBoxButton) { , _revert(this, tr::lng_theme_revert(), st::defaultBoxButton) {
_keepChanges->setClickedCallback([] { Window::Theme::KeepApplied(); }); _keepChanges->setClickedCallback([] { KeepApplied(); });
_revert->setClickedCallback([] { Window::Theme::Revert(); }); _revert->setClickedCallback([] { Revert(); });
updateText(); updateText();
} }

View file

@ -340,9 +340,9 @@ void CloudList::setup() {
auto themeChanges = rpl::single(BackgroundUpdate( auto themeChanges = rpl::single(BackgroundUpdate(
BackgroundUpdate::Type::ApplyingTheme, BackgroundUpdate::Type::ApplyingTheme,
Background()->tile() Background()->tile()
)) | rpl::then(base::ObservableViewer( )) | rpl::then(
*Background() Background()->updates()
)) | rpl::filter([](const BackgroundUpdate &update) { ) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme); return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}); });

View file

@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "core/update_checker.h" #include "core/update_checker.h"
#include "window/themes/window_theme.h"
#include "boxes/connection_box.h" #include "boxes/connection_box.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
@ -112,9 +111,7 @@ private:
}; };
class ConnectionState::Widget::ProxyIcon class ConnectionState::Widget::ProxyIcon final : public Ui::RpWidget {
: public Ui::RpWidget
, private base::Subscriber {
public: public:
ProxyIcon(QWidget *parent); ProxyIcon(QWidget *parent);
@ -143,12 +140,10 @@ ConnectionState::Widget::ProxyIcon::ProxyIcon(QWidget *parent) : RpWidget(parent
st::connectingRadial.size.height(), st::connectingRadial.size.height(),
st::connectingProxyOn.height())); st::connectingProxyOn.height()));
using namespace Window::Theme; style::PaletteChanged(
subscribe(Background(), [=](const BackgroundUpdate &update) { ) | rpl::start_with_next([=] {
if (update.paletteChanged()) { refreshCacheImages();
refreshCacheImages(); }, lifetime());
}
});
refreshCacheImages(); refreshCacheImages();
} }

View file

@ -138,9 +138,7 @@ void ShowCallsBox(not_null<Window::SessionController*> window) {
namespace Window { namespace Window {
class MainMenu::AccountButton final class MainMenu::AccountButton final : public Ui::RippleButton {
: public Ui::RippleButton
, public base::Subscriber {
public: public:
AccountButton(QWidget *parent, not_null<Main::Account*> account); AccountButton(QWidget *parent, not_null<Main::Account*> account);
@ -209,12 +207,10 @@ MainMenu::AccountButton::AccountButton(
+ _st.itemPadding.bottom(); + _st.itemPadding.bottom();
resize(width(), height); resize(width(), height);
subscribe(Window::Theme::Background(), [=]( style::PaletteChanged(
const Window::Theme::BackgroundUpdate &update) { ) | rpl::start_with_next([=] {
if (update.paletteChanged()) { _userpicKey = {};
_userpicKey = {}; }, lifetime());
}
});
rpl::single( rpl::single(
rpl::empty_value() rpl::empty_value()
@ -639,8 +635,10 @@ MainMenu::MainMenu(
refreshMenu(); refreshMenu();
}, lifetime()); }, lifetime());
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { using Window::Theme::BackgroundUpdate;
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) { Window::Theme::Background()->updates(
) | rpl::start_with_next([=](const BackgroundUpdate &update) {
if (update.type == BackgroundUpdate::Type::ApplyingTheme) {
if (const auto action = *_nightThemeAction) { if (const auto action = *_nightThemeAction) {
const auto nightMode = Window::Theme::IsNightMode(); const auto nightMode = Window::Theme::IsNightMode();
if (action->isChecked() != nightMode) { if (action->isChecked() != nightMode) {
@ -649,10 +647,10 @@ MainMenu::MainMenu(
} }
} }
} }
if (update.type == Window::Theme::BackgroundUpdate::Type::New) { if (update.type == BackgroundUpdate::Type::New) {
refreshBackground(); refreshBackground();
} }
}); }, lifetime());
updatePhone(); updatePhone();
initResetScaleButton(); initResetScaleButton();
} }

View file

@ -37,7 +37,7 @@ namespace Window {
class SessionController; class SessionController;
class MainMenu : public Ui::LayerWidget, private base::Subscriber { class MainMenu final : public Ui::LayerWidget {
public: public:
MainMenu(QWidget *parent, not_null<SessionController*> controller); MainMenu(QWidget *parent, not_null<SessionController*> controller);

View file

@ -25,7 +25,7 @@ namespace Window {
class SessionController; class SessionController;
class MediaPreviewWidget : public Ui::RpWidget, private base::Subscriber { class MediaPreviewWidget final : public Ui::RpWidget {
public: public:
MediaPreviewWidget( MediaPreviewWidget(
QWidget *parent, QWidget *parent,