From 9d04c0c1779c83cfbec30beeba2ead764403ff43 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 13:05:48 -0600 Subject: [PATCH 01/12] Changed scroll property of ScrollViewer controlling Axis Config tab Related to issue #948 --- DS4Windows/DS4Forms/ProfileEditor.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DS4Windows/DS4Forms/ProfileEditor.xaml b/DS4Windows/DS4Forms/ProfileEditor.xaml index 61bb2eb..9cb9b94 100644 --- a/DS4Windows/DS4Forms/ProfileEditor.xaml +++ b/DS4Windows/DS4Forms/ProfileEditor.xaml @@ -289,7 +289,7 @@ - + From ee34544f6ff41131690b1bf9a011786a19a121c8 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 15:00:37 -0600 Subject: [PATCH 02/12] Added extra locking in TrayIconViewModel --- .../DS4Forms/ViewModels/TrayIconViewModel.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs b/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs index f51a3f7..3d7297d 100644 --- a/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs +++ b/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; +using System.Threading; using System.Windows.Controls; using DS4Windows; @@ -42,6 +42,7 @@ namespace DS4WinWPF.DS4Forms.ViewModels public event EventHandler RequestOpen; public event EventHandler RequestMinimize; + private ReaderWriterLockSlim _colLocker = new ReaderWriterLockSlim(); private List controllerList = new List(); private ProfileList profileListHolder; private ControlService controlService; @@ -79,22 +80,28 @@ namespace DS4WinWPF.DS4Forms.ViewModels private void ClearControllerList(object sender, EventArgs e) { + _colLocker.EnterWriteLock(); controllerList.Clear(); + _colLocker.ExitWriteLock(); } private void UnhookEvents(object sender, EventArgs e) { + _colLocker.EnterReadLock(); foreach (ControllerHolder holder in controllerList) { DS4Device currentDev = holder.Device; RemoveDeviceEvents(currentDev); } + _colLocker.ExitReadLock(); } private void Service_HotplugController(ControlService sender, DS4Device device, int index) { SetupDeviceEvents(device); + _colLocker.EnterWriteLock(); controllerList.Add(new ControllerHolder(device, index)); + _colLocker.ExitWriteLock(); } private void ProfileListCol_CollectionChanged(object sender, @@ -115,6 +122,7 @@ namespace DS4WinWPF.DS4Forms.ViewModels MenuItem item; int idx = 0; + _colLocker.EnterReadLock(); foreach (ControllerHolder holder in controllerList) { DS4Device currentDev = holder.Device; @@ -156,6 +164,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels idx++; } + _colLocker.ExitReadLock(); + items.Add(item); items.Add(new Separator()); item = new MenuItem() { Header = "Open" }; @@ -188,7 +198,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels ProfileSelected?.Invoke(this, holder, item.Header.ToString()); } - private void DisconnectMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) + private void DisconnectMenuItem_Click(object sender, + System.Windows.RoutedEventArgs e) { MenuItem item = sender as MenuItem; int idx = Convert.ToInt32(item.Tag); @@ -214,11 +225,13 @@ namespace DS4WinWPF.DS4Forms.ViewModels { //IEnumerable devices = DS4Devices.getDS4Controllers(); int idx = 0; + _colLocker.EnterWriteLock(); foreach (DS4Device currentDev in controlService.slotManager.ControllerColl) { controllerList.Add(new ControllerHolder(currentDev, idx)); idx++; } + _colLocker.ExitWriteLock(); } private void StartPopulateText(object sender, EventArgs e) @@ -234,12 +247,14 @@ namespace DS4WinWPF.DS4Forms.ViewModels //IEnumerable devices = DS4Devices.getDS4Controllers(); int idx = 1; //foreach (DS4Device currentDev in devices) + _colLocker.EnterReadLock(); foreach (ControllerHolder holder in controllerList) { DS4Device currentDev = holder.Device; items.Add($"{idx}: {currentDev.ConnectionType} {currentDev.Battery}%{(currentDev.Charging ? "+" : "")}"); idx++; } + _colLocker.ExitReadLock(); TooltipText = string.Join("\n", items); } @@ -248,11 +263,13 @@ namespace DS4WinWPF.DS4Forms.ViewModels { //IEnumerable devices = DS4Devices.getDS4Controllers(); //foreach (DS4Device currentDev in devices) + _colLocker.EnterReadLock(); foreach (ControllerHolder holder in controllerList) { DS4Device currentDev = holder.Device; SetupDeviceEvents(currentDev); } + _colLocker.ExitReadLock(); } private void SetupDeviceEvents(DS4Device device) @@ -274,6 +291,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels DS4Device currentDev = sender as DS4Device; ControllerHolder item = null; int idx = 0; + + _colLocker.EnterWriteLock(); foreach (ControllerHolder holder in controllerList) { if (currentDev == holder.Device) @@ -291,6 +310,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels RemoveDeviceEvents(currentDev); PopulateToolText(); } + + _colLocker.ExitWriteLock(); } private void HookEvents(object sender, EventArgs e) From 63dfd8e194cd82feba4efe10e9f9a3cf4c2c7109 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 19:02:32 -0600 Subject: [PATCH 03/12] Fixed lock recursion issue with tray icon view model --- DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs b/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs index 3d7297d..a03cdc8 100644 --- a/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs +++ b/DS4Windows/DS4Forms/ViewModels/TrayIconViewModel.cs @@ -308,10 +308,11 @@ namespace DS4WinWPF.DS4Forms.ViewModels { controllerList.RemoveAt(idx); RemoveDeviceEvents(currentDev); - PopulateToolText(); } _colLocker.ExitWriteLock(); + + PopulateToolText(); } private void HookEvents(object sender, EventArgs e) From 4540e9c9ebb89343acbdc22d7967b50beae3dd13 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 20:30:18 -0600 Subject: [PATCH 04/12] Make sure Hide DS4 Controller checkbox is temporarily disabled after click --- DS4Windows/DS4Forms/MainWindow.xaml.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 21bfcd4..4132f9e 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -991,13 +991,15 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question private async void HideDS4ContCk_Click(object sender, RoutedEventArgs e) { StartStopBtn.IsEnabled = false; - bool checkStatus = hideDS4ContCk.IsChecked == true; + //bool checkStatus = hideDS4ContCk.IsChecked == true; + hideDS4ContCk.IsEnabled = false; await Task.Run(() => { App.rootHub.Stop(); App.rootHub.Start(); }); + hideDS4ContCk.IsEnabled = true; StartStopBtn.IsEnabled = true; } From b9342af23e5260a757a8ad508774cd2b534072fd Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 26 Dec 2019 20:41:09 -0600 Subject: [PATCH 05/12] Fixed sensitivity ranges in Profile Editor Related to issue #962 --- DS4Windows/DS4Forms/ProfileEditor.xaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DS4Windows/DS4Forms/ProfileEditor.xaml b/DS4Windows/DS4Forms/ProfileEditor.xaml index 9cb9b94..751dde4 100644 --- a/DS4Windows/DS4Forms/ProfileEditor.xaml +++ b/DS4Windows/DS4Forms/ProfileEditor.xaml @@ -333,9 +333,9 @@ Margin="{StaticResource spaceMargin}" />