diff --git a/app/Helpers/ClamshellModeControl.cs b/app/Helpers/ClamshellModeControl.cs index 539b516c..9bc02461 100644 --- a/app/Helpers/ClamshellModeControl.cs +++ b/app/Helpers/ClamshellModeControl.cs @@ -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) diff --git a/app/Mode/PowerNative.cs b/app/Mode/PowerNative.cs index 06a65bb2..ae70ee60 100644 --- a/app/Mode/PowerNative.cs +++ b/app/Mode/PowerNative.cs @@ -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) { /**