2 * Copyright (C) 2009-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.
9 #include "X11DPMSSupport.h"
11 #include "ServiceBroker.h"
12 #include "utils/log.h"
13 #include "windowing/X11/WinSystemX11.h"
16 #include <X11/extensions/dpms.h>
18 using namespace KODI::WINDOWING::X11
;
22 // Mapping of PowerSavingMode to X11's mode constants.
23 const CARD16 X_DPMS_MODES
[] =
31 CX11DPMSSupport::CX11DPMSSupport()
33 CWinSystemX11
* winSystem
= dynamic_cast<CWinSystemX11
*>(CServiceBroker::GetWinSystem());
37 Display
* dpy
= winSystem
->GetDisplay();
41 int event_base
, error_base
; // we ignore these
42 if (!DPMSQueryExtension(dpy
, &event_base
, &error_base
))
44 CLog::Log(LOGINFO
, "DPMS: X11 extension not present, power-saving will not be available");
48 if (!DPMSCapable(dpy
))
50 CLog::Log(LOGINFO
, "DPMS: display does not support power-saving");
54 m_supportedModes
.push_back(SUSPEND
); // best compromise
55 m_supportedModes
.push_back(OFF
); // next best
56 m_supportedModes
.push_back(STANDBY
); // rather lame, < 80% power according to DPMS spec
59 bool CX11DPMSSupport::EnablePowerSaving(PowerSavingMode mode
)
61 CWinSystemX11
* winSystem
= dynamic_cast<CWinSystemX11
*>(CServiceBroker::GetWinSystem());
65 Display
* dpy
= winSystem
->GetDisplay();
69 // This is not needed on my ATI Radeon, but the docs say that DPMSForceLevel
70 // after a DPMSDisable (from SDL) should not normally work.
72 DPMSForceLevel(dpy
, X_DPMS_MODES
[mode
]);
73 // There shouldn't be any errors if we called DPMSEnable; if they do happen,
74 // they're asynchronous and messy to detect.
79 bool CX11DPMSSupport::DisablePowerSaving()
81 CWinSystemX11
* winSystem
= dynamic_cast<CWinSystemX11
*>(CServiceBroker::GetWinSystem());
85 Display
* dpy
= winSystem
->GetDisplay();
89 DPMSForceLevel(dpy
, DPMSModeOn
);
93 winSystem
->RecreateWindow();