xbmc
ApplicationPowerHandling.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "application/IApplicationComponent.h"
12 
13 #ifdef TARGET_WINDOWS
14 #include "powermanagement/WinIdleTimer.h"
15 #endif
16 #include "utils/Stopwatch.h"
17 #include "windowing/OSScreenSaver.h"
18 
19 #include <string>
20 
21 namespace ADDON
22 {
23 class IAddon;
24 using AddonPtr = std::shared_ptr<IAddon>;
25 } // namespace ADDON
26 
27 class CApplication;
28 class CSetting;
29 
35 {
36  friend class CApplication;
37 
38 public:
39  bool IsInScreenSaver() const { return m_screensaverActive; }
40  bool IsScreenSaverInhibited() const;
41  void ResetScreenSaver();
42  void SetScreenSaverLockFailed() { m_iScreenSaveLock = -1; }
43  void SetScreenSaverUnlocked() { m_iScreenSaveLock = 1; }
44  void StopScreenSaverTimer();
45  std::string ScreensaverIdInUse() const { return m_screensaverIdInUse; }
46 
47  bool GetRenderGUI() const { return m_renderGUI; }
48  void SetRenderGUI(bool renderGUI);
49 
50  int GlobalIdleTime();
51  void ResetSystemIdleTimer();
52  bool IsIdleShutdownInhibited() const;
53 
54  void ResetShutdownTimers();
55  void StopShutdownTimer();
56 
57  void ResetNavigationTimer();
58 
59  bool IsDPMSActive() const { return m_dpmsIsActive; }
60  bool ToggleDPMS(bool manual);
61 
62  // Wakes up from the screensaver and / or DPMS. Returns true if woken up.
63  bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed = false);
64 
65  bool OnSettingChanged(const CSetting& setting);
66  bool OnSettingAction(const CSetting& setting);
67 
68 protected:
69  void ActivateScreenSaver(bool forceType = false);
70  void CheckOSScreenSaverInhibitionSetting();
71  // Checks whether the screensaver and / or DPMS should become active.
72  void CheckScreenSaverAndDPMS();
73  void InhibitScreenSaver(bool inhibit);
74  void ResetScreenSaverTimer();
75  bool WakeUpScreenSaver(bool bPowerOffKeyPressed = false);
76 
77  void InhibitIdleShutdown(bool inhibit);
78 
81  void HandleShutdownMessage();
82  void CheckShutdown();
83 
84  float NavigationIdleTime();
85 
86  bool m_renderGUI{false};
87 
88  bool m_bInhibitScreenSaver = false;
89  bool m_bResetScreenSaver = false;
90  ADDON::AddonPtr
91  m_pythonScreenSaver; // @warning: Fallback for Python interface, for binaries not needed!
92  bool m_screensaverActive = false;
93  // -1 = failed, 0 = locked, 1 = unlocked, 2 = check in progress
94  int m_iScreenSaveLock = 0;
95  std::string m_screensaverIdInUse;
96 
97  bool m_dpmsIsActive = false;
98  bool m_dpmsIsManual = false;
99 
100  bool m_bInhibitIdleShutdown = false;
101  CStopWatch m_navigationTimer;
102  CStopWatch m_shutdownTimer;
103 
104 #ifdef TARGET_WINDOWS
105  CWinIdleTimer m_idleTimer;
106  CWinIdleTimer m_screenSaverTimer;
107 #else
108  CStopWatch m_idleTimer;
109  CStopWatch m_screenSaverTimer;
110 #endif
111 
112  // OS screen saver inhibitor that is always active if user selected a Kodi screen saver
113  KODI::WINDOWING::COSScreenSaverInhibitor m_globalScreensaverInhibitor;
114  // Inhibitor that is active e.g. during video playback
115  KODI::WINDOWING::COSScreenSaverInhibitor m_screensaverInhibitor;
116 };
Class handling application support for screensavers, dpms and shutdown timers.
Definition: ApplicationPowerHandling.h:34
Definition: Stopwatch.h:14
Inhibit the OS screen saver as long as this object is alive.
Definition: OSScreenSaver.h:31
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Definition: Application.h:84
Base class for application components.
Definition: IApplicationComponent.h:12
Definition: WinIdleTimer.h:13
void OnSettingChanged(const std::shared_ptr< const CSetting > &setting) override
The value of the given setting has changed.
Definition: ApplicationSettingsHandling.cpp:106
Definition: Addon.cpp:39
void OnSettingAction(const std::shared_ptr< const CSetting > &setting) override
The given setting has been activated.
Definition: ApplicationSettingsHandling.cpp:138