[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / windowing / X11 / X11DPMSSupport.cpp
blob7512bfa63ceed025cb60e37bf65000b3650ecb2f
1 /*
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.
7 */
9 #include "X11DPMSSupport.h"
11 #include "ServiceBroker.h"
12 #include "utils/log.h"
13 #include "windowing/X11/WinSystemX11.h"
15 #include <X11/Xlib.h>
16 #include <X11/extensions/dpms.h>
18 using namespace KODI::WINDOWING::X11;
20 namespace
22 // Mapping of PowerSavingMode to X11's mode constants.
23 const CARD16 X_DPMS_MODES[] =
25 DPMSModeStandby,
26 DPMSModeSuspend,
27 DPMSModeOff
31 CX11DPMSSupport::CX11DPMSSupport()
33 CWinSystemX11* winSystem = dynamic_cast<CWinSystemX11*>(CServiceBroker::GetWinSystem());
34 if (!winSystem)
35 return;
37 Display* dpy = winSystem->GetDisplay();
38 if (!dpy)
39 return;
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");
45 return;
48 if (!DPMSCapable(dpy))
50 CLog::Log(LOGINFO, "DPMS: display does not support power-saving");
51 return;
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());
62 if (!winSystem)
63 return false;
65 Display* dpy = winSystem->GetDisplay();
66 if (!dpy)
67 return false;
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.
71 DPMSEnable(dpy);
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.
75 XFlush(dpy);
76 return true;
79 bool CX11DPMSSupport::DisablePowerSaving()
81 CWinSystemX11* winSystem = dynamic_cast<CWinSystemX11*>(CServiceBroker::GetWinSystem());
82 if (!winSystem)
83 return false;
85 Display* dpy = winSystem->GetDisplay();
86 if (!dpy)
87 return false;
89 DPMSForceLevel(dpy, DPMSModeOn);
90 DPMSDisable(dpy);
91 XFlush(dpy);
93 winSystem->RecreateWindow();
95 return true;