Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep behaves differently on Connected/Modern Standby #719

Closed
Gaurav-Original-ClassicShellTester opened this issue May 15, 2021 · 2 comments
Assignees

Comments

@Gaurav-Original-ClassicShellTester

On PCs which have Modern Standby/Connected Standby, Sleep command from Open Shell menu is making them turn off (or hibernate? I don't know) but it's definitely not entering just Sleep. Running Windows 10 20H2.

@axobarcala
Copy link

axobarcala commented May 18, 2021

TL;DR: The behavior of Open-Shell’s sleep button varies depending upon the enabled sleep state(s). On systems with enabled "Modern Standby" (S0 Low Power Idle) the sleep state can be invoked by turning off the display programmatically [0] [1]

This issue already has been raised here: #387

I’ll try to describe the issue in detail, hopefully this should allow the devs to reproduce the issue this time. Since the sleep state behavior highly differentiates between system configurations (OS/BIOS, settings/versions), this might only apply to systems similar to my setup (Dell XPS 13 9365 on Win10 20H2).

Check if "Modern Standby" is enabled on system:

C:\Windows\System32>powercfg /a
The following sleep states are available on this system:
    Standby (S0 Low Power Idle) Network Disconnected
    Hibernate
<truncated>

Behavior with "Modern Standby" and "Hibernate" available (=enabled) on the system:

  • If "Sleep" is invoked from the Open-Shell menu the system will enter "Hibernate"
  • If "Sleep" is invoked from the Windows Start Menu the system will enter "Modern Standby"

Behavior with only "Modern Standby" available (=enabled) on the system:

  • If "Sleep" is invoked from the Open-Shell menu the system will do nothing
  • If "Sleep" is invoked from the Windows Start Menu the system will enter "Modern Standby"

Note: Just to clarify, this mess is due to the poor "Modern Standby" implementation by MS. Open-Shell’s behavior to enter standby, hibernate or do nothing, depending upon the sleep state configuration, is consistent with other tools, e.g. "nircmd standby" or just running "rundll32.exe powrprof.dll,SetSuspendState 0,1,0" from the command line.

Test workaround:

  • Check if the system is able to enter "Modern Standby" from command shell. Run the following in the command shell (cmd.exe not powershell)
    powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)

Note: This is the same as using the "Sleep" command from the Windows Start Menu. The system should turn off the display and a few seconds later enter standby. It’s necessary that no devices (e.g. mouse) are prohibiting the system from entering standby. Entering "Modern Standby", at least on my system, can be super finicky, due to a attached mouse. Apart from the obvious, to check if the system entered the sleep state successfully, you might want to run "powercfg -SleepStudy" afterwards.

Workaround for start menu "Classic style" and "Classic with two columns"

  • Customize the start menu and edit the existing "Sleep" entry by replacing the command with "monitor_off"

Workaround for start menu "Windows 7 style"

  • Add custom start menu entry with command "monitor_off"

Proposed solution:

  • Add an option to the Open-Shell shutdown menu to replace the currently used standby function with a display sleep function for the "Sleep" button.

Ref:
[0] putting-pc-into-sleep-mode-programmatically
[1] turn-off-display-in-windows-on-command

ge0rdi added a commit that referenced this issue Dec 21, 2022
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
ge0rdi added a commit that referenced this issue Dec 21, 2022
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
ge0rdi added a commit that referenced this issue Dec 23, 2022
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
ge0rdi added a commit that referenced this issue Dec 23, 2022
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
ge0rdi added a commit that referenced this issue Dec 24, 2022
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
ge0rdi added a commit that referenced this issue Dec 25, 2022
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
ge0rdi added a commit that referenced this issue Dec 27, 2022
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
@ge0rdi ge0rdi self-assigned this Dec 27, 2022
@ge0rdi ge0rdi closed this as completed in db0e768 Dec 28, 2022
@ge0rdi
Copy link
Member

ge0rdi commented Dec 28, 2022

Should be fixed in latest build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants