diff --git a/RELEASE.md b/RELEASE.md index d6eece1..44af668 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,3 +31,4 @@ It does help this project on being supported. - Merge `X360 with Haptic` into `X360` profile - Improve responsiveness of PowerControl (read input more frequently) - Fix selecting `DefaultProfile` on startup +- Detect GamePad UI open temporarily for controller layout diff --git a/SteamController/Helpers/ForegroundProcess.cs b/SteamController/Helpers/ForegroundProcess.cs index a4cfb59..b4ee703 100644 --- a/SteamController/Helpers/ForegroundProcess.cs +++ b/SteamController/Helpers/ForegroundProcess.cs @@ -30,12 +30,16 @@ namespace SteamController.Helpers return false; } } - public static Process? Find() + { + return Find(GetForegroundWindow()); + } + + public static Process? Find(IntPtr hWnd) { try { - var id = GetTopLevelProcessId(); + var id = GetProcessId(hWnd); if (id is null) return null; @@ -50,9 +54,11 @@ namespace SteamController.Helpers private static int? GetTopLevelProcessId() { - var hWnd = GetForegroundWindow(); - if (hWnd == IntPtr.Zero) - return null; + return GetProcessId(GetForegroundWindow()); + } + + private static int? GetProcessId(IntPtr hWnd) + { var result = GetWindowThreadProcessId(hWnd, out var processId); if (result != 0) return processId; diff --git a/SteamController/Helpers/SteamConfiguration.cs b/SteamController/Helpers/SteamConfiguration.cs index 63e9bba..33f3c78 100644 --- a/SteamController/Helpers/SteamConfiguration.cs +++ b/SteamController/Helpers/SteamConfiguration.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; +using System.Text; using System.Text.RegularExpressions; using Microsoft.Win32; @@ -54,13 +55,32 @@ namespace SteamController.Helpers get { var steamWindow = FindWindow("SDL_app", "SP"); - if (steamWindow == null) + if (steamWindow == IntPtr.Zero) return false; return GetForegroundWindow() == steamWindow; } } + public static bool IsPossibleGamePadUI + { + get + { + IntPtr hWnd = GetForegroundWindow(); + if (hWnd == IntPtr.Zero) + return false; + + StringBuilder className = new StringBuilder(256); + if (GetClassName(hWnd, className, className.Capacity) == 0) + return false; + + if (className.ToString() != "SDL_app") + return false; + + return ForegroundProcess.Find(hWnd)?.ProcessName == "steamwebhelper"; + } + } + public static String? SteamExe { get { return GetValue2(SteamKey, SteamExeValue); } @@ -374,5 +394,11 @@ namespace SteamController.Helpers [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); } } \ No newline at end of file diff --git a/SteamController/Managers/SteamConfigsManager.cs b/SteamController/Managers/SteamConfigsManager.cs index dc0420d..351f133 100644 --- a/SteamController/Managers/SteamConfigsManager.cs +++ b/SteamController/Managers/SteamConfigsManager.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using CommonHelpers; using SteamController.Helpers; namespace SteamController.Managers @@ -59,6 +60,8 @@ namespace SteamController.Managers if (!IsActive) return; + Log.TraceLine("SetSteamControllerFilesLock: {0}", lockConfigs); + if (lockConfigs) { foreach (var config in lockedSteamControllerFiles) diff --git a/SteamController/Managers/SteamManager.cs b/SteamController/Managers/SteamManager.cs index b15cf50..b60da35 100644 --- a/SteamController/Managers/SteamManager.cs +++ b/SteamController/Managers/SteamManager.cs @@ -75,6 +75,8 @@ namespace SteamController.Managers return "game"; if (SteamConfiguration.IsGamePadUI) return "gamepadui"; + if (SteamConfiguration.IsPossibleGamePadUI) + return "possiblegamepadui"; return null; } }