Fix some button mapping issues. Style changes. Change runStartupPanel

This commit is contained in:
Travis Nickles 2017-04-24 02:43:56 -07:00
parent bba8af6a63
commit e34e8115ad
8 changed files with 1795 additions and 2348 deletions

View File

@ -423,7 +423,7 @@ namespace DS4Windows
if (DS4Controllers[index] != null) if (DS4Controllers[index] != null)
{ {
DS4Device d = DS4Controllers[index]; DS4Device d = DS4Controllers[index];
String battery; string battery;
if (!d.IsAlive()) if (!d.IsAlive())
battery = "..."; battery = "...";
@ -483,9 +483,10 @@ namespace DS4Windows
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change. CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
x360Bus.Unplug(ind); x360Bus.Unplug(ind);
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString()); string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
if (device.Battery <= 20 && if (device.getBattery() <= 20 &&
device.ConnectionType == ConnectionType.BT && !device.Charging) device.getConnectionType() == ConnectionType.BT && !device.isCharging())
removed += ". " + Properties.Resources.ChargeController; removed += ". " + Properties.Resources.ChargeController;
LogDebug(removed); LogDebug(removed);
Log.LogToTray(removed); Log.LogToTray(removed);
System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);

View File

@ -794,15 +794,17 @@ namespace DS4Windows
cState.calculateStickAngles(); cState.calculateStickAngles();
DS4StateFieldMapping fieldMapping = new DS4StateFieldMapping(cState, eState, tp); DS4StateFieldMapping fieldMapping = new DS4StateFieldMapping(cState, eState, tp);
DS4StateFieldMapping outputfieldMapping = new DS4StateFieldMapping(cState, eState, tp);
SyntheticState deviceState = Mapping.deviceState[device]; SyntheticState deviceState = Mapping.deviceState[device];
if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device])) if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device]))
MapCustomAction(device, cState, MappedState, eState, tp, ctrl, fieldMapping); MapCustomAction(device, cState, MappedState, eState, tp, ctrl, fieldMapping, outputfieldMapping);
if (ctrl.DS4Controllers[device] == null) return; if (ctrl.DS4Controllers[device] == null) return;
cState.CopyTo(MappedState); cState.CopyTo(MappedState);
Dictionary<DS4Controls, DS4Controls> tempControlDict = new Dictionary<DS4Controls, DS4Controls>(); Dictionary<DS4Controls, DS4Controls> tempControlDict = new Dictionary<DS4Controls, DS4Controls>();
//MultiValueDict<DS4Controls, DS4Controls> tempControlDict = new MultiValueDict<DS4Controls, DS4Controls>();
DS4Controls usingExtra = DS4Controls.None; DS4Controls usingExtra = DS4Controls.None;
List<DS4ControlSettings> tempSettingsList = getDS4CSettings(device); List<DS4ControlSettings> tempSettingsList = getDS4CSettings(device);
//foreach (DS4ControlSettings dcs in getDS4CSettings(device)) //foreach (DS4ControlSettings dcs in getDS4CSettings(device))
@ -832,7 +834,7 @@ namespace DS4Windows
bool active = getBoolMapping2(device, dcs.control, cState, eState, tp, fieldMapping); bool active = getBoolMapping2(device, dcs.control, cState, eState, tp, fieldMapping);
if (active) if (active)
{ {
resetToDefaultValue2(dcs.control, MappedState, fieldMapping); resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType); PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType);
} }
else else
@ -845,7 +847,7 @@ namespace DS4Windows
ushort value = ushort.Parse(action.ToString()); ushort value = ushort.Parse(action.ToString());
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{ {
resetToDefaultValue2(dcs.control, MappedState, fieldMapping); resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
SyntheticState.KeyPresses kp; SyntheticState.KeyPresses kp;
if (!deviceState.keyPresses.TryGetValue(value, out kp)) if (!deviceState.keyPresses.TryGetValue(value, out kp))
deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses(); deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses();
@ -901,10 +903,10 @@ namespace DS4Windows
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.A: tempControlDict.Add(DS4Controls.Cross, dcs.control); break; case X360Controls.A: tempControlDict.Add(dcs.control, DS4Controls.Cross); break;
case X360Controls.B: tempControlDict.Add(DS4Controls.Circle, dcs.control); break; case X360Controls.B: tempControlDict.Add(dcs.control, DS4Controls.Circle); break;
case X360Controls.X: tempControlDict.Add(DS4Controls.Square, dcs.control); break; case X360Controls.X: tempControlDict.Add(dcs.control, DS4Controls.Square); break;
case X360Controls.Y: tempControlDict.Add(DS4Controls.Triangle, dcs.control); break; case X360Controls.Y: tempControlDict.Add(dcs.control, DS4Controls.Triangle); break;
default: break; default: break;
} }
} }
@ -912,12 +914,12 @@ namespace DS4Windows
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.LB: tempControlDict.Add(DS4Controls.L1, dcs.control); break; case X360Controls.LB: tempControlDict.Add(dcs.control, DS4Controls.L1); break;
case X360Controls.LT: tempControlDict.Add(DS4Controls.L2, dcs.control); break; case X360Controls.LT: tempControlDict.Add(dcs.control, DS4Controls.L2); break;
case X360Controls.LS: tempControlDict.Add(DS4Controls.L3, dcs.control); break; case X360Controls.LS: tempControlDict.Add(dcs.control, DS4Controls.L3); break;
case X360Controls.RB: tempControlDict.Add(DS4Controls.R1, dcs.control); break; case X360Controls.RB: tempControlDict.Add(dcs.control, DS4Controls.R1); break;
case X360Controls.RT: tempControlDict.Add(DS4Controls.R2, dcs.control); break; case X360Controls.RT: tempControlDict.Add(dcs.control, DS4Controls.R2); break;
case X360Controls.RS: tempControlDict.Add(DS4Controls.R3, dcs.control); break; case X360Controls.RS: tempControlDict.Add(dcs.control, DS4Controls.R3); break;
default: break; default: break;
} }
} }
@ -925,10 +927,10 @@ namespace DS4Windows
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.DpadUp: tempControlDict.Add(DS4Controls.DpadUp, dcs.control); break; case X360Controls.DpadUp: tempControlDict.Add(dcs.control, DS4Controls.DpadUp); break;
case X360Controls.DpadDown: tempControlDict.Add(DS4Controls.DpadDown, dcs.control); break; case X360Controls.DpadDown: tempControlDict.Add(dcs.control, DS4Controls.DpadDown); break;
case X360Controls.DpadLeft: tempControlDict.Add(DS4Controls.DpadLeft, dcs.control); break; case X360Controls.DpadLeft: tempControlDict.Add(dcs.control, DS4Controls.DpadLeft); break;
case X360Controls.DpadRight: tempControlDict.Add(DS4Controls.DpadRight, dcs.control); break; case X360Controls.DpadRight: tempControlDict.Add(dcs.control, DS4Controls.DpadRight); break;
default: break; default: break;
} }
} }
@ -936,14 +938,14 @@ namespace DS4Windows
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.LXNeg: tempControlDict.Add(DS4Controls.LXNeg, dcs.control); break; case X360Controls.LXNeg: tempControlDict.Add(dcs.control, DS4Controls.LXNeg); break;
case X360Controls.LYNeg: tempControlDict.Add(DS4Controls.LYNeg, dcs.control); break; case X360Controls.LYNeg: tempControlDict.Add(dcs.control, DS4Controls.LYNeg); break;
case X360Controls.RXNeg: tempControlDict.Add(DS4Controls.RXNeg, dcs.control); break; case X360Controls.RXNeg: tempControlDict.Add(dcs.control, DS4Controls.RXNeg); break;
case X360Controls.RYNeg: tempControlDict.Add(DS4Controls.RYNeg, dcs.control); break; case X360Controls.RYNeg: tempControlDict.Add(dcs.control, DS4Controls.RYNeg); break;
case X360Controls.LXPos: tempControlDict.Add(DS4Controls.LXPos, dcs.control); break; case X360Controls.LXPos: tempControlDict.Add(dcs.control, DS4Controls.LXPos); break;
case X360Controls.LYPos: tempControlDict.Add(DS4Controls.LYPos, dcs.control); break; case X360Controls.LYPos: tempControlDict.Add(dcs.control, DS4Controls.LYPos); break;
case X360Controls.RXPos: tempControlDict.Add(DS4Controls.RXPos, dcs.control); break; case X360Controls.RXPos: tempControlDict.Add(dcs.control, DS4Controls.RXPos); break;
case X360Controls.RYPos: tempControlDict.Add(DS4Controls.RYPos, dcs.control); break; case X360Controls.RYPos: tempControlDict.Add(dcs.control, DS4Controls.RYPos); break;
default: break; default: break;
} }
} }
@ -1033,9 +1035,9 @@ namespace DS4Windows
{ {
switch (xboxControl) switch (xboxControl)
{ {
case X360Controls.Start: tempControlDict.Add(DS4Controls.Options, dcs.control); break; case X360Controls.Start: tempControlDict.Add(dcs.control, DS4Controls.Options); break;
case X360Controls.Guide: tempControlDict.Add(DS4Controls.PS, dcs.control); break; case X360Controls.Guide: tempControlDict.Add(dcs.control, DS4Controls.PS); break;
case X360Controls.Back: tempControlDict.Add(DS4Controls.Share, dcs.control); break; case X360Controls.Back: tempControlDict.Add(dcs.control, DS4Controls.Share); break;
default: break; default: break;
} }
} }
@ -1044,7 +1046,7 @@ namespace DS4Windows
{ {
if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping)) if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{ {
resetToDefaultValue2(dcs.control, MappedState, fieldMapping); resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
if (!pressedonce[keyvalue]) if (!pressedonce[keyvalue])
{ {
deviceState.currentClicks.toggle = !deviceState.currentClicks.toggle; deviceState.currentClicks.toggle = !deviceState.currentClicks.toggle;
@ -1058,7 +1060,7 @@ namespace DS4Windows
} }
} }
resetToDefaultValue2(dcs.control, MappedState, fieldMapping); // erase default mappings for things that are remapped resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping); // erase default mappings for things that are remapped
} }
} }
@ -1115,7 +1117,9 @@ namespace DS4Windows
usingExtra = DS4Controls.None; usingExtra = DS4Controls.None;
} }
} }
} }
outputfieldMapping.populateState(MappedState);
if (macroControl[00]) MappedState.Cross = true; if (macroControl[00]) MappedState.Cross = true;
if (macroControl[01]) MappedState.Circle = true; if (macroControl[01]) MappedState.Circle = true;
@ -1168,6 +1172,7 @@ namespace DS4Windows
tempControlDict.Add(DS4Controls.RYPos, DS4Controls.RYPos); tempControlDict.Add(DS4Controls.RYPos, DS4Controls.RYPos);
Dictionary<DS4Controls, DS4Controls>.KeyCollection controlKeys = tempControlDict.Keys; Dictionary<DS4Controls, DS4Controls>.KeyCollection controlKeys = tempControlDict.Keys;
//Dictionary<DS4Controls, List<DS4Controls>>.KeyCollection controlKeys = tempControlDict.Keys;
//foreach (KeyValuePair<DS4Controls, DS4Controls> entry in tempControlDict) //foreach (KeyValuePair<DS4Controls, DS4Controls> entry in tempControlDict)
for (int i = 0, keyCount = controlKeys.Count; i < keyCount; i++) for (int i = 0, keyCount = controlKeys.Count; i < keyCount; i++)
@ -1176,11 +1181,12 @@ namespace DS4Windows
DS4Controls dc = tempControlDict[key]; DS4Controls dc = tempControlDict[key];
//DS4Controls key = entry.Key; //DS4Controls key = entry.Key;
//DS4Controls dc = entry.Value; //DS4Controls dc = entry.Value;
if (getBoolActionMapping2(device, dc, cState, eState, tp, fieldMapping, true))
if (getBoolActionMapping2(device, key, cState, eState, tp, fieldMapping, true))
{ {
if (key >= DS4Controls.Square && key <= DS4Controls.Cross) if (dc >= DS4Controls.Square && dc <= DS4Controls.Cross)
{ {
switch (key) switch (dc)
{ {
case DS4Controls.Cross: MappedState.Cross = true; break; case DS4Controls.Cross: MappedState.Cross = true; break;
case DS4Controls.Circle: MappedState.Circle = true; break; case DS4Controls.Circle: MappedState.Circle = true; break;
@ -1189,22 +1195,22 @@ namespace DS4Windows
default: break; default: break;
} }
} }
else if (key >= DS4Controls.L1 && key <= DS4Controls.R3) else if (dc >= DS4Controls.L1 && dc <= DS4Controls.R3)
{ {
switch (key) switch (dc)
{ {
case DS4Controls.L1: MappedState.L1 = true; break; case DS4Controls.L1: MappedState.L1 = true; break;
case DS4Controls.L2: MappedState.L2 = getByteMapping(device, dc, cState, eState, tp); break; case DS4Controls.L2: MappedState.L2 = getByteMapping(device, key, cState, eState, tp); break;
case DS4Controls.L3: MappedState.L3 = true; break; case DS4Controls.L3: MappedState.L3 = true; break;
case DS4Controls.R1: MappedState.R1 = true; break; case DS4Controls.R1: MappedState.R1 = true; break;
case DS4Controls.R2: MappedState.R2 = getByteMapping(device, dc, cState, eState, tp); break; case DS4Controls.R2: MappedState.R2 = getByteMapping(device, key, cState, eState, tp); break;
case DS4Controls.R3: MappedState.R3 = true; break; case DS4Controls.R3: MappedState.R3 = true; break;
default: break; default: break;
} }
} }
else if (key >= DS4Controls.DpadUp && key <= DS4Controls.DpadLeft) else if (dc >= DS4Controls.DpadUp && dc <= DS4Controls.DpadLeft)
{ {
switch (key) switch (dc)
{ {
case DS4Controls.DpadUp: MappedState.DpadUp = true; break; case DS4Controls.DpadUp: MappedState.DpadUp = true; break;
case DS4Controls.DpadRight: MappedState.DpadRight = true; break; case DS4Controls.DpadRight: MappedState.DpadRight = true; break;
@ -1213,100 +1219,100 @@ namespace DS4Windows
default: break; default: break;
} }
} }
else if (key >= DS4Controls.LXNeg && key <= DS4Controls.RYPos) else if (dc >= DS4Controls.LXNeg && dc <= DS4Controls.RYPos)
{ {
switch (key) switch (dc)
{ {
case DS4Controls.LXNeg: case DS4Controls.LXNeg:
case DS4Controls.LXPos: case DS4Controls.LXPos:
{
if (Math.Abs(MappedState.LX - 127) < 10)
{ {
if (key == DS4Controls.LXNeg) if (Math.Abs(MappedState.LX - 127) < 10)
{ {
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp, true); if (dc == DS4Controls.LXNeg)
if (Math.Abs(127 - axisMapping) > 5) {
MappedState.LX = axisMapping; byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LX = axisMapping;
}
else
{
byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LX = axisMapping;
}
} }
else
{
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LX = axisMapping;
}
}
break; break;
} }
case DS4Controls.LYNeg: case DS4Controls.LYNeg:
case DS4Controls.LYPos: case DS4Controls.LYPos:
{
if (Math.Abs(MappedState.LY - 127) < 10)
{ {
if (key == DS4Controls.LYNeg) if (Math.Abs(MappedState.LY - 127) < 10)
{ {
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp); if (dc == DS4Controls.LYNeg)
if (Math.Abs(127 - axisMapping) > 5) {
MappedState.LY = axisMapping; byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LY = axisMapping;
}
else
{
byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LY = axisMapping;
}
} }
else
{
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.LY = axisMapping;
}
}
break; break;
} }
case DS4Controls.RXNeg: case DS4Controls.RXNeg:
case DS4Controls.RXPos: case DS4Controls.RXPos:
{
if (Math.Abs(MappedState.RX - 127) < 10)
{ {
if (key == DS4Controls.RXNeg) if (Math.Abs(MappedState.RX - 127) < 10)
{ {
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp); if (dc == DS4Controls.RXNeg)
if (Math.Abs(127 - axisMapping) > 5) {
MappedState.RX = axisMapping; byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RX = axisMapping;
}
else
{
byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RX = axisMapping;
}
} }
else
{
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RX = axisMapping;
}
}
break; break;
} }
case DS4Controls.RYNeg: case DS4Controls.RYNeg:
case DS4Controls.RYPos: case DS4Controls.RYPos:
{
if (Math.Abs(MappedState.RY - 127) < 10)
{ {
if (key == DS4Controls.RYNeg) if (Math.Abs(MappedState.RY - 127) < 10)
{ {
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp); if (dc == DS4Controls.RYNeg)
if (Math.Abs(127 - axisMapping) > 5) {
MappedState.RY = axisMapping; byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RY = axisMapping;
}
else
{
byte axisMapping = getXYAxisMapping(device, key, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RY = axisMapping;
}
} }
else
{
byte axisMapping = getXYAxisMapping(device, dc, cState, eState, tp, true);
if (Math.Abs(127 - axisMapping) > 5)
MappedState.RY = axisMapping;
}
}
break; break;
} }
default: break; default: break;
} }
} }
else else
{ {
switch (key) switch (dc)
{ {
case DS4Controls.Options: MappedState.Options = true; break; case DS4Controls.Options: MappedState.Options = true; break;
case DS4Controls.Share: MappedState.Share = true; break; case DS4Controls.Share: MappedState.Share = true; break;
@ -1317,8 +1323,6 @@ namespace DS4Windows
} }
} }
fieldMapping.populateState(MappedState);
calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY, calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY,
out mouseDeltaX, out mouseDeltaY); out mouseDeltaX, out mouseDeltaY);
if (mouseDeltaX != 0 || mouseDeltaY != 0) if (mouseDeltaX != 0 || mouseDeltaY != 0)
@ -1333,7 +1337,7 @@ namespace DS4Windows
} }
private static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, private static async void MapCustomAction(int device, DS4State cState, DS4State MappedState,
DS4StateExposed eState, Mouse tp, ControlService ctrl, DS4StateFieldMapping fieldMapping) DS4StateExposed eState, Mouse tp, ControlService ctrl, DS4StateFieldMapping fieldMapping, DS4StateFieldMapping outputfieldMapping)
{ {
/* TODO: This method is slow sauce. Find ways to speed up action execution */ /* TODO: This method is slow sauce. Find ways to speed up action execution */
try try
@ -1527,7 +1531,7 @@ namespace DS4Windows
for (int i = 0, arlen = action.trigger.Count; i < arlen; i++) for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{ {
DS4Controls dc = action.trigger[i]; DS4Controls dc = action.trigger[i];
resetToDefaultValue2(dc, MappedState, fieldMapping); resetToDefaultValue2(dc, MappedState, outputfieldMapping);
} }
PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType); PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType);

View File

@ -142,6 +142,21 @@ namespace DS4Windows
} }
} }
public class MultiValueDict<Key, Value> : Dictionary<Key, List<Value>>
{
public void Add(Key key, Value val)
{
List<Value> values = null;
if (!this.TryGetValue(key, out values))
{
values = new List<Value>();
this.Add(key, values);
}
values.Add(val);
}
}
public class Global public class Global
{ {
protected static BackingStore m_Config = new BackingStore(); protected static BackingStore m_Config = new BackingStore();

View File

@ -19,26 +19,26 @@ namespace DS4Windows
internal class WindowsEnumerator internal class WindowsEnumerator
{ {
private delegate int EnumCallBackDelegate(IntPtr hwnd, int lParam); private delegate int EnumCallBackDelegate(IntPtr hwnd, int lParam);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int EnumWindows(EnumCallBackDelegate lpEnumFunc, int lParam); private static extern int EnumWindows(EnumCallBackDelegate lpEnumFunc, int lParam);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int EnumChildWindows(IntPtr hWndParent, EnumCallBackDelegate lpEnumFunc, int lParam); private static extern int EnumChildWindows(IntPtr hWndParent, EnumCallBackDelegate lpEnumFunc, int lParam);
[DllImport("user32", EntryPoint = "GetClassNameA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] [DllImport("user32", EntryPoint = "GetClassNameA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int GetClassName(IntPtr hwnd, System.Text.StringBuilder lpClassName, int nMaxCount); private static extern int GetClassName(IntPtr hwnd, System.Text.StringBuilder lpClassName, int nMaxCount);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int IsWindowVisible(IntPtr hwnd); private static extern int IsWindowVisible(IntPtr hwnd);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int GetParent(IntPtr hwnd); private static extern int GetParent(IntPtr hwnd);
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
[DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, System.Text.StringBuilder lParam); private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, System.Text.StringBuilder lParam);
private List<ApiWindow> _listChildren = new List<ApiWindow>(); private List<ApiWindow> _listChildren = new List<ApiWindow>();

View File

@ -119,6 +119,7 @@
this.cBSwipeProfiles = new System.Windows.Forms.CheckBox(); this.cBSwipeProfiles = new System.Windows.Forms.CheckBox();
this.StartWindowsCheckBox = new System.Windows.Forms.CheckBox(); this.StartWindowsCheckBox = new System.Windows.Forms.CheckBox();
this.runStartupPanel = new System.Windows.Forms.Panel(); this.runStartupPanel = new System.Windows.Forms.Panel();
this.uacTaskButton = new System.Windows.Forms.Button();
this.runStartTaskRadio = new System.Windows.Forms.RadioButton(); this.runStartTaskRadio = new System.Windows.Forms.RadioButton();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.runStartProgRadio = new System.Windows.Forms.RadioButton(); this.runStartProgRadio = new System.Windows.Forms.RadioButton();
@ -893,12 +894,21 @@
// runStartupPanel // runStartupPanel
// //
this.runStartupPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.runStartupPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.runStartupPanel.Controls.Add(this.uacTaskButton);
this.runStartupPanel.Controls.Add(this.runStartTaskRadio); this.runStartupPanel.Controls.Add(this.runStartTaskRadio);
this.runStartupPanel.Controls.Add(this.label1); this.runStartupPanel.Controls.Add(this.label1);
this.runStartupPanel.Controls.Add(this.runStartProgRadio); this.runStartupPanel.Controls.Add(this.runStartProgRadio);
resources.ApplyResources(this.runStartupPanel, "runStartupPanel"); resources.ApplyResources(this.runStartupPanel, "runStartupPanel");
this.runStartupPanel.Name = "runStartupPanel"; this.runStartupPanel.Name = "runStartupPanel";
// //
// uacTaskButton
//
this.uacTaskButton.FlatAppearance.BorderSize = 0;
resources.ApplyResources(this.uacTaskButton, "uacTaskButton");
this.uacTaskButton.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.uacTaskButton.Name = "uacTaskButton";
this.uacTaskButton.UseVisualStyleBackColor = true;
//
// runStartTaskRadio // runStartTaskRadio
// //
resources.ApplyResources(this.runStartTaskRadio, "runStartTaskRadio"); resources.ApplyResources(this.runStartTaskRadio, "runStartTaskRadio");
@ -1379,6 +1389,7 @@
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.RadioButton runStartProgRadio; private System.Windows.Forms.RadioButton runStartProgRadio;
private System.Windows.Forms.RadioButton runStartTaskRadio; private System.Windows.Forms.RadioButton runStartTaskRadio;
private System.Windows.Forms.Button uacTaskButton;
//private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; //private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
} }
} }

View File

@ -57,12 +57,18 @@ namespace DS4Windows
bool runningBat; bool runningBat;
//bool outputlog = false; //bool outputlog = false;
internal const int BCM_FIRST = 0x1600; // Normal button
internal const int BCM_SETSHIELD = (BCM_FIRST + 0x000C); // Elevated button
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow(); private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, uint lParam);
[DllImport("kernel32.dll")] [DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId); private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
@ -344,6 +350,16 @@ namespace DS4Windows
{ {
StartWindowsCheckBox.Checked = true; StartWindowsCheckBox.Checked = true;
runStartupPanel.Visible = true; runStartupPanel.Visible = true;
if (Global.IsAdministrator())
{
runStartTaskRadio.Enabled = true;
}
else
{
runStartTaskRadio.Enabled = false;
}
string lnkpath = WinProgs.ResolveShortcutAndArgument(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"); string lnkpath = WinProgs.ResolveShortcutAndArgument(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
string onlylnkpath = WinProgs.ResolveShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk"); string onlylnkpath = WinProgs.ResolveShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\DS4Windows.lnk");
if (!lnkpath.EndsWith("-runtask")) if (!lnkpath.EndsWith("-runtask"))
@ -361,6 +377,8 @@ namespace DS4Windows
appShortcutToStartup(); appShortcutToStartup();
changeStartupRoutine(); changeStartupRoutine();
} }
SendMessage(uacTaskButton.Handle, BCM_SETSHIELD, 0, 1);
} }
UpdateTheUpdater(); UpdateTheUpdater();
@ -869,53 +887,61 @@ namespace DS4Windows
else else
ControllerStatusChanged(); ControllerStatusChanged();
} }
protected void ControllerStatusChanged() protected void ControllerStatusChanged()
{ {
String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion; String tooltip = "DS4Windows v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
bool nocontrollers = true; bool nocontrollers = true;
DS4Device[] devices = Program.rootHub.DS4Controllers;
int controllerLen = devices.Length;
for (Int32 Index = 0, PadsLen = Pads.Length; Index < PadsLen; Index++) for (Int32 Index = 0, PadsLen = Pads.Length; Index < PadsLen; Index++)
{ {
Pads[Index].Text = Program.rootHub.getDS4MacAddress(Index); // Make sure a controller exists
DS4Device d = Program.rootHub.DS4Controllers[Index]; if (Index < controllerLen)
switch (Program.rootHub.getDS4Status(Index))
{ {
case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break; Pads[Index].Text = Program.rootHub.getDS4MacAddress(Index);
case "BT": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break; DS4Device d = devices[Index];
case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break;
default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break;
}
Batteries[Index].Text = Program.rootHub.getDS4Battery(Index); switch (Program.rootHub.getDS4Status(Index))
if (Pads[Index].Text != String.Empty)
{
if (runningBat)
{ {
SendKeys.Send("A"); case "USB": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.USB; toolTip1.SetToolTip(statPB[Index], ""); break;
runningBat = false; case "BT": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break;
case "SONYWA": statPB[Index].Visible = true; statPB[Index].Image = Properties.Resources.BT; toolTip1.SetToolTip(statPB[Index], "Right click to disconnect"); break;
default: statPB[Index].Visible = false; toolTip1.SetToolTip(statPB[Index], ""); break;
} }
Pads[Index].Enabled = true;
nocontrollers = false; Batteries[Index].Text = Program.rootHub.getDS4Battery(Index);
if (Pads[Index].Text != Properties.Resources.Connecting) if (Pads[Index].Text != String.Empty)
{ {
Enable_Controls(Index, true); if (runningBat)
//if (opt != null) {
// if (opt.Visible && tabMain.SelectedIndex == 1) SendKeys.Send("A");
runningBat = false;
}
Pads[Index].Enabled = true;
nocontrollers = false;
if (Pads[Index].Text != Properties.Resources.Connecting)
{
Enable_Controls(Index, true);
//if (opt != null)
// if (opt.Visible && tabMain.SelectedIndex == 1)
//opt.inputtimer.Start(); //opt.inputtimer.Start();
//MinimumSize = new Size(MinimumSize.Width, 137 + 29 * Index); //MinimumSize = new Size(MinimumSize.Width, 137 + 29 * Index);
}
else
opt.inputtimer.Stop();
} }
else else
opt.inputtimer.Stop(); {
Pads[Index].Text = Properties.Resources.Disconnected;
Enable_Controls(Index, false);
}
//if (((Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index)).Length > 50)
//MessageBox.Show(((Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index)).Length.ToString());
if (Program.rootHub.getShortDS4ControllerInfo(Index) != Properties.Resources.NoneText)
tooltip += "\n" + (Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index); // Carefully stay under the 63 character limit.
} }
else
{
Pads[Index].Text = Properties.Resources.Disconnected;
Enable_Controls(Index, false);
}
//if (((Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index)).Length > 50)
//MessageBox.Show(((Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index)).Length.ToString());
if (Program.rootHub.getShortDS4ControllerInfo(Index) != Properties.Resources.NoneText)
tooltip += "\n" + (Index + 1) + ": " + Program.rootHub.getShortDS4ControllerInfo(Index); // Carefully stay under the 63 character limit.
} }
lbNoControllers.Visible = nocontrollers; lbNoControllers.Visible = nocontrollers;

File diff suppressed because it is too large Load Diff

View File

@ -36,10 +36,13 @@ namespace DS4Windows
// Sort Bluetooth first in case USB is also connected on the same controller. // Sort Bluetooth first in case USB is also connected on the same controller.
hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); }); hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); });
foreach (HidDevice hDevice in hDevices) for (int i = 0, devCount = hDevices.Count(); i < devCount; i++)
//foreach (HidDevice hDevice in hDevices)
{ {
HidDevice hDevice = hDevices.ElementAt<HidDevice>(i);
if (DevicePaths.Contains(hDevice.DevicePath)) if (DevicePaths.Contains(hDevice.DevicePath))
continue; // BT/USB endpoint already open once continue; // BT/USB endpoint already open once
if (!hDevice.IsOpen) if (!hDevice.IsOpen)
{ {
hDevice.OpenDevice(isExclusiveMode); hDevice.OpenDevice(isExclusiveMode);
@ -98,7 +101,6 @@ namespace DS4Windows
} }
} }
} }
} }
} }
@ -134,11 +136,14 @@ namespace DS4Windows
lock (Devices) lock (Devices)
{ {
IEnumerable<DS4Device> devices = getDS4Controllers(); IEnumerable<DS4Device> devices = getDS4Controllers();
foreach (DS4Device device in devices) //foreach (DS4Device device in devices)
for (int i = 0, devCount = devices.Count(); i < devCount; i++)
{ {
DS4Device device = devices.ElementAt<DS4Device>(i);
device.StopUpdate(); device.StopUpdate();
device.HidDevice.CloseDevice(); device.HidDevice.CloseDevice();
} }
Devices.Clear(); Devices.Clear();
DevicePaths.Clear(); DevicePaths.Clear();
} }