Implement some power saving options.

This commit is contained in:
John Preston 2023-02-21 16:31:55 +04:00
parent 02bc950b57
commit 2a4c39b9d7
53 changed files with 446 additions and 108 deletions

View File

@ -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

View File

@ -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";

View File

@ -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<std::pair<PowerSaving::Flag, PowerSaving::Flag>> {
return {};
}
struct NestedRestrictionLabels {
std::optional<rpl::producer<QString>> nestedLabel;
std::vector<RestrictionLabel> 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<Ui::FlatLabel>(
container,
std::move(header),
st::rightsHeaderLabel),
st::rightsHeaderMargin);
if (header) {
container->add(
object_ptr<Ui::FlatLabel>(
container,
std::move(header),
st::rightsHeaderLabel),
st::rightsHeaderMargin);
}
const auto addCheckbox = [&](
not_null<Ui::VerticalLayout*> verticalLayout,
bool isInner,
@ -1131,3 +1137,18 @@ ChatAdminRights AdminRightsForOwnershipTransfer(
}
return result;
}
EditFlagsControl<PowerSaving::Flags, Ui::RpWidget> CreateEditPowerSaving(
QWidget *parent,
PowerSaving::Flags flags) {
auto widget = object_ptr<Ui::VerticalLayout>(parent);
auto result = CreateEditFlags(
widget.data(),
nullptr,
flags,
std::map<PowerSaving::Flags, QString>{},
Settings::PowerSavingLabelsList());
result.widget = std::move(widget);
return result;
}

View File

@ -16,6 +16,11 @@ class RpWidget;
class VerticalLayout;
} // namespace Ui
namespace PowerSaving {
enum Flag : uint32;
using Flags = base::flags<Flag>;
} // namespace PowerSaving
template <typename Object>
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<PowerSaving::Flags, Ui::RpWidget>;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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<TabbedSelector::InnerFooter> 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<StickersListFooter>(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();

View File

@ -24,6 +24,10 @@ namespace Data {
class StickersSet;
} // namespace Data
namespace PowerSaving {
enum Flag : uint32;
} // namespace PowerSaving
namespace tr {
template <typename ...Tags>
struct phrase;
@ -322,6 +326,7 @@ private:
[[nodiscard]] std::unique_ptr<Ui::RippleAnimation> createButtonRipple(
int section);
[[nodiscard]] QPoint buttonRippleTopLeft(int section) const;
[[nodiscard]] PowerSaving::Flag powerSavingFlag() const;
void repaintCustom(uint64 setId);

View File

@ -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));

View File

@ -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<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
Expects(_footer == nullptr);
const auto footerPaused = [method = pausedMethod()] {
return On(PowerSaving::kStickersPanel) || method();
};
using FooterDescriptor = StickersListFooter::Descriptor;
auto result = object_ptr<StickersListFooter>(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);
}

View File

@ -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,
});
}

View File

@ -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());

View File

@ -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

View File

@ -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);

View File

@ -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<Shortcuts::Request*> request) {
using Command = Shortcuts::Command;
request->check(Command::Search, 1) && request->handle([=] {
@ -2996,7 +2997,15 @@ void HistoryWidget::newItemAdded(not_null<HistoryItem*> 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 {

View File

@ -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,
});
}

View File

@ -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<ForwardPanel*>(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,
});
}

View File

@ -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,
});
}

View File

@ -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,
});

View File

@ -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,
});
}
}

View File

@ -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,
});
}

View File

@ -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) {

View File

@ -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,

View File

@ -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) {

View File

@ -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;

View File

@ -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);
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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

View File

@ -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,

View File

@ -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<Ui::Text::CustomEmoji*> 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(

View File

@ -109,7 +109,7 @@ private:
Painter &p,
not_null<Ui::Text::CustomEmoji*> emoji,
QPoint innerTopLeft,
crl::time now,
const PaintContext &context,
const QColor &textColor) const;
QSize countOptimalSize() override;

View File

@ -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,
});
}

View File

