Skip to content

Commit db0e768

Browse files
committed
Proper sleep operation on systems with connected standby enabled
Standard API for sleep (`SetSuspendState`) seems to do nothing on systems with connected standby. Windows start menu calls `NtPowerInformation(ScreenOff)` on such systems instead. This is implemented in `shutdownux!ShutdownViewModel::_InitiatePowerTransition` function. Fixes #719
1 parent 23a1dc7 commit db0e768

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Src/StartMenu/StartMenuDLL/MenuCommands.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,33 @@ class ExitGuard
663663
#endif
664664
#define EWX_INSTALL_UPDATES 0x00100000 // undocumented switch to install updates on shutdown
665665

666+
NTSTATUS
667+
NTAPI
668+
NtPowerInformation(
669+
_In_ POWER_INFORMATION_LEVEL InformationLevel,
670+
_In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer,
671+
_In_ ULONG InputBufferLength,
672+
_Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
673+
_In_ ULONG OutputBufferLength
674+
);
675+
676+
static bool ConnectedStandby()
677+
{
678+
SYSTEM_POWER_CAPABILITIES powerCaps{};
679+
GetPwrCapabilities(&powerCaps);
680+
681+
if (powerCaps.AoAc)
682+
{
683+
static auto pNtPowerInformation = static_cast<decltype(&NtPowerInformation)>((void*)GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtPowerInformation"));
684+
if (pNtPowerInformation)
685+
pNtPowerInformation(ScreenOff, NULL, 0, NULL, 0);
686+
687+
return true;
688+
}
689+
690+
return false;
691+
}
692+
666693
static bool ExecuteSysCommand( TMenuID menuCommand )
667694
{
668695
CComPtr<IShellDispatch2> pShellDisp;
@@ -885,7 +912,8 @@ static bool ExecuteSysCommand( TMenuID menuCommand )
885912
WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,FALSE);
886913
Sleep(250);
887914
}
888-
CreateThread(NULL,0,SleepThread,(void*)FALSE,0,NULL);
915+
if (!ConnectedStandby())
916+
CreateThread(NULL,0,SleepThread,(void*)FALSE,0,NULL);
889917
return true;
890918

891919
case MENU_HIBERNATE:

0 commit comments

Comments
 (0)