Force disconnect for wireless controllers when suspending

Related to issue #227
This commit is contained in:
Travis Nickles 2018-02-26 02:55:17 -06:00
parent 164f6f65e3
commit 16341d37b5
4 changed files with 21 additions and 21 deletions

View File

@ -214,7 +214,7 @@ namespace DS4Windows
return true; return true;
} }
public bool Stop(bool showlog = true) public bool Stop(bool showlog = true, bool suspend = false)
{ {
if (running) if (running)
{ {
@ -232,7 +232,7 @@ namespace DS4Windows
DS4Device tempDevice = DS4Controllers[i]; DS4Device tempDevice = DS4Controllers[i];
if (tempDevice != null) if (tempDevice != null)
{ {
if (DCBTatStop && !tempDevice.isCharging()) if ((DCBTatStop && !tempDevice.isCharging()) || suspend)
{ {
if (tempDevice.getConnectionType() == ConnectionType.BT) if (tempDevice.getConnectionType() == ConnectionType.BT)
{ {

View File

@ -1263,7 +1263,7 @@
resources.ApplyResources(this.btnClear, "btnClear"); resources.ApplyResources(this.btnClear, "btnClear");
this.btnClear.Name = "btnClear"; this.btnClear.Name = "btnClear";
this.btnClear.UseVisualStyleBackColor = true; this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click); this.btnClear.Click += new System.EventHandler(this.BtnClear_Click);
// //
// saveProfiles // saveProfiles
// //

View File

@ -310,7 +310,7 @@ namespace DS4Windows
} }
if (btnStartStop.Enabled && start) if (btnStartStop.Enabled && start)
btnStartStop_Clicked(); BtnStartStop_Clicked();
startToolStripMenuItem.Text = btnStartStop.Text; startToolStripMenuItem.Text = btnStartStop.Text;
cBoxNotifications.SelectedIndex = Notifications; cBoxNotifications.SelectedIndex = Notifications;
@ -507,7 +507,7 @@ namespace DS4Windows
{ {
DS4LightBar.shuttingdown = false; DS4LightBar.shuttingdown = false;
wasrunning = false; wasrunning = false;
btnStartStop_Clicked(); BtnStartStop_Clicked();
} }
break; break;
} }
@ -516,7 +516,7 @@ namespace DS4Windows
if (btnStartStop.Text == Properties.Resources.StopText) if (btnStartStop.Text == Properties.Resources.StopText)
{ {
DS4LightBar.shuttingdown = true; DS4LightBar.shuttingdown = true;
btnStartStop_Clicked(); BtnStartStop_Clicked(true, true);
wasrunning = true; wasrunning = true;
} }
break; break;
@ -586,7 +586,7 @@ namespace DS4Windows
turnOffTemp = true; turnOffTemp = true;
if (btnStartStop.Text == Properties.Resources.StopText) if (btnStartStop.Text == Properties.Resources.StopText)
{ {
btnStartStop_Clicked(); BtnStartStop_Clicked();
hotkeysTimer.Start(); hotkeysTimer.Start();
autoProfilesTimer.Start(); autoProfilesTimer.Start();
btnStartStop.Text = Properties.Resources.StartText; btnStartStop.Text = Properties.Resources.StartText;
@ -612,7 +612,7 @@ namespace DS4Windows
turnOffTemp = false; turnOffTemp = false;
if (btnStartStop.Text == Properties.Resources.StartText) if (btnStartStop.Text == Properties.Resources.StartText)
{ {
btnStartStop_Clicked(); BtnStartStop_Clicked();
btnStartStop.Text = Properties.Resources.StopText; btnStartStop.Text = Properties.Resources.StopText;
} }
} }
@ -888,7 +888,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
protected void btnStartStop_Click(object sender, EventArgs e) protected void btnStartStop_Click(object sender, EventArgs e)
{ {
btnStartStop_Clicked(); BtnStartStop_Clicked();
} }
private void serviceStartup(bool log) private void serviceStartup(bool log)
@ -919,12 +919,12 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText; startToolStripMenuItem.Text = btnStartStop.Text = Properties.Resources.StopText;
} }
private void serviceShutdown(bool log) private void ServiceShutdown(bool log, bool suspend = false)
{ {
changingService = true; changingService = true;
TaskRunner.Run(() => TaskRunner.Run(() =>
{ {
Program.rootHub.Stop(log); Program.rootHub.Stop(log, suspend);
Invoke((System.Action)(() => { serviceShutdownFinish(); })); Invoke((System.Action)(() => { serviceShutdownFinish(); }));
changingService = false; changingService = false;
}); });
@ -939,7 +939,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
populateFullNotifyText(); populateFullNotifyText();
} }
public void btnStartStop_Clicked(bool log = true) public void BtnStartStop_Clicked(bool log = true, bool suspend = false)
{ {
if (btnStartStop.Text == Properties.Resources.StartText) if (btnStartStop.Text == Properties.Resources.StartText)
{ {
@ -948,11 +948,11 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
else if (btnStartStop.Text == Properties.Resources.StopText) else if (btnStartStop.Text == Properties.Resources.StopText)
{ {
blankControllerTab(); blankControllerTab();
serviceShutdown(log); ServiceShutdown(log, suspend);
} }
} }
protected void btnClear_Click(object sender, EventArgs e) protected void BtnClear_Click(object sender, EventArgs e)
{ {
lvDebug.Items.Clear(); lvDebug.Items.Clear();
lbLastMessage.Text = string.Empty; lbLastMessage.Text = string.Empty;
@ -1537,7 +1537,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
hideDS4CheckBox.Enabled = false; hideDS4CheckBox.Enabled = false;
Save(); Save();
btnStartStop_Clicked(false); BtnStartStop_Clicked(false);
finishHideDS4Check(); finishHideDS4Check();
} }
@ -1551,7 +1551,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
} }
}); });
btnStartStop_Clicked(false); BtnStartStop_Clicked(false);
await TaskRunner.Factory.StartNew(() => await TaskRunner.Factory.StartNew(() =>
{ {
@ -1655,7 +1655,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
private void startToolStripMenuItem_Click(object sender, EventArgs e) private void startToolStripMenuItem_Click(object sender, EventArgs e)
{ {
btnStartStop_Clicked(); BtnStartStop_Clicked();
} }
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
@ -2184,7 +2184,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
oldxiport = (int)Math.Round(nUDXIPorts.Value, 0); oldxiport = (int)Math.Round(nUDXIPorts.Value, 0);
FirstXinputPort = oldxiport; FirstXinputPort = oldxiport;
Program.rootHub.x360Bus.FirstController = oldxiport; Program.rootHub.x360Bus.FirstController = oldxiport;
btnStartStop_Clicked(false); BtnStartStop_Clicked(false);
finishHideDS4Check(); finishHideDS4Check();
} }
} }

View File

@ -1639,7 +1639,7 @@ namespace DS4Windows
if (olddinputcheck != cBDinput.Checked) if (olddinputcheck != cBDinput.Checked)
{ {
root.btnStartStop_Clicked(false); root.BtnStartStop_Clicked(false);
finishDInputChange(); finishDInputChange();
} }
@ -2166,7 +2166,7 @@ namespace DS4Windows
DinputOnly[device] = cBDinput.Checked; DinputOnly[device] = cBDinput.Checked;
if (!loading && device < 4) if (!loading && device < 4)
{ {
root.btnStartStop_Clicked(false); root.BtnStartStop_Clicked(false);
finishDInputChange(); finishDInputChange();
} }
} }
@ -2181,7 +2181,7 @@ namespace DS4Windows
} }
}); });
root.btnStartStop_Clicked(false); root.BtnStartStop_Clicked(false);
} }
private void cbStartTouchpadOff_CheckedChanged(object sender, EventArgs e) private void cbStartTouchpadOff_CheckedChanged(object sender, EventArgs e)