@ -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) {

View File

@ -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<Ui::VerticalLayout*> container) {
void SetupAnimations(
not_null<Window::Controller*> window,
not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout*> container) {
@ -804,7 +801,7 @@ void SetupOpenGL(
void SetupPerformance(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
SetupAnimations(container);
SetupAnimations(&controller->window(), container);
SetupHardwareAcceleration(container);
#ifdef Q_OS_WIN
SetupANGLE(controller, container);

View File

@ -33,7 +33,9 @@ void SetupWindowTitleContent(
void SetupSystemIntegrationContent(
Window::SessionController *controller,
not_null<Ui::VerticalLayout*> container);
void SetupAnimations(not_null<Ui::VerticalLayout*> container);
void SetupAnimations(
not_null<Window::Controller*> window,
not_null<Ui::VerticalLayout*> container);
class Advanced : public Section<Advanced> {
public:

View File

@ -98,7 +98,7 @@ object_ptr<Ui::RpWidget> CreateIntroSettings(
if (anim::Disabled()) {
AddDivider(result);
AddSkip(result);
SetupAnimations(result);
SetupAnimations(window, result);
AddSkip(result);
}

View File

@ -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<Ui::GenericBox*> 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<NestedPowerSavingLabels> PowerSavingLabelsList() {
using namespace PowerSaving;
using Label = PowerSavingLabel;
auto stickers = std::vector<Label>{
{ kStickersPanel, tr::lng_settings_power_stickers_panel(tr::now) },
{ kStickersChat, tr::lng_settings_power_stickers_chat(tr::now) },
};
auto emoji = std::vector<Label>{
{ kEmojiPanel, tr::lng_settings_power_emoji_panel(tr::now) },
{ kEmojiReactions, tr::lng_settings_power_emoji_reactions(tr::now) },
{ kEmojiChat, tr::lng_settings_power_emoji_chat(tr::now) },
};
auto chat = std::vector<Label>{
{ kChatBackground, tr::lng_settings_power_chat_background(tr::now) },
{ kChatSpoiler, tr::lng_settings_power_chat_spoiler(tr::now) },
};
auto calls = std::vector<Label>{
{ kCalls, tr::lng_settings_power_calls(tr::now) },
};
auto animations = std::vector<Label>{
{ kAnimations, tr::lng_settings_power_ui(tr::now) },
};
return {
{ tr::lng_settings_power_stickers(), std::move(stickers) },
{ tr::lng_settings_power_emoji(), std::move(emoji) },
{ tr::lng_settings_power_chat(), std::move(chat) },
{ std::nullopt, std::move(calls) },
{ std::nullopt, std::move(animations) },
};
}
} // namespace Settings

View File

@ -0,0 +1,34 @@
/*
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
*/
#pragma once
namespace PowerSaving {
enum Flag : uint32;
} // namespace PowerSaving
namespace Ui {
class GenericBox;
} // namespace Ui
namespace Settings {
void PowerSavingBox(not_null<Ui::GenericBox*> box);
struct PowerSavingLabel {
PowerSaving::Flag flags;
QString label;
};
struct NestedPowerSavingLabels {
std::optional<rpl::producer<QString>> nestedLabel;
std::vector<PowerSavingLabel> restrictionLabels;
};
[[nodiscard]] std::vector<NestedPowerSavingLabels> PowerSavingLabelsList();
} // namespace PowerSaving

View File

@ -13,9 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "core/core_settings.h"
#include "mtproto/mtproto_config.h"
#include "ui/effects/animation_value.h"
#include "ui/widgets/input_fields.h"
#include "ui/chat/attach/attach_send_files_way.h"
#include "ui/power_saving.h"
#include "window/themes/window_theme.h"
#include "core/update_checker.h"
#include "platform/platform_specific.h"
@ -232,14 +232,14 @@ bool ReadSetting(
context.cacheBigFileTotalTimeLimit = NoTimeLimit(timeBig) ? 0 : timeBig;
} break;
case dbiAnimationsDisabled: {
qint32 disabled;
stream >> disabled;
case dbiPowerSaving: {
qint32 settings;
stream >> settings;
if (!CheckStreamStatus(stream)) {
return false;
}
anim::SetDisabled(disabled == 1);
PowerSaving::Set(PowerSaving::Flags::from_raw(settings));
} break;
case dbiSoundFlashBounceNotifyOld: {

View File

@ -154,7 +154,7 @@ enum {
dbiThemeKey = 0x54,
dbiTileBackground = 0x55,
dbiCacheSettingsOld = 0x56,
dbiAnimationsDisabled = 0x57,
dbiPowerSaving = 0x57,
dbiScalePercent = 0x58,
dbiPlaybackSpeedOld = 0x59,
dbiLanguagesKey = 0x5a,

View File

@ -6,7 +6,7 @@ For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "storage/localstorage.h"
//
#include "storage/serialize_common.h"
#include "storage/storage_account.h"
#include "storage/details/storage_file_utilities.h"
@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document_media.h"
#include "base/platform/base_platform_info.h"
#include "base/random.h"
#include "ui/effects/animation_value.h"
#include "ui/power_saving.h"
#include "core/update_checker.h"
#include "core/file_location.h"
#include "core/application.h"
@ -473,6 +473,8 @@ void writeSettings() {
}
size += sizeof(quint32) + sizeof(qint32) * 8;
const auto powerSaving = PowerSaving::Current().value();
EncryptedDescriptor data(size);
data.stream << quint32(dbiAutoStart) << qint32(cAutoStart());
data.stream << quint32(dbiStartMinimized) << qint32(cStartMinimized());
@ -484,7 +486,7 @@ void writeSettings() {
data.stream << quint32(dbiFallbackProductionConfig) << configSerialized;
data.stream << quint32(dbiApplicationSettings) << applicationSettings;
data.stream << quint32(dbiDialogLastPath) << cDialogLastPath();
data.stream << quint32(dbiAnimationsDisabled) << qint32(anim::Disabled() ? 1 : 0);
data.stream << quint32(dbiPowerSaving) << qint32(powerSaving);
data.stream
<< quint32(dbiThemeKey)

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/spoiler_mess.h"
#include "ui/widgets/popup_menu.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "lang/lang_keys.h"
#include "styles/style_boxes.h"
#include "styles/style_chat.h"
@ -200,11 +201,12 @@ void AbstractSingleMediaPreview::paintEvent(QPaintEvent *e) {
const auto position = QPoint(_previewLeft, _previewTop);
p.drawPixmap(position, pixmap);
if (_spoiler) {
const auto paused = On(PowerSaving::kChatSpoiler);
FillSpoilerRect(
p,
QRect(position, pixmap.size() / pixmap.devicePixelRatio()),
DefaultImageSpoiler().frame(
_spoiler->index(crl::now(), false)));
_spoiler->index(crl::now(), paused)));
}
}
if (_animated && !isAnimatedPreviewReady() && !_spoiler) {

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/spoiler_mess.h"
#include "ui/ui_utility.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "base/call_delayed.h"
#include "styles/style_chat.h"
#include "styles/style_boxes.h"
@ -243,11 +244,12 @@ void AlbumThumbnail::paintInAlbum(
_albumCorners);
}
p.drawPixmap(paintedTo, _albumImageBlurred);
const auto paused = On(PowerSaving::kChatSpoiler);
FillSpoilerRect(
p,
paintedTo,
corners,
DefaultImageSpoiler().frame(_spoiler->index(crl::now(), false)),
DefaultImageSpoiler().frame(_spoiler->index(crl::now(), paused)),
_cornerCache);
p.setOpacity(1.);
}
@ -439,12 +441,13 @@ void AlbumThumbnail::paintPhoto(Painter &p, int left, int top, int outerWidth) {
outerWidth,
pixmap);
if (_spoiler) {
const auto paused = On(PowerSaving::kChatSpoiler);
FillSpoilerRect(
p,
rect,
Images::CornersMaskRef(
Images::CornersMask(ImageRoundRadius::Large)),
DefaultImageSpoiler().frame(_spoiler->index(crl::now(), false)),
DefaultImageSpoiler().frame(_spoiler->index(crl::now(), paused)),
_cornerCache);
} else if (_isVideo) {
paintPlayVideo(p, rect);

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/chat_theme.h"
#include "ui/image/image_prepare.h"
#include "ui/power_saving.h"
#include "ui/ui_utility.h"
#include "ui/chat/message_bubble.h"
#include "ui/chat/chat_style.h"
@ -519,7 +520,7 @@ void ChatTheme::clearBackgroundState() {
bool ChatTheme::readyForBackgroundRotation() const {
Expects(_cacheBackgroundTimer.has_value());
return !anim::Disabled()
return !On(PowerSaving::kChatBackground)
&& !_backgroundFade.animating()
&& !_cacheBackgroundTimer->isActive()
&& !_backgroundState.now.pixmap.isNull();
@ -528,10 +529,8 @@ bool ChatTheme::readyForBackgroundRotation() const {
void ChatTheme::generateNextBackgroundRotation() {
if (_backgroundCachingRequest
|| !_backgroundNext.image.isNull()
|| !readyForBackgroundRotation()) {
return;
}
if (background().colors.size() < 3) {
|| !readyForBackgroundRotation()
|| background().colors.size() < 3) {
return;
}
constexpr auto kAddRotationDoubled = (720 - 45);

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/paint/blobs.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "base/random.h"
#include "styles/style_chat.h"
@ -116,10 +117,10 @@ GroupCallUserpics::GroupCallUserpics(
});
rpl::combine(
rpl::single(anim::Disabled()) | rpl::then(anim::Disables()),
PowerSaving::Value(PowerSaving::kCalls),
std::move(hideBlobs)
) | 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 && _speakingAnimationHideLastTime)) {
_speakingAnimationHideLastTime = hide ? crl::now() : 0;

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_options.h"
#include "ui/image/image_prepare.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "styles/style_chat.h"
#include "styles/palette.h"
@ -378,6 +379,7 @@ void MessageBar::paint(Painter &p) {
: (shiftTo + shiftFull);
const auto now = crl::now();
const auto paused = p.inactive();
const auto pausedSpoiler = paused || On(PowerSaving::kChatSpoiler);
paintLeftBar(p);
@ -389,7 +391,7 @@ void MessageBar::paint(Painter &p) {
_image,
_spoiler.get(),
now,
paused);
pausedSpoiler);
}
} else if (!_animation->imageTo.isNull()
|| (!_animation->imageFrom.isNull()
@ -413,7 +415,7 @@ void MessageBar::paint(Painter &p) {
_animation->imageFrom,
_animation->spoilerFrom.get(),
now,
paused);
pausedSpoiler);
p.setOpacity(progress);
paintImageWithSpoiler(
p,
@ -421,7 +423,7 @@ void MessageBar::paint(Painter &p) {
_animation->imageTo,
_spoiler.get(),
now,
paused);
pausedSpoiler);
p.setOpacity(1.);
} else {
paintImageWithSpoiler(
@ -430,7 +432,7 @@ void MessageBar::paint(Painter &p) {
_image,
_spoiler.get(),
now,
paused);
pausedSpoiler);
}
}
if (!_animation || _animation->bodyAnimation == BodyAnimation::None) {
@ -452,7 +454,8 @@ void MessageBar::paint(Painter &p) {
.palette = &_st.textPalette,
.spoiler = Ui::Text::DefaultSpoilerCache(),
.now = now,
.paused = paused,
.pausedEmoji = paused || On(PowerSaving::kEmojiChat),
.pausedSpoiler = pausedSpoiler,
.elisionLines = 1,
});
}

View File

@ -10,6 +10,7 @@
#include "ui/abstract_button.h"
#include "ui/paint/blobs.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "ui/widgets/call_button.h"
#include "ui/widgets/labels.h"
#include "base/random.h"
@ -516,15 +517,13 @@ CallMuteButton::CallMuteButton(
parent,
_st->active.bgSize,
rpl::combine(
rpl::single(anim::Disabled()) | rpl::then(anim::Disables()),
PowerSaving::Value(PowerSaving::kCalls),
std::move(hideBlobs),
_state.value(
) | rpl::map([](const CallMuteButtonState &state) {
return IsInactive(state.type);
})
) | rpl::map([](bool animDisabled, bool hide, bool isBadState) {
return isBadState || !(!animDisabled && !hide);
})))
) | rpl::map(rpl::mappers::_1 || rpl::mappers::_2 || rpl::mappers::_3)))
, _content(base::make_unique_q<AbstractButton>(parent))
, _colors(Colors())
, _iconState(iconStateFrom(initial.type)) {

View File

@ -0,0 +1,46 @@
/*
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 "ui/power_saving.h"
namespace PowerSaving {
namespace {
Flags Data/* = {}*/;
rpl::event_stream<> Events;
} // namespace
Flags Current() {
return Data;
}
void Set(Flags flags) {
if (const auto diff = Data ^ flags) {
Data = flags;
if (diff & kAnimations) {
anim::SetDisabled(On(kAnimations));
}
Events.fire({});
}
}
rpl::producer<Flags> Changes() {
return Events.events() | rpl::map(Current);
}
rpl::producer<Flags> Value() {
return rpl::single(Current()) | rpl::then(Changes());
}
rpl::producer<bool> Value(Flag flag) {
return Value() | rpl::map([=](Flags flags) {
return (flags & flag) != 0;
}) | rpl::distinct_until_changed();
}
} // namespace PowerSaving

View File

@ -0,0 +1,38 @@
/*
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
*/
#pragma once
namespace PowerSaving {
enum Flag : uint32 {
kAnimations = (1U << 0),
kStickersPanel = (1U << 1),
kStickersChat = (1U << 2),
kEmojiPanel = (1U << 3),
kEmojiReactions = (1U << 4),
kEmojiChat = (1U << 5),
kChatBackground = (1U << 6),
kChatSpoiler = (1U << 7),
kCalls = (1U << 8),
kAll = (1U << 9) - 1,
};
inline constexpr bool is_flag_type(Flag) { return true; }
using Flags = base::flags<Flag>;
[[nodiscard]] Flags Current();
[[nodiscard]] rpl::producer<Flags> Changes();
[[nodiscard]] rpl::producer<Flags> Value();
[[nodiscard]] rpl::producer<bool> Value(Flag flag);
[[nodiscard]] void Set(Flags flags);
[[nodiscard]] inline bool On(Flag flag) {
return Current() & flag;
}
} // namespace PowerSaving

View File

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/emoji_config.h"
#include "ui/empty_userpic.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "ui/ui_utility.h"
#include "data/data_session.h"
#include "data/data_forum_topic.h"
@ -825,6 +826,8 @@ void Notification::paintTitle(Painter &p) {
.availableWidth = _titleRect.width(),
.palette = &st::dialogsTextPalette,
.spoiler = Ui::Text::DefaultSpoilerCache(),
.pausedEmoji = On(PowerSaving::kEmojiChat),
.pausedSpoiler = On(PowerSaving::kChatSpoiler),
.elisionLines = 1,
});
}
@ -837,6 +840,8 @@ void Notification::paintText(Painter &p) {
.availableWidth = _textRect.width(),
.palette = &st::dialogsTextPalette,
.spoiler = Ui::Text::DefaultSpoilerCache(),
.pausedEmoji = On(PowerSaving::kEmojiChat),
.pausedSpoiler = On(PowerSaving::kChatSpoiler),
.elisionLines = _textRect.height() / st::dialogsTextFont->height,
});
}

View File

@ -303,6 +303,8 @@ PRIVATE
ui/empty_userpic.h
ui/grouped_layout.cpp
ui/grouped_layout.h
ui/power_saving.cpp
ui/power_saving.h
ui/unread_badge_paint.cpp
ui/unread_badge_paint.h
ui/userpic_view.cpp