https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3a207cdf273976ac11ea7…
commit 3a207cdf273976ac11ea7bf21394b35b129bbc81
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Thu May 9 23:56:37 2019 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Thu May 9 23:56:37 2019 +0200
[POWERCFG] Fix-up the lid, power button and sleep button settings according to the
power capabilities.
---
dll/cpl/powercfg/advanced.c | 131 +++++++++++++++++++-------------------------
1 file changed, 55 insertions(+), 76 deletions(-)
diff --git a/dll/cpl/powercfg/advanced.c b/dll/cpl/powercfg/advanced.c
index 914afdb6c6..cc4bbff80c 100644
--- a/dll/cpl/powercfg/advanced.c
+++ b/dll/cpl/powercfg/advanced.c
@@ -94,7 +94,10 @@ IsBatteryUsed(VOID)
}
POWER_ACTION
-GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy)
+GetPowerActionFromPolicy(
+ POWER_ACTION_POLICY *Policy,
+ PSYSTEM_POWER_CAPABILITIES spc,
+ BOOL bIsLid)
{
POWER_ACTION poAction = PowerActionNone;
/*
@@ -132,6 +135,15 @@ GetPowerActionFromPolicy(POWER_ACTION_POLICY *Policy)
else
{
poAction = Policy->Action;
+ if ((poAction == PowerActionHibernate) && !(spc->SystemS4 &&
spc->HiberFilePresent))
+ poAction = PowerActionSleep;
+ if ((poAction == PowerActionSleep) && !(spc->SystemS1 ||
spc->SystemS2 || spc->SystemS3))
+ {
+ if (bIsLid)
+ poAction = PowerActionNone;
+ else
+ poAction = PowerActionShutdown;
+ }
}
return poAction;
@@ -141,12 +153,14 @@ VOID
ShowCurrentPowerActionPolicy(HWND hDlgCtrl,
POWER_ACTION *lpAction,
DWORD dwActionSize,
- POWER_ACTION_POLICY *Policy)
+ POWER_ACTION_POLICY *Policy,
+ PSYSTEM_POWER_CAPABILITIES spc,
+ BOOL bIsLid)
{
int poActionIndex;
POWER_ACTION poAction;
- poAction = GetPowerActionFromPolicy(Policy);
+ poAction = GetPowerActionFromPolicy(Policy, spc, bIsLid);
poActionIndex = FindActionIndex(lpAction, dwActionSize, poAction);
if (poActionIndex < 0)
@@ -176,12 +190,12 @@ SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl,
{
case PowerActionNone:
Policy->Action = PowerActionNone;
- Policy->EventCode = POWER_FORCE_TRIGGER_RESET;
+ Policy->EventCode = POWER_FORCE_TRIGGER_RESET;
break;
case PowerActionWarmEject:
Policy->Action = PowerActionNone;
- Policy->EventCode = POWER_USER_NOTIFY_BUTTON;
+ Policy->EventCode = POWER_USER_NOTIFY_BUTTON;
break;
case PowerActionShutdown:
@@ -208,90 +222,55 @@ SaveCurrentPowerActionPolicy(IN HWND hDlgCtrl,
//-------------------------------------------------------------------
VOID
-ShowCurrentPowerActionPolicies(HWND hwndDlg)
+ShowCurrentPowerActionPolicies(
+ HWND hwndDlg,
+ PSYSTEM_POWER_CAPABILITIES spc)
{
- TCHAR szAction[MAX_PATH];
-
if (!IsBatteryUsed())
{
-#if 0
- /* experimental code */
-// ShowCurrentPowerButtonAcAction(hList2,
- ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON),
- g_SystemBatteries,
- sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
- &gGPP.user.LidCloseAc);
-#else
- if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.LidCloseAc.Action,
szAction, MAX_PATH))
- {
- SendDlgItemMessage(hwndDlg, IDC_LIDCLOSE,
- CB_SELECTSTRING,
- TRUE,
- (LPARAM)szAction);
- }
-#endif
+ ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE),
+ g_SystemBatteries,
+ sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
+ &gGPP.user.LidCloseAc,
+ spc,
+ TRUE);
+
ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON),
- g_PowerButton,
- sizeof(g_PowerButton) / sizeof(POWER_ACTION),
- &gGPP.user.PowerButtonAc);
+ g_PowerButton,
+ sizeof(g_PowerButton) / sizeof(POWER_ACTION),
+ &gGPP.user.PowerButtonAc,
+ spc,
+ FALSE);
-#if 0
- /* experimental code */
ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON),
- g_SleepButton,
- sizeof(g_SleepButton) / sizeof(POWER_ACTION),
- &gGPP.user.SleepButtonAc);
-#else
- if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.SleepButtonAc.Action,
szAction, MAX_PATH))
- {
- SendDlgItemMessage(hwndDlg, IDC_SLEEPBUTTON,
- CB_SELECTSTRING,
- TRUE,
- (LPARAM)szAction);
- }
-#endif
+ g_SleepButton,
+ sizeof(g_SleepButton) / sizeof(POWER_ACTION),
+ &gGPP.user.SleepButtonAc,
+ spc,
+ FALSE);
}
else
{
-#if 0
-
ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_LIDCLOSE),
- g_SleepButton,
- sizeof(g_SleepButton) / sizeof(POWER_ACTION),
- &gGPP.user.LidCloseDc);
+ g_SystemBatteries,
+ sizeof(g_SystemBatteries) / sizeof(POWER_ACTION),
+ &gGPP.user.LidCloseDc,
+ spc,
+ TRUE);
ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_POWERBUTTON),
- g_SleepButton,
- sizeof(g_SleepButton) / sizeof(POWER_ACTION),
- &gGPP.user.PowerButtonDc);
+ g_PowerButton,
+ sizeof(g_PowerButton) / sizeof(POWER_ACTION),
+ &gGPP.user.PowerButtonDc,
+ spc,
+ FALSE);
ShowCurrentPowerActionPolicy(GetDlgItem(hwndDlg, IDC_SLEEPBUTTON),
- g_SleepButton,
- sizeof(g_SleepButton) / sizeof(POWER_ACTION),
- &gGPP.user.SleepButtonDc);
-#else
- if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.LidCloseDc.Action,
szAction, MAX_PATH))
- {
- SendDlgItemMessage(hwndDlg, IDC_LIDCLOSE,
- CB_SELECTSTRING,
- TRUE,
- (LPARAM)szAction);
- }
- if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.PowerButtonDc.Action,
szAction, MAX_PATH))
- {
- SendDlgItemMessage(hwndDlg, IDC_POWERBUTTON,
- CB_SELECTSTRING,
- TRUE,
- (LPARAM)szAction);
- }
- if (LoadString(hApplet, IDS_PowerActionNone1+gGPP.user.SleepButtonDc.Action,
szAction, MAX_PATH))
- {
- SendDlgItemMessage(hwndDlg, IDC_SLEEPBUTTON,
- CB_SELECTSTRING,
- TRUE,
- (LPARAM)szAction);
- }
-#endif
+ g_SleepButton,
+ sizeof(g_SleepButton) / sizeof(POWER_ACTION),
+ &gGPP.user.SleepButtonDc,
+ spc,
+ FALSE);
}
}
@@ -422,7 +401,7 @@ Adv_InitDialog(
if (ReadGlobalPwrPolicy(&gGPP))
{
- ShowCurrentPowerActionPolicies(hwndDlg);
+ ShowCurrentPowerActionPolicies(hwndDlg, &spc);
}
}