2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "application/IApplicationComponent.h"
14 #include "powermanagement/WinIdleTimer.h"
16 #include "utils/Stopwatch.h"
17 #include "windowing/OSScreenSaver.h"
24 using AddonPtr
= std::shared_ptr
<IAddon
>;
31 * \brief Class handling application support for screensavers, dpms and shutdown timers.
34 class CApplicationPowerHandling
: public IApplicationComponent
36 friend class CApplication
;
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
; }
47 bool GetRenderGUI() const { return m_renderGUI
; }
48 void SetRenderGUI(bool renderGUI
);
51 void ResetSystemIdleTimer();
52 bool IsIdleShutdownInhibited() const;
54 void ResetShutdownTimers();
55 void StopShutdownTimer();
57 void ResetNavigationTimer();
59 bool IsDPMSActive() const { return m_dpmsIsActive
; }
60 bool ToggleDPMS(bool manual
);
62 // Wakes up from the screensaver and / or DPMS. Returns true if woken up.
63 bool WakeUpScreenSaverAndDPMS(bool bPowerOffKeyPressed
= false);
65 bool OnSettingChanged(const CSetting
& setting
);
66 bool OnSettingAction(const CSetting
& setting
);
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);
77 void InhibitIdleShutdown(bool inhibit
);
79 /*! \brief Helper method to determine how to handle TMSG_SHUTDOWN
81 void HandleShutdownMessage();
84 float NavigationIdleTime();
86 bool m_renderGUI
{false};
88 bool m_bInhibitScreenSaver
= false;
89 bool m_bResetScreenSaver
= false;
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
;
97 bool m_dpmsIsActive
= false;
98 bool m_dpmsIsManual
= false;
100 bool m_bInhibitIdleShutdown
= false;
101 CStopWatch m_navigationTimer
;
102 CStopWatch m_shutdownTimer
;
104 #ifdef TARGET_WINDOWS
105 CWinIdleTimer m_idleTimer
;
106 CWinIdleTimer m_screenSaverTimer
;
108 CStopWatch m_idleTimer
;
109 CStopWatch m_screenSaverTimer
;
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
;