From 18bb83ceef83292884de4a416fabae681cbefeee Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 21 Mar 2018 17:31:22 -0500 Subject: [PATCH] Do not restart service when changing dinput option in profile Only plug or unplug an xinput device as needed. Only perform when saving a profile. --- DS4Windows/DS4Control/ControlService.cs | 21 +++++++++++++++++++++ DS4Windows/DS4Forms/Options.Designer.cs | 2 +- DS4Windows/DS4Forms/Options.cs | 23 ++++++++++++++++------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 3882e13..3b819ae 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -101,6 +101,27 @@ namespace DS4Windows catch { } } + public bool PlugXInputController(int index) + { + int xinputIndex = x360Bus.FirstController + index; + LogDebug("Plugging in X360 Controller #" + xinputIndex); + bool xinputResult = x360Bus.Plugin(index); + useDInputOnly[index] = false; + LogDebug("X360 Controller # " + xinputIndex + " connected"); + + return xinputResult; + } + + public bool UnplugXInputController(int index) + { + bool unplugResult = x360Bus.Unplug(index); + int xinputIndex = x360Bus.FirstController + index; + useDInputOnly[index] = true; + LogDebug("X360 Controller # " + xinputIndex + " unplugged"); + + return unplugResult; + } + public bool Start(object tempui, bool showlog = true) { if (x360Bus.Open() && x360Bus.Start()) diff --git a/DS4Windows/DS4Forms/Options.Designer.cs b/DS4Windows/DS4Forms/Options.Designer.cs index b89b325..40e92f1 100644 --- a/DS4Windows/DS4Forms/Options.Designer.cs +++ b/DS4Windows/DS4Forms/Options.Designer.cs @@ -1366,7 +1366,7 @@ resources.ApplyResources(this.cBDinput, "cBDinput"); this.cBDinput.Name = "cBDinput"; this.cBDinput.UseVisualStyleBackColor = true; - this.cBDinput.CheckedChanged += new System.EventHandler(this.cBDinput_CheckedChanged); + this.cBDinput.CheckedChanged += new System.EventHandler(this.CBDinput_CheckedChanged); // // pBProgram // diff --git a/DS4Windows/DS4Forms/Options.cs b/DS4Windows/DS4Forms/Options.cs index 7eca38c..ff9580a 100644 --- a/DS4Windows/DS4Forms/Options.cs +++ b/DS4Windows/DS4Forms/Options.cs @@ -1637,11 +1637,12 @@ namespace DS4Windows for (int i = 0; i < 4; i++) LoadProfile(i, false, Program.rootHub); // Refreshes all profiles in case other controllers are using the same profile - if (olddinputcheck != cBDinput.Checked) + /*if (olddinputcheck != cBDinput.Checked) { root.BtnStartStop_Clicked(false); finishDInputChange(); } + */ if (btnRumbleHeavyTest.Text == Properties.Resources.StopText) Program.rootHub.setRumble(0, 0, (int)nUDSixaxis.Value - 1); @@ -1655,6 +1656,7 @@ namespace DS4Windows { int discon = getIdleDisconnectTimeout(device); int btCurrentIndex = btPollRateComboBox.SelectedIndex; + tempDev.queueEvent(() => { tempDev.setIdleTimeout(discon); @@ -1662,6 +1664,18 @@ namespace DS4Windows { tempDev.setBTPollRate(btCurrentIndex); } + + if (olddinputcheck != cBDinput.Checked) + { + if (cBDinput.Checked) + { + Program.rootHub.UnplugXInputController(device); + } + else + { + Program.rootHub.PlugXInputController(device); + } + } }); } } @@ -2161,14 +2175,9 @@ namespace DS4Windows } } - private void cBDinput_CheckedChanged(object sender, EventArgs e) + private void CBDinput_CheckedChanged(object sender, EventArgs e) { DinputOnly[device] = cBDinput.Checked; - if (!loading && device < 4) - { - root.BtnStartStop_Clicked(false); - finishDInputChange(); - } } private async void finishDInputChange()