power_saving.cpp 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "ui/power_saving.h"
  8. namespace PowerSaving {
  9. namespace {
  10. Flags Data/* = {}*/;
  11. rpl::event_stream<> Events;
  12. bool AllForced/* = false*/;
  13. } // namespace
  14. void Set(Flags flags) {
  15. if (const auto diff = Data ^ flags) {
  16. Data = flags;
  17. if (!AllForced) {
  18. if (diff & kAnimations) {
  19. anim::SetDisabled(On(kAnimations));
  20. }
  21. Events.fire({});
  22. }
  23. }
  24. }
  25. Flags Current() {
  26. return Data;
  27. }
  28. void SetForceAll(bool force) {
  29. if (AllForced == force) {
  30. return;
  31. }
  32. AllForced = force;
  33. if (const auto diff = Data ^ kAll) {
  34. if (diff & kAnimations) {
  35. anim::SetDisabled(On(kAnimations));
  36. }
  37. Events.fire({});
  38. }
  39. }
  40. bool ForceAll() {
  41. return AllForced;
  42. }
  43. rpl::producer<> Changes() {
  44. return Events.events();
  45. }
  46. } // namespace PowerSaving