Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 8d187c1

Browse files
committed
Fix reconnect devices
1 parent 0e152c6 commit 8d187c1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

XOutput/Devices/Mapper/InputMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void Attach(IEnumerable<IInputDevice> inputDevices)
8484
{
8585
if (mapperData.InputDevice == inputDevice.UniqueId)
8686
{
87-
mapperData.Source = inputDevice.Sources.FirstOrDefault(s => s.Offset.ToString() == mapperData.InputType);
87+
mapperData.SetSourceWithoutSaving(inputDevice.Sources.FirstOrDefault(s => s.Offset.ToString() == mapperData.InputType));
8888
inputs.Add(inputDevice);
8989
found = true;
9090
break;
@@ -93,7 +93,7 @@ public void Attach(IEnumerable<IInputDevice> inputDevices)
9393
}
9494
if (!found)
9595
{
96-
mapperData.Source = DisabledInputSource.Instance;
96+
mapperData.SetSourceWithoutSaving(DisabledInputSource.Instance);
9797
}
9898
}
9999
}

XOutput/Devices/Mapper/MapperData.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,13 @@ public double GetValue(double value)
9191
}
9292
return mappedValue;
9393
}
94+
public void SetSourceWithoutSaving(InputSource value)
95+
{
96+
var newValue = value ?? DisabledInputSource.Instance;
97+
if (newValue != source)
98+
{
99+
source = newValue;
100+
}
101+
}
94102
}
95103
}

XOutput/UI/Windows/MainWindowViewModel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public MainWindowViewModel(MainWindowModel model, Dispatcher dispatcher, HidGuar
4040
{
4141
this.dispatcher = dispatcher;
4242
this.hidGuardianManager = hidGuardianManager;
43-
timer.Interval = TimeSpan.FromMilliseconds(10000);
43+
timer.Interval = TimeSpan.FromMilliseconds(5000);
4444
timer.Tick += (object sender1, EventArgs e1) => { RefreshGameControllers(); };
4545
timer.Start();
4646
}
@@ -216,6 +216,7 @@ public void RefreshGameControllers()
216216
{
217217
IEnumerable<SharpDX.DirectInput.DeviceInstance> instances = directInputDevices.GetInputDevices(Model.AllDevices);
218218

219+
bool changed = false;
219220
foreach (var inputView in Model.Inputs.ToArray())
220221
{
221222
var device = inputView.ViewModel.Model.Device;
@@ -225,6 +226,7 @@ public void RefreshGameControllers()
225226
InputDevices.Instance.Remove(device);
226227
inputView.ViewModel.Dispose();
227228
device.Dispose();
229+
changed = true;
228230
}
229231
}
230232
foreach (var instance in instances)
@@ -240,8 +242,18 @@ public void RefreshGameControllers()
240242
device.Disconnected -= DispatchRefreshGameControllers;
241243
device.Disconnected += DispatchRefreshGameControllers;
242244
Model.Inputs.Add(new InputView(new InputViewModel(new InputModel(), device, Model.IsAdmin)));
245+
changed = true;
243246
}
244247
}
248+
if (changed)
249+
{
250+
foreach (var controller in Controllers.Instance.GetControllers())
251+
{
252+
var mapper = settings.CreateMapper(controller.Mapper.Id);
253+
controller.Mapper.Mappings = mapper.Mappings;
254+
}
255+
Controllers.Instance.Update(InputDevices.Instance.GetDevices());
256+
}
245257
}
246258

247259
public void AddController(InputMapper mapper)

0 commit comments

Comments
 (0)