[host] windows: detect whether screensaver is disabled in the guest

This will allow us to add an option to disable the screensaver on the client
when an application in the guest requests it. This behaviour may be useful
when the guest is doing media playback.
This commit is contained in:
Quantum
2021-02-03 17:42:54 -05:00
committed by Geoffrey McRae
parent cc2104c699
commit 8e98f863b6
6 changed files with 35 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ target_link_libraries(platform_Windows
wtsapi32
psapi
shlwapi
powrprof
)
target_include_directories(platform_Windows

View File

@@ -25,6 +25,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <shellapi.h>
#include <shlwapi.h>
#include <fcntl.h>
#include <powrprof.h>
#include <ntstatus.h>
#include "interface/platform.h"
#include "common/debug.h"
@@ -397,3 +399,24 @@ HWND os_getMessageWnd(void)
{
return app.messageWnd;
}
bool os_blockScreensaver()
{
static bool lastResult = false;
static ULONGLONG lastCheck = 0;
ULONGLONG now = GetTickCount64();
if (now - lastCheck >= 1000)
{
ULONG executionState;
NTSTATUS status = CallNtPowerInformation(SystemExecutionState, NULL, 0,
&executionState, sizeof executionState);
if (status == STATUS_SUCCESS)
lastResult = executionState & ES_DISPLAY_REQUIRED;
else
DEBUG_ERROR("Failed to call CallNtPowerInformation(SystemExecutionState): %ld", status);
lastCheck = now;
}
return lastResult;
}