From 39f94ef8d381014f8351fe139ef1f953537d9eae Mon Sep 17 00:00:00 2001 From: mika-n Date: Sun, 29 Dec 2019 01:34:41 +0200 Subject: [PATCH] Added "Revert to default profile on unknown process" option to auto-profile screen. If this is enabled then DS4Windows will revert back to default profile when an unknown process is the foreground app. If this option is unchecked then DS4Windows leaves the current profile as active on unknown foreground processes. --- DS4Windows/AutoProfileChecker.cs | 14 +++++++++++--- DS4Windows/DS4Control/ScpUtil.cs | 12 ++++++++++++ DS4Windows/DS4Forms/AutoProfiles.xaml | 1 + DS4Windows/DS4Forms/AutoProfiles.xaml.cs | 2 ++ DS4Windows/DS4Forms/MainWindow.xaml.cs | 4 +--- .../DS4Forms/ViewModels/AutoProfilesViewModel.cs | 6 ++++++ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/DS4Windows/AutoProfileChecker.cs b/DS4Windows/AutoProfileChecker.cs index b03130b..e2e28af 100644 --- a/DS4Windows/AutoProfileChecker.cs +++ b/DS4Windows/AutoProfileChecker.cs @@ -99,10 +99,18 @@ namespace DS4WinWPF { if (Global.useTempProfile[j]) { - if (autoProfileDebugLogLevel > 0) - DS4Windows.AppLogger.LogToGui($"DEBUG: Auto-Profile. RestoreProfile Controller {j + 1}={Global.ProfilePath[j]} (default)", false); + if (DS4Windows.Global.AutoProfileRevertDefaultProfile) + { + if (autoProfileDebugLogLevel > 0) + DS4Windows.AppLogger.LogToGui($"DEBUG: Auto-Profile. Unknown process. Reverting to default profile. Controller {j + 1}={Global.ProfilePath[j]} (default)", false); - Global.LoadProfile(j, false, Program.rootHub); + Global.LoadProfile(j, false, Program.rootHub); + } + else + { + if (autoProfileDebugLogLevel > 0) + DS4Windows.AppLogger.LogToGui($"DEBUG: Auto-Profile. Unknown process. Existing profile left as active. Controller {j + 1}={Global.tempprofilename[j]}", false); + } } } diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 32d93b2..904c429 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -966,6 +966,12 @@ namespace DS4Windows get { return m_Config.customSteamFolder; } } + public static bool AutoProfileRevertDefaultProfile + { + set { m_Config.autoProfileRevertDefaultProfile = value; } + get { return m_Config.autoProfileRevertDefaultProfile; } + } + // controller/profile specfic values public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity; @@ -2209,6 +2215,9 @@ namespace DS4Windows OutContType.X360, OutContType.X360, OutContType.X360, OutContType.X360 }; + // TRUE=AutoProfile reverts to default profile if current foreground process is unknown, FALSE=Leave existing profile active when a foreground proces is unknown (ie. no matching auto-profile rule) + public bool autoProfileRevertDefaultProfile = true; + bool tempBool = false; public BackingStore() @@ -3960,6 +3969,8 @@ namespace DS4Windows catch { missingSetting = true; } try { Item = m_Xdoc.SelectSingleNode("/Profile/CustomSteamFolder"); customSteamFolder = Item.InnerText; } catch { missingSetting = true; } + try { Item = m_Xdoc.SelectSingleNode("/Profile/AutoProfileRevertDefaultProfile"); Boolean.TryParse(Item.InnerText, out autoProfileRevertDefaultProfile); } + catch { missingSetting = true; } for (int i = 0; i < 4; i++) { @@ -4032,6 +4043,7 @@ namespace DS4Windows XmlNode xmlUDPServListenAddress = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerListenAddress", null); xmlUDPServListenAddress.InnerText = udpServListenAddress; Node.AppendChild(xmlUDPServListenAddress); XmlNode xmlUseCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "UseCustomSteamFolder", null); xmlUseCustomSteamFolder.InnerText = useCustomSteamFolder.ToString(); Node.AppendChild(xmlUseCustomSteamFolder); XmlNode xmlCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "CustomSteamFolder", null); xmlCustomSteamFolder.InnerText = customSteamFolder; Node.AppendChild(xmlCustomSteamFolder); + XmlNode xmlAutoProfileRevertDefaultProfile = m_Xdoc.CreateNode(XmlNodeType.Element, "AutoProfileRevertDefaultProfile", null); xmlAutoProfileRevertDefaultProfile.InnerText = autoProfileRevertDefaultProfile.ToString(); Node.AppendChild(xmlAutoProfileRevertDefaultProfile); for (int i = 0; i < 4; i++) { diff --git a/DS4Windows/DS4Forms/AutoProfiles.xaml b/DS4Windows/DS4Forms/AutoProfiles.xaml index 90e6df4..6fc2e90 100644 --- a/DS4Windows/DS4Forms/AutoProfiles.xaml +++ b/DS4Windows/DS4Forms/AutoProfiles.xaml @@ -120,6 +120,7 @@ + diff --git a/DS4Windows/DS4Forms/AutoProfiles.xaml.cs b/DS4Windows/DS4Forms/AutoProfiles.xaml.cs index 2360442..bd99a40 100644 --- a/DS4Windows/DS4Forms/AutoProfiles.xaml.cs +++ b/DS4Windows/DS4Forms/AutoProfiles.xaml.cs @@ -67,6 +67,8 @@ namespace DS4WinWPF.DS4Forms programListLV.DataContext = autoProfVM; programListLV.ItemsSource = autoProfVM.ProgramColl; + revertDefaultProfileOnUnknownCk.DataContext = autoProfVM; + autoProfVM.SearchFinished += AutoProfVM_SearchFinished; autoProfVM.CurrentItemChange += AutoProfVM_CurrentItemChange; diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 619c208..484e8f6 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -45,7 +45,6 @@ namespace DS4WinWPF.DS4Forms private AutoProfileHolder autoProfileHolder; private NonFormTimer hotkeysTimer; private NonFormTimer autoProfilesTimer; - private static int autoProfileDebugLogLevel = 0; // 0=Dont log debug messages about active process and window titles to GUI Log screen. 1=Show debug log messages private AutoProfileChecker autoprofileChecker; private ProfileEditor editor; private bool preserveSize = true; @@ -346,8 +345,7 @@ Suspend support not enabled.", true); private void AutoProfControl_AutoDebugChanged(object sender, EventArgs e) { - autoprofileChecker.AutoProfileDebugLogLevel = - autoProfileDebugLogLevel = autoProfControl.AutoDebug == true ? 1 : 0; + autoprofileChecker.AutoProfileDebugLogLevel = autoProfControl.AutoDebug == true ? 1 : 0; } private void PowerEventArrive(object sender, EventArrivedEventArgs e) diff --git a/DS4Windows/DS4Forms/ViewModels/AutoProfilesViewModel.cs b/DS4Windows/DS4Forms/ViewModels/AutoProfilesViewModel.cs index 8c063c0..c9107c4 100644 --- a/DS4Windows/DS4Forms/ViewModels/AutoProfilesViewModel.cs +++ b/DS4Windows/DS4Forms/ViewModels/AutoProfilesViewModel.cs @@ -50,6 +50,12 @@ namespace DS4WinWPF.DS4Forms.ViewModels public delegate void AutoProfileStateHandler(AutoProfilesViewModel sender, bool state); public event AutoProfileStateHandler AutoProfileSystemChange; + public bool RevertDefaultProfileOnUnknown + { + get => DS4Windows.Global.AutoProfileRevertDefaultProfile; + set => DS4Windows.Global.AutoProfileRevertDefaultProfile = value; + } + public AutoProfilesViewModel(AutoProfileHolder autoProfileHolder, ProfileList profileList) { programColl = new ObservableCollection();