| 1 |
/* |
| 2 |
* Copyright (C) 2009-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 |
#include "Win32DPMSSupport.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "rendering/dx/RenderContext.h" |
| 13 |
#include "utils/log.h" |
| 14 |
#include "windowing/GraphicContext.h" |
| 15 |
#include "windowing/windows/WinSystemWin32.h" |
| 16 |
|
| 17 |
CWin32DPMSSupport::CWin32DPMSSupport() |
| 18 |
{ |
| 19 |
m_supportedModes.push_back(OFF); |
| 20 |
m_supportedModes.push_back(STANDBY); |
| 21 |
} |
| 22 |
|
| 23 |
bool CWin32DPMSSupport::EnablePowerSaving(PowerSavingMode mode) |
| 24 |
{ |
| 25 |
auto winSystem = dynamic_cast<CWinSystemWin32*>(CServiceBroker::GetWinSystem()); |
| 26 |
if (!winSystem) |
| 27 |
return false; |
| 28 |
|
| 29 |
if (!winSystem->GetGfxContext().IsFullScreenRoot()) |
| 30 |
{ |
| 31 |
CLog::Log(LOGDEBUG, "DPMS: not in fullscreen, power saving disabled"); |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
switch (mode) |
| 36 |
{ |
| 37 |
case OFF: |
| 38 |
// Turn off display |
| 39 |
return SendMessage(DX::Windowing()->GetHwnd(), WM_SYSCOMMAND, SC_MONITORPOWER, static_cast<LPARAM>(2)) == 0; |
| 40 |
case STANDBY: |
| 41 |
// Set display to low power |
| 42 |
return SendMessage(DX::Windowing()->GetHwnd(), WM_SYSCOMMAND, SC_MONITORPOWER, static_cast<LPARAM>(1)) == 0; |
| 43 |
default: |
| 44 |
return true; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
bool CWin32DPMSSupport::DisablePowerSaving() |
| 49 |
{ |
| 50 |
// Turn display on |
| 51 |
return SendMessage(DX::Windowing()->GetHwnd(), WM_SYSCOMMAND, SC_MONITORPOWER, static_cast<LPARAM>(-1)) == 0; |
| 52 |
} |