From 42a67143eaa4cbfa45df94f8237137d64afefd16 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 7 Jan 2018 11:44:04 -0600 Subject: [PATCH] Fix for device plugin changes while switching profiles --- DS4Windows/DS4Control/ScpUtil.cs | 41 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 4b80f7a..351ac5b 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -2031,6 +2031,9 @@ namespace DS4Windows else profilepath = propath; + bool xinputPlug = false; + bool xinputStatus = false; + if (File.Exists(profilepath)) { XmlNode Item; @@ -2385,25 +2388,17 @@ namespace DS4Windows { if (dinputOnly[device] == true) { - bool xinputResult = control.x360Bus.Unplug(device); - if (xinputResult) - { - int xinputIndex = control.x360Bus.FirstController + device; - Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false); - Global.useDInputOnly[device] = true; - } + Global.useDInputOnly[device] = true; + xinputPlug = false; + xinputStatus = true; //changed = true; } else if (synced && isAlive) { - bool xinputResult = control.x360Bus.Plugin(device); - if (xinputResult) - { - int xinputIndex = control.x360Bus.FirstController + device; - Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false); - Global.useDInputOnly[device] = false; - } + Global.useDInputOnly[device] = false; + xinputPlug = true; + xinputStatus = true; //changed = true; } @@ -2756,6 +2751,24 @@ namespace DS4Windows { tempDev.setIdleTimeout(idleDisconnectTimeout[device]); tempDev.setBTPollRate(btPollRate[device]); + if (xinputStatus && xinputPlug) + { + bool xinputResult = control.x360Bus.Plugin(device); + if (xinputResult) + { + int xinputIndex = control.x360Bus.FirstController + device; + Log.LogToGui("X360 Controller # " + xinputIndex + " connected", false); + } + } + else if (xinputStatus && !xinputPlug) + { + bool xinputResult = control.x360Bus.Unplug(device); + if (xinputResult) + { + int xinputIndex = control.x360Bus.FirstController + device; + Log.LogToGui("X360 Controller # " + xinputIndex + " unplugged", false); + } + } }); Program.rootHub.touchPad[device]?.ResetTrackAccel(trackballFriction[device]);