From fec7e87c21b2c5f26468157b64a119e900b6530e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Sat, 10 Dec 2022 10:18:21 +0100 Subject: [PATCH] Detect SAS (Secure Attention Sequence) in a way that does not prevent screen sleep --- RELEASE.md | 1 + SteamController/Context.cs | 1 + SteamController/Controller.cs | 5 ++-- SteamController/Devices/MouseController.cs | 32 +--------------------- SteamController/Managers/SASManager.cs | 13 +++++++++ SteamController/Profiles/DesktopProfile.cs | 11 ++++---- SteamController/Profiles/X360Profile.cs | 2 +- 7 files changed, 26 insertions(+), 39 deletions(-) create mode 100644 SteamController/Managers/SASManager.cs diff --git a/RELEASE.md b/RELEASE.md index 5ce5fbd..c3b574b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -18,3 +18,4 @@ - Automatically manage steam controller configs when using Steam Input - Allow to assign BackPanel keys to X360 controller (breaks all current configs to set mappings) - All SteamDeckTools settings are stored in `.ini` file in root folder +- Detect SAS (Secure Attention Sequence) in a way that does not prevent screen sleep diff --git a/SteamController/Context.cs b/SteamController/Context.cs index eb4a652..9559775 100644 --- a/SteamController/Context.cs +++ b/SteamController/Context.cs @@ -41,6 +41,7 @@ namespace SteamController } public bool RequestEnable { get; set; } = true; + public bool KeyboardMouseValid { get; set; } = true; public ContextState State; public event Action ProfileChanged; diff --git a/SteamController/Controller.cs b/SteamController/Controller.cs index 2b2e4fb..224a67a 100644 --- a/SteamController/Controller.cs +++ b/SteamController/Controller.cs @@ -28,7 +28,8 @@ namespace SteamController new Managers.SteamManager(), new Managers.ProfileSwitcher(), new Managers.SteamConfigsManager(), - new Managers.SharedDataManager() + new Managers.SharedDataManager(), + new Managers.SASManager() } }; @@ -141,7 +142,7 @@ namespace SteamController var isDesktop = context.CurrentProfile?.IsDesktop ?? false; - if (!context.Mouse.Valid) + if (!context.KeyboardMouseValid) { notifyIcon.Text = TitleWithVersion + ". Cannot send input."; notifyIcon.Icon = Resources.microsoft_xbox_controller_off_red; diff --git a/SteamController/Devices/MouseController.cs b/SteamController/Devices/MouseController.cs index 09ec081..4364f0f 100644 --- a/SteamController/Devices/MouseController.cs +++ b/SteamController/Devices/MouseController.cs @@ -37,7 +37,6 @@ namespace SteamController.Devices // TODO: Unsure what it is public const int XButtonID = 0; public const int YButtonID = 1; - public const int UpdateValidInterval = 100; InputSimulator simulator = new InputSimulator(); @@ -46,9 +45,6 @@ namespace SteamController.Devices Accum movedX, movedY, verticalScroll, horizontalScroll; - bool? valid = null; - DateTime lastValid = DateTime.Now; - public enum Button { Left, @@ -68,11 +64,6 @@ namespace SteamController.Devices } } - public bool Valid - { - get { return valid ?? true; } - } - public Button[] DownButtons { get { return mouseButtons.ToArray(); } @@ -90,29 +81,10 @@ namespace SteamController.Devices { try { - if (action()) - { - valid = true; - lastValid = DateTime.Now; - } - + action(); } catch (InvalidOperationException) { - valid = false; - lastValid = DateTime.Now; - } - } - - private void UpdateValid() - { - if (valid is null || lastValid.AddMilliseconds(UpdateValidInterval) < DateTime.Now) - { - Safe(() => - { - simulator.Mouse.MoveMouseBy(0, 0); - return true; - }); } } @@ -235,8 +207,6 @@ namespace SteamController.Devices }); } } - - UpdateValid(); } public void MouseClick(Button button) diff --git a/SteamController/Managers/SASManager.cs b/SteamController/Managers/SASManager.cs new file mode 100644 index 0000000..74fe3e8 --- /dev/null +++ b/SteamController/Managers/SASManager.cs @@ -0,0 +1,13 @@ +using System.Diagnostics; +using SteamController.Helpers; + +namespace SteamController.Managers +{ + public sealed class SASManager : Manager + { + public override void Tick(Context context) + { + context.KeyboardMouseValid = ForegroundProcess.Find() is not null; + } + } +} diff --git a/SteamController/Profiles/DesktopProfile.cs b/SteamController/Profiles/DesktopProfile.cs index 00c9b08..cc65977 100644 --- a/SteamController/Profiles/DesktopProfile.cs +++ b/SteamController/Profiles/DesktopProfile.cs @@ -28,17 +28,18 @@ namespace SteamController.Profiles return Status.Done; } - if (!c.Mouse.Valid) + if (!c.KeyboardMouseValid) { // Failed to acquire secure context // Enable emergency Lizard c.Steam.LizardButtons = true; c.Steam.LizardMouse = true; - return Status.Done; } - - c.Steam.LizardButtons = SteamModeLizardButtons; - c.Steam.LizardMouse = SteamModeLizardMouse; + else + { + c.Steam.LizardButtons = SteamModeLizardButtons; + c.Steam.LizardMouse = SteamModeLizardMouse; + } EmulateScrollOnLPad(c); EmulateScrollOnLStick(c); diff --git a/SteamController/Profiles/X360Profile.cs b/SteamController/Profiles/X360Profile.cs index 3b5ea40..6e59c16 100644 --- a/SteamController/Profiles/X360Profile.cs +++ b/SteamController/Profiles/X360Profile.cs @@ -6,7 +6,7 @@ namespace SteamController.Profiles { public override bool Selected(Context context) { - return context.Enabled && context.X360.Valid && context.Mouse.Valid && !context.State.SteamUsesSteamInput; + return context.Enabled && context.X360.Valid && context.KeyboardMouseValid && !context.State.SteamUsesSteamInput; } internal override ProfilesSettings.BackPanelSettings BackPanelSettings