diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index c0d2a844e1..4ecea9c6ef 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1215,6 +1215,8 @@ PRIVATE settings/settings_main.h settings/settings_notifications.cpp settings/settings_notifications.h + settings/settings_power_saving.cpp + settings/settings_power_saving.h settings/settings_premium.cpp settings/settings_premium.h settings/settings_privacy_controllers.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ad8d1f1466..bcdd1e01c7 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -593,7 +593,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_version_info" = "Version and updates"; "lng_settings_system_integration" = "System integration"; "lng_settings_performance" = "Performance"; -"lng_settings_enable_animations" = "Enable animations"; "lng_settings_enable_hwaccel" = "Hardware accelerated video decoding"; "lng_settings_enable_opengl" = "Enable OpenGL rendering for media"; "lng_settings_angle_backend" = "ANGLE graphics backend"; @@ -609,6 +608,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_security_bots" = "Bots and websites"; "lng_settings_clear_payment_info" = "Clear Payment and Shipping Info"; +"lng_settings_power_title" = "Power efficiency"; +"lng_settings_power_stickers" = "Animated Stickers"; +"lng_settings_power_stickers_panel" = "Autoplay in panel"; +"lng_settings_power_stickers_chat" = "Autoplay in chat"; +"lng_settings_power_emoji" = "Animated Emoji"; +"lng_settings_power_emoji_panel" = "Autoplay in panel"; +"lng_settings_power_emoji_reactions" = "Autoplay in reactions menu"; +"lng_settings_power_emoji_chat" = "Autoplay in messages"; +"lng_settings_power_chat" = "Animations in Chats"; +"lng_settings_power_chat_background" = "Background rotation"; +"lng_settings_power_chat_spoiler" = "Animated spoiler effect"; +"lng_settings_power_calls" = "Animations in Calls"; +"lng_settings_power_ui" = "Interface animations"; + "lng_settings_cloud_password_on" = "On"; "lng_settings_cloud_password_off" = "Off"; "lng_settings_cloud_password_start_title" = "Two-Step Verification"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 0c537478cc..421d3eb122 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_values.h" #include "boxes/peers/edit_participants_box.h" #include "boxes/peers/edit_peer_info_box.h" +#include "settings/settings_power_saving.h" #include "window/window_session_controller.h" #include "window/window_controller.h" #include "main/main_session.h" @@ -42,6 +43,11 @@ namespace { constexpr auto kSlowmodeValues = 7; constexpr auto kSuggestGigagroupThreshold = 199000; +[[nodiscard]] auto Dependencies(PowerSaving::Flags) +-> std::vector> { + return {}; +} + struct NestedRestrictionLabels { std::optional> nestedLabel; std::vector restrictionLabels; @@ -194,7 +200,6 @@ auto Dependencies(ChatRestrictions) }; } - ChatRestrictions NegateRestrictions(ChatRestrictions value) { using Flag = ChatRestriction; @@ -473,13 +478,14 @@ template < ApplyDependencies(state->checkViews, dependencies, view); }; - container->add( - object_ptr( - container, - std::move(header), - st::rightsHeaderLabel), - st::rightsHeaderMargin); - + if (header) { + container->add( + object_ptr( + container, + std::move(header), + st::rightsHeaderLabel), + st::rightsHeaderMargin); + } const auto addCheckbox = [&]( not_null verticalLayout, bool isInner, @@ -1131,3 +1137,18 @@ ChatAdminRights AdminRightsForOwnershipTransfer( } return result; } + +EditFlagsControl CreateEditPowerSaving( + QWidget *parent, + PowerSaving::Flags flags) { + auto widget = object_ptr(parent); + auto result = CreateEditFlags( + widget.data(), + nullptr, + flags, + std::map{}, + Settings::PowerSavingLabelsList()); + result.widget = std::move(widget); + + return result; +} diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h index f28f5b472d..75d806deac 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h @@ -16,6 +16,11 @@ class RpWidget; class VerticalLayout; } // namespace Ui +namespace PowerSaving { +enum Flag : uint32; +using Flags = base::flags; +} // namespace PowerSaving + template class object_ptr; @@ -82,3 +87,8 @@ struct EditFlagsControl { ChatRestrictions restrictions); [[nodiscard]] ChatAdminRights AdminRightsForOwnershipTransfer( Data::AdminRightsSetOptions options); + +[[nodiscard]] auto CreateEditPowerSaving( + QWidget *parent, + PowerSaving::Flags flags +) -> EditFlagsControl; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index ba89371fb8..d5b7e717db 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/path_shift_gradient.h" #include "ui/emoji_config.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/toast/toast.h" #include "ui/widgets/popup_menu.h" #include "ui/cached_round_corners.h" @@ -1125,8 +1126,8 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { _pathGradient->startFrame(0, width(), width() / 2); const auto now = crl::now(); - const auto paused = _controller->isGifPausedAtLeastFor( - Window::GifPauseReason::Layer); + const auto paused = On(PowerSaving::kStickersPanel) + || _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); for (int32 i = from; i < to; ++i) { for (int32 j = 0; j < _perRow; ++j) { int32 index = i * _perRow + j; diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 0ff423ccb3..091cdf5386 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/padding_wrap.h" #include "ui/text/format_values.h" #include "ui/toast/toast.h" +#include "ui/power_saving.h" #include "lang/lang_keys.h" #include "core/application.h" #include "calls/calls_call.h" @@ -496,18 +497,12 @@ void TopBar::initBlobsUnder( } }, lifetime()); + using namespace rpl::mappers; auto hideBlobs = rpl::combine( - rpl::single(anim::Disabled()) | rpl::then(anim::Disables()), + PowerSaving::Value(PowerSaving::kCalls), Core::App().appDeactivatedValue(), group->instanceStateValue() - ) | rpl::map([]( - bool animDisabled, - bool hide, - GroupCall::InstanceState instanceState) { - return (instanceState == GroupCall::InstanceState::Disconnected) - || animDisabled - || hide; - }); + ) | rpl::map(_1 || _2 || _3 == GroupCall::InstanceState::Disconnected); std::move( hideBlobs diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.cpp b/Telegram/SourceFiles/calls/group/calls_group_members.cpp index fcec2a8ff0..7dd2e83656 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/ripple_animation.h" #include "ui/effects/cross_line.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/application.h" // Core::App().domain, .activeWindow. #include "main/main_domain.h" // Core::App().domain().activate. #include "main/main_session.h" @@ -234,10 +235,10 @@ Members::Controller::Controller( }, _lifetime); rpl::combine( - rpl::single(anim::Disabled()) | rpl::then(anim::Disables()), + PowerSaving::Value(PowerSaving::kCalls), Core::App().appDeactivatedValue() - ) | rpl::start_with_next([=](bool animDisabled, bool deactivated) { - const auto hide = !(!animDisabled && !deactivated); + ) | rpl::start_with_next([=](bool disabled, bool deactivated) { + const auto hide = disabled || deactivated; if (!(hide && _soundingAnimationHideLastTime)) { _soundingAnimationHideLastTime = hide ? crl::now() : 0; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index fcfa7fc52f..2183be4062 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/premium_graphics.h" #include "ui/emoji_config.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" #include "ui/cached_round_corners.h" #include "boxes/sticker_set_box.h" @@ -709,9 +710,13 @@ object_ptr EmojiListWidget::createFooter() { Expects(_footer == nullptr); using FooterDescriptor = StickersListFooter::Descriptor; + const auto flag = powerSavingFlag(); + const auto footerPaused = [method = pausedMethod(), flag]() { + return On(flag) || method(); + }; auto result = object_ptr(FooterDescriptor{ .session = &session(), - .paused = pausedMethod(), + .paused = footerPaused, .parent = this, .st = &st(), }); @@ -1006,7 +1011,7 @@ void EmojiListWidget::validateEmojiPaintContext( .size = QSize(_customSingleSize, _customSingleSize), .now = crl::now(), .scale = context.progress, - .paused = paused(), + .paused = On(powerSavingFlag()) || paused(), .scaled = context.expanding, }; if (!_emojiPaintContext) { @@ -2179,6 +2184,14 @@ QPoint EmojiListWidget::buttonRippleTopLeft(int section) const { : QPoint()); } +PowerSaving::Flag EmojiListWidget::powerSavingFlag() const { + const auto reactions = (_mode == Mode::FullReactions) + || (_mode == Mode::RecentReactions); + return reactions + ? PowerSaving::kEmojiReactions + : PowerSaving::kEmojiPanel; +} + void EmojiListWidget::refreshEmoji() { refreshRecent(); refreshCustom(); diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index 764263580c..e928bda692 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -24,6 +24,10 @@ namespace Data { class StickersSet; } // namespace Data +namespace PowerSaving { +enum Flag : uint32; +} // namespace PowerSaving + namespace tr { template struct phrase; @@ -322,6 +326,7 @@ private: [[nodiscard]] std::unique_ptr createButtonRipple( int section); [[nodiscard]] QPoint buttonRippleTopLeft(int section) const; + [[nodiscard]] PowerSaving::Flag powerSavingFlag() const; void repaintCustom(uint64 setId); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 019fd55171..ddceac33f5 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" #include "data/data_session.h" #include "data/data_user.h" @@ -325,6 +326,9 @@ void InitMessageFieldHandlers( const style::InputField *fieldStyle) { field->setTagMimeProcessor( FieldTagMimeProcessor(session, allowPremiumEmoji)); + const auto paused = [customEmojiPaused] { + return On(PowerSaving::kEmojiChat) || customEmojiPaused(); + }; field->setCustomEmojiFactory( session->data().customEmojiManager().factory(), std::move(customEmojiPaused)); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index f25751c419..d4d2997095 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/premium_graphics.h" #include "ui/image/image.h" #include "ui/cached_round_corners.h" +#include "ui/power_saving.h" #include "lottie/lottie_multi_player.h" #include "lottie/lottie_single_player.h" #include "lottie/lottie_animation.h" @@ -265,10 +266,14 @@ auto StickersListWidget::choosingUpdated() const object_ptr StickersListWidget::createFooter() { Expects(_footer == nullptr); + const auto footerPaused = [method = pausedMethod()] { + return On(PowerSaving::kStickersPanel) || method(); + }; + using FooterDescriptor = StickersListFooter::Descriptor; auto result = object_ptr(FooterDescriptor{ .session = &session(), - .paused = pausedMethod(), + .paused = footerPaused, .parent = this, .settingsButtonVisible = true, }); @@ -854,7 +859,8 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { : &_selected); const auto now = crl::now(); - const auto paused = this->paused(); + const auto paused = On(PowerSaving::kStickersPanel) + || this->paused(); if (sets.empty() && _section == Section::Search) { paintEmptySearchResults(p); } diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index a104294ff8..7e195ba946 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/unread_badge.h" #include "ui/unread_badge_paint.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/ui_integration.h" #include "lang/lang_keys.h" #include "support/support_helper.h" @@ -262,7 +263,8 @@ void PaintFolderEntryText( : st::dialogsTextPaletteArchive), .spoiler = Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .elisionLines = rect.height() / st::dialogsTextFont->height, }); } @@ -420,7 +422,8 @@ void PaintRow( .availableWidth = availableWidth, .spoiler = Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .elisionLines = 1, }); } else if (draft @@ -514,7 +517,8 @@ void PaintRow( : st::dialogsTextPaletteDraft)), .spoiler = Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .elisionLines = 1, }); } diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp index ed869dd4b9..cb9fb4ee99 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/image/image.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/ui_integration.h" #include "lang/lang_keys.h" #include "lang/lang_text_entity.h" @@ -296,6 +297,8 @@ void MessageView::paint( finalRight -= st::forumDialogJumpArrowSkip; } const auto lines = rect.height() / st::dialogsTextFont->height; + const auto pausedSpoiler = context.paused + || On(PowerSaving::kChatSpoiler); if (!_senderCache.isEmpty()) { _senderCache.draw(p, { .position = rect.topLeft(), @@ -323,7 +326,7 @@ void MessageView::paint( p.drawImage(mini, image.data); if (image.hasSpoiler()) { const auto frame = DefaultImageSpoiler().frame( - _spoiler->index(context.now, context.paused)); + _spoiler->index(context.now, pausedSpoiler)); FillSpoilerRect(p, mini, frame); } } @@ -341,7 +344,8 @@ void MessageView::paint( .palette = palette, .spoiler = Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = pausedSpoiler, .elisionLines = lines, }); rect.setLeft(rect.x() + _textCache.maxWidth()); diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp index 2b5b403495..20d74e916a 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/ui_integration.h" #include "lang/lang_keys.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "ui/effects/ripple_animation.h" @@ -138,7 +139,8 @@ void TopicsView::paint( .palette = palette, .spoiler = Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .elisionLines = 1, }); const auto skip = skipBig diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 1556a579a1..8b65739351 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/chat/chat_theme.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "history/history.h" #include "history/history_item.h" #include "history/history_item_helpers.h" @@ -469,6 +470,8 @@ void HistoryMessageReply::paint( p.setOpacity(opacity); } + const auto pausedSpoiler = context.paused + || On(PowerSaving::kChatSpoiler); if (w > st::msgReplyBarSkip) { if (replyToMsg) { const auto media = replyToMsg->media(); @@ -499,7 +502,7 @@ void HistoryMessageReply::paint( Ui::DefaultImageSpoiler().frame( spoiler->index( context.now, - context.paused))); + pausedSpoiler))); } } } @@ -529,7 +532,9 @@ void HistoryMessageReply::paint( : st->imgReplyTextPalette()), .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = (context.paused + || On(PowerSaving::kEmojiChat)), + .pausedSpoiler = pausedSpoiler, .elisionLines = 1, }); p.setTextPalette(stm->textPalette); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 1a29f31624..d8d9e317b4 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/choose_send_as.h" #include "ui/image/image.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/controls/emoji_button.h" #include "ui/controls/send_button.h" #include "ui/controls/send_as_button.h" @@ -1826,7 +1827,7 @@ void HistoryWidget::setupShortcuts() { && Ui::AppInFocus() && Ui::InFocusChain(this) && !controller()->isLayerShown() - && (Core::App().activeWindow() == &controller()->window()); + && window()->isActiveWindow(); }) | rpl::start_with_next([=](not_null request) { using Command = Shortcuts::Command; request->check(Command::Search, 1) && request->handle([=] { @@ -2996,7 +2997,15 @@ void HistoryWidget::newItemAdded(not_null item) { } } const auto view = item->mainView(); - if (anim::Disabled() || !view) { + if (!view) { + return; + } else if (anim::Disabled()) { + if (!On(PowerSaving::kChatBackground)) { + // Strange case of disabled animations, but enabled bg rotation. + if (item->out() || _history->peer->isSelf()) { + _list->theme()->rotateComplexGradientBackground(); + } + } return; } _itemRevealPending.emplace(item); @@ -7690,6 +7699,7 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { if (_editMsgId || _replyToId || (!hasForward && _kbReplyTo)) { const auto now = crl::now(); const auto paused = p.inactive(); + const auto pausedSpoiler = paused || On(PowerSaving::kChatSpoiler); auto replyLeft = st::historyReplySkip; (_editMsgId ? st::historyEditIcon : st::historyReplyIcon).paint(p, st::historyReplyIconPosition + QPoint(0, backy), width()); if (!drawWebPagePreview) { @@ -7708,7 +7718,7 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { p, to, Ui::DefaultImageSpoiler().frame( - _replySpoiler->index(now, paused))); + _replySpoiler->index(now, pausedSpoiler))); } } replyLeft += st::msgReplyBarSize.height() + st::msgReplyBarSkip - st::msgReplyBarSize.width() - st::msgReplyBarPos.x(); @@ -7728,7 +7738,8 @@ void HistoryWidget::drawField(Painter &p, const QRect &rect) { .palette = &st::historyComposeAreaPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = now, - .paused = paused, + .pausedEmoji = paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = pausedSpoiler, .elisionLines = 1, }); } else { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 3c5e3e5727..470581c545 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_chat_participants.h" #include "ui/boxes/confirm_box.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "history/history.h" #include "history/history_item.h" #include "history/view/controls/history_view_voice_record_bar.h" @@ -800,7 +801,8 @@ void FieldHeader::paintEditOrReplyToMessage(Painter &p) { .palette = &st::historyComposeAreaPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = crl::now(), - .paused = p.inactive(), + .pausedEmoji = p.inactive() || On(PowerSaving::kEmojiChat), + .pausedSpoiler = p.inactive() || On(PowerSaving::kChatSpoiler), .elisionLines = 1, }); } diff --git a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp index 91ff80e946..5c65cfe1bb 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/ui_integration.h" #include "lang/lang_keys.h" #include "window/window_peer_menu.h" @@ -309,6 +310,7 @@ void ForwardPanel::paint( const_cast(this)->checkTexts(); const auto now = crl::now(); const auto paused = p.inactive(); + const auto pausedSpoiler = paused || On(PowerSaving::kChatSpoiler); const auto firstItem = _data.items.front(); const auto firstMedia = firstItem->media(); const auto hasPreview = (_data.items.size() < 2) @@ -335,7 +337,7 @@ void ForwardPanel::paint( })); if (_spoiler) { Ui::FillSpoilerRect(p, to, Ui::DefaultImageSpoiler().frame( - _spoiler->index(now, paused))); + _spoiler->index(now, pausedSpoiler))); } const auto skip = st::msgReplyBarSize.height() + st::msgReplyBarSkip @@ -359,7 +361,8 @@ void ForwardPanel::paint( .palette = &st::historyComposeAreaPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = now, - .paused = paused, + .pausedEmoji = paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = pausedSpoiler, .elisionLines = 1, }); } diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 8605c960b2..221e0e7050 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/text/text_entity.h" #include "ui/cached_round_corners.h" +#include "ui/power_saving.h" #include "base/unixtime.h" #include "data/data_session.h" #include "data/data_user.h" @@ -1472,7 +1473,8 @@ void Message::paintText( .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, }); } diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index c955572ef3..2697ad7c4b 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/text/text_options.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" #include "mainwidget.h" #include "menu/menu_ttl_validator.h" @@ -554,7 +555,8 @@ void Service::draw(Painter &p, const PaintContext &context) const { .palette = &st->serviceTextPalette(), .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, .fullWidthSelection = false, }); diff --git a/Telegram/SourceFiles/history/view/media/history_view_custom_emoji.cpp b/Telegram/SourceFiles/history/view/media/history_view_custom_emoji.cpp index 8e628d659e..acd836fc13 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_custom_emoji.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_custom_emoji.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/text/text_isolated_emoji.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "styles/style_chat.h" namespace HistoryView { @@ -264,6 +265,7 @@ void CustomEmoji::paintCustom( } //const auto preview = context.imageStyle()->msgServiceBg->c; auto &textst = context.st->messageStyle(false, false); + const auto paused = context.paused || On(PowerSaving::kEmojiChat); if (context.selected()) { const auto factor = style::DevicePixelRatio(); const auto size = QSize(_singleSize, _singleSize) * factor; @@ -278,7 +280,7 @@ void CustomEmoji::paintCustom( emoji->paint(q, { .textColor = textst.historyTextFg->c, .now = context.now, - .paused = context.paused, + .paused = paused, }); q.end(); @@ -291,7 +293,7 @@ void CustomEmoji::paintCustom( .textColor = textst.historyTextFg->c, .now = context.now, .position = { x, y }, - .paused = context.paused, + .paused = paused, }); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 69aaf26fdb..19832fc233 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" #include "data/data_session.h" #include "data/data_document.h" @@ -749,7 +750,8 @@ void Document::draw( .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = selection, }); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp index 7ede5a9d67..f2768fef16 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image_prepare.h" #include "ui/chat/chat_style.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "data/data_session.h" #include "payments/payments_checkout_process.h" #include "window/window_session_controller.h" @@ -236,7 +237,8 @@ void ExtendedPreview::draw(Painter &p, const PaintContext &context) const { .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, }); } else if (!inWebPage) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_game.cpp b/Telegram/SourceFiles/history/view/media/history_view_game.cpp index d689b6535d..788b28e2c6 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_game.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_game.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/cached_round_corners.h" #include "ui/chat/chat_style.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/ui_integration.h" #include "data/data_session.h" #include "data/data_game.h" @@ -253,7 +254,8 @@ void Game::draw(Painter &p, const PaintContext &context) const { .availableWidth = paintw, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = toDescriptionSelection(context.selection), .elisionLines = _descriptionLines, .elisionRemoveFromEnd = endskip, diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 303c22e24c..caf8c2e7a4 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/grouped_layout.h" #include "ui/cached_round_corners.h" +#include "ui/power_saving.h" #include "ui/effects/path_shift_gradient.h" #include "ui/effects/spoiler_mess.h" #include "data/data_session.h" @@ -681,7 +682,8 @@ void Gif::draw(Painter &p, const PaintContext &context) const { .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, }); } else if (!inWebPage && !skipDrawingSurrounding) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp b/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp index d1ddb75015..95676cc89b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "data/data_media_types.h" #include "styles/style_chat.h" @@ -237,7 +238,8 @@ void Invoice::draw(Painter &p, const PaintContext &context) const { .availableWidth = paintw, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = toDescriptionSelection(context.selection), }); tshift += _descriptionHeight; diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index 2d252eb599..da0f56871d 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/chat/message_bubble.h" #include "ui/image/image_prepare.h" +#include "ui/power_saving.h" #include "core/ui_integration.h" #include "styles/style_chat.h" @@ -261,12 +262,14 @@ void Media::fillImageSpoiler( history()->owner().registerHeavyViewPart(_parent); } _parent->clearCustomEmojiRepaint(); + const auto pausedSpoiler = context.paused + || On(PowerSaving::kChatSpoiler); Ui::FillSpoilerRect( p, rect, MediaRoundingMask(spoiler->backgroundRounding), Ui::DefaultImageSpoiler().frame( - spoiler->animation->index(context.now, context.paused)), + spoiler->animation->index(context.now, pausedSpoiler)), spoiler->cornerCache); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index 308dd8d942..e20cf8f1ed 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/message_bubble.h" #include "ui/text/text_options.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "layout/layout_selection.h" #include "styles/style_chat.h" @@ -368,7 +369,8 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const { .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, }); } else if (_parent->media() == this) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 0d5ec5d10f..b65b946e9b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/grouped_layout.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "data/data_session.h" #include "data/data_streaming.h" #include "data/data_photo.h" @@ -355,7 +356,8 @@ void Photo::draw(Painter &p, const PaintContext &context) const { .palette = &stm->textPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = context.selection, }); } else if (!inWebPage) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index f5e644637d..e1668a29c2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/custom_emoji_instance.h" #include "ui/emoji_config.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "core/application.h" #include "core/core_settings.h" #include "core/click_handler_types.h" @@ -247,13 +248,17 @@ void Sticker::paintAnimationFrame( : (context.selected() && !_nextLastDiceFrame) ? context.st->msgStickerOverlay()->c : QColor(0, 0, 0, 0); + const auto powerSavingFlag = (isEmojiSticker() || _diceIndex >= 0) + ? PowerSaving::kEmojiChat + : PowerSaving::kStickersChat; + const auto paused = context.paused || On(powerSavingFlag); const auto frame = _player ? _player->frame( _size, colored, mirrorHorizontal(), context.now, - context.paused) + paused) : StickerPlayer::FrameInfo(); if (_nextLastDiceFrame) { _nextLastDiceFrame = false; @@ -282,7 +287,7 @@ void Sticker::paintAnimationFrame( const auto count = _player->framesCount(); _frameIndex = frame.index; _framesCount = count; - _nextLastDiceFrame = !context.paused + _nextLastDiceFrame = !paused && (_diceIndex > 0) && (_frameIndex + 2 == count); const auto playOnce = (_diceIndex > 0) @@ -294,7 +299,7 @@ void Sticker::paintAnimationFrame( const auto lastDiceFrame = (_diceIndex > 0) && atTheEnd(); const auto switchToNext = !playOnce || (!lastDiceFrame && (_frameIndex != 0 || !_oncePlayed)); - if (!context.paused + if (!paused && switchToNext && _player->markFrameShown() && playOnce diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index cab4fd7b43..3b909485f2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "data/data_session.h" #include "data/data_wall_paper.h" #include "data/data_media_types.h" @@ -578,7 +579,8 @@ void WebPage::draw(Painter &p, const PaintContext &context) const { .availableWidth = paintw, .spoiler = Ui::Text::DefaultSpoilerCache(), .now = context.now, - .paused = context.paused, + .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat), + .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler), .selection = toDescriptionSelection(context.selection), .elisionLines = std::max(_descriptionLines, 0), .elisionRemoveFromEnd = (_descriptionLines > 0) ? endskip : 0, diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp index ce84d5b45f..ef46797645 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" #include "ui/effects/reaction_fly_animation.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "styles/style_chat.h" namespace HistoryView::Reactions { @@ -417,7 +418,7 @@ void InlineList::paint( p, custom, inner.topLeft(), - context.now, + context, textFg.color()); } else if (!button.image.isNull()) { p.drawImage(image.topLeft(), button.image); @@ -546,7 +547,7 @@ void InlineList::paintCustomFrame( Painter &p, not_null emoji, QPoint innerTopLeft, - crl::time now, + const PaintContext &context, const QColor &textColor) const { if (_customCache.isNull()) { using namespace Ui::Text; @@ -563,8 +564,8 @@ void InlineList::paintCustomFrame( auto q = QPainter(&_customCache); emoji->paint(q, { .textColor = textColor, - .now = now, - .paused = p.inactive(), + .now = context.now, + .paused = context.paused || On(PowerSaving::kEmojiChat), }); q.end(); _customCache = Images::Round( diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.h b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.h index 1100aa4af6..ef2758d5c5 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.h +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.h @@ -109,7 +109,7 @@ private: Painter &p, not_null emoji, QPoint innerTopLeft, - crl::time now, + const PaintContext &context, const QColor &textColor) const; QSize countOptimalSize() override; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index a3ea689ce0..f95668c546 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/item_text_options.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" #include "ui/cached_round_corners.h" #include "ui/gl/gl_surface.h" @@ -4279,6 +4280,8 @@ void OverlayWidget::paintCaptionContent( .availableWidth = inner.width(), .palette = &st::mediaviewTextPalette, .spoiler = Ui::Text::DefaultSpoilerCache(), + .pausedEmoji = On(PowerSaving::kEmojiChat), + .pausedSpoiler = On(PowerSaving::kChatSpoiler), .elisionLines = inner.height() / st::mediaviewCaptionStyle.font->height, }); } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 9a2c875fc4..369a6ff5d8 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -48,6 +48,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/ui_utility.h" namespace Overview { @@ -363,11 +364,12 @@ void Photo::paint(Painter &p, const QRect &clip, TextSelection selection, const } if (_spoiler) { + const auto paused = context->paused || On(PowerSaving::kChatSpoiler); Ui::FillSpoilerRect( p, QRect(0, 0, _width, _height), Ui::DefaultImageSpoiler().frame( - _spoiler->index(context->ms, context->paused))); + _spoiler->index(context->ms, paused))); } if (selected) { @@ -517,11 +519,12 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const } if (_spoiler) { + const auto paused = context->paused || On(PowerSaving::kChatSpoiler); Ui::FillSpoilerRect( p, QRect(0, 0, _width, _height), Ui::DefaultImageSpoiler().frame( - _spoiler->index(context->ms, context->paused))); + _spoiler->index(context->ms, paused))); } if (selected) { diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 7f3ed4469f..3fe1c256f1 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" #include "settings/settings_chat.h" #include "settings/settings_experimental.h" +#include "settings/settings_power_saving.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/widgets/labels.h" @@ -658,20 +659,16 @@ void SetupWindowTitleOptions( SetupWindowTitleContent); } -void SetupAnimations(not_null container) { +void SetupAnimations( + not_null window, + not_null container) { AddButton( container, - tr::lng_settings_enable_animations(), + tr::lng_settings_power_title(), st::settingsButtonNoIcon - )->toggleOn( - rpl::single(!anim::Disabled()) - )->toggledValue( - ) | rpl::filter([](bool enabled) { - return (enabled == anim::Disabled()); - }) | rpl::start_with_next([](bool enabled) { - anim::SetDisabled(!enabled); - Local::writeSettings(); - }, container->lifetime()); + )->setClickedCallback([=] { + window->show(Box(PowerSavingBox)); + }); } void SetupHardwareAcceleration(not_null container) { @@ -804,7 +801,7 @@ void SetupOpenGL( void SetupPerformance( not_null controller, not_null container) { - SetupAnimations(container); + SetupAnimations(&controller->window(), container); SetupHardwareAcceleration(container); #ifdef Q_OS_WIN SetupANGLE(controller, container); diff --git a/Telegram/SourceFiles/settings/settings_advanced.h b/Telegram/SourceFiles/settings/settings_advanced.h index 940c362a62..27afff6231 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.h +++ b/Telegram/SourceFiles/settings/settings_advanced.h @@ -33,7 +33,9 @@ void SetupWindowTitleContent( void SetupSystemIntegrationContent( Window::SessionController *controller, not_null container); -void SetupAnimations(not_null container); +void SetupAnimations( + not_null window, + not_null container); class Advanced : public Section { public: diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index 68150ef1d3..feea99acd0 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -98,7 +98,7 @@ object_ptr CreateIntroSettings( if (anim::Disabled()) { AddDivider(result); AddSkip(result); - SetupAnimations(result); + SetupAnimations(window, result); AddSkip(result); } diff --git a/Telegram/SourceFiles/settings/settings_power_saving.cpp b/Telegram/SourceFiles/settings/settings_power_saving.cpp new file mode 100644 index 0000000000..28a971c246 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_power_saving.cpp @@ -0,0 +1,66 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "settings/settings_power_saving.h" + +#include "boxes/peers/edit_peer_permissions_box.h" +#include "core/application.h" +#include "lang/lang_keys.h" +#include "ui/layers/generic_box.h" +#include "ui/power_saving.h" + +namespace Settings { + +void PowerSavingBox(not_null box) { + box->setTitle(tr::lng_settings_power_title()); + + auto [checkboxes, getResult, changes] = CreateEditPowerSaving( + box, + PowerSaving::kAll & ~PowerSaving::Current()); + + box->addRow(std::move(checkboxes), {}); + + box->addButton(tr::lng_settings_save(), [=] { + Set(PowerSaving::kAll & ~getResult()); + Core::App().saveSettingsDelayed(); + box->closeBox(); + }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); +} + +std::vector PowerSavingLabelsList() { + using namespace PowerSaving; + using Label = PowerSavingLabel; + auto stickers = std::vector