Save lid action to config file during startup if user has set it to hibernate or shutdown.

This commit is contained in:
IceStormNG
2023-07-26 23:15:28 +02:00
parent e16a50f1f2
commit cff2c9af0b
2 changed files with 44 additions and 0 deletions

View File

@@ -6,6 +6,13 @@ namespace GHelper.Helpers
{
internal class ClamshellModeControl
{
public ClamshellModeControl()
{
//Save current setting if hibernate or shutdown to prevent reverting the user set option.
CheckAndSaveLidAction();
}
public bool IsExternalDisplayConnected()
{
var devices = ScreenInterrogatory.GetAllDevices().ToArray();
@@ -90,6 +97,21 @@ namespace GHelper.Helpers
ToggleLidAction();
}
private static int CheckAndSaveLidAction()
{
int val = PowerNative.GetLidAction(true);
//If it is 0 then it is likely already set by clamshell mdoe
//If 0 was set by the user, then why do they even use clamshell mode?
//We only care about hibernate or shutdown setting here
if (val == 2 || val == 3)
{
AppConfig.Set("clamshell_default_lid_action", val);
return val;
}
return 1;
}
//Power users can change that setting.
//0 = Do nothing
//1 = Sleep (default)

View File

@@ -167,6 +167,28 @@ namespace GHelper.Mode
}
}
public static int GetLidAction(bool ac)
{
Guid activeSchemeGuid = GetActiveScheme();
IntPtr activeIndex;
if (ac)
PowerReadACValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_SYSTEM_BUTTON_SUBGROUP,
GUID_LIDACTION, out activeIndex);
else
PowerReadDCValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_SYSTEM_BUTTON_SUBGROUP,
GUID_LIDACTION, out activeIndex);
return activeIndex.ToInt32();
}
public static void SetLidAction(int action, bool acOnly = false)
{
/**