Skip to content

Commit 524455d

Browse files
authored
FIX: Input devices sometimes marked as disabled on reconnect (#1524).
1 parent e0b76e2 commit 524455d

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,52 @@ public void Devices_WhenRetainedOnDisconnectedList_CanBeReconnected(string devic
15011501
Assert.That(InputSystem.disconnectedDevices, Is.Empty);
15021502
}
15031503

1504+
// https://fogbugz.unity3d.com/f/cases/1404320
1505+
[Test]
1506+
[Category("Devices")]
1507+
public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus()
1508+
{
1509+
runtime.runInBackground = true;
1510+
1511+
var deviceDesc = new InputDeviceDescription
1512+
{
1513+
deviceClass = "Gamepad",
1514+
product = "TestDevice",
1515+
serial = "1234"
1516+
};
1517+
1518+
var deviceId = runtime.ReportNewInputDevice(deviceDesc);
1519+
InputSystem.Update();
1520+
1521+
var device = InputSystem.GetDeviceById(deviceId);
1522+
Assert.That(device, Is.Not.Null);
1523+
1524+
// Loose focus.
1525+
runtime.PlayerFocusLost();
1526+
InputSystem.Update();
1527+
1528+
// Disconnect.
1529+
var inputEvent = DeviceRemoveEvent.Create(deviceId, runtime.currentTime);
1530+
InputSystem.QueueEvent(ref inputEvent);
1531+
InputSystem.Update();
1532+
1533+
Assert.That(InputSystem.disconnectedDevices, Is.EquivalentTo(new[] { device }));
1534+
Assert.That(InputSystem.devices, Is.Empty);
1535+
1536+
// Regain focus.
1537+
runtime.PlayerFocusGained();
1538+
InputSystem.Update();
1539+
1540+
var newDeviceId = runtime.ReportNewInputDevice(deviceDesc);
1541+
InputSystem.Update();
1542+
1543+
var newDevice = InputSystem.GetDeviceById(newDeviceId);
1544+
Assert.That(newDevice, Is.SameAs(device));
1545+
1546+
Assert.That(device.added, Is.True);
1547+
Assert.That(device.enabled, Is.True);
1548+
}
1549+
15041550
[Test]
15051551
[Category("Devices")]
15061552
public void Devices_WhenRemoved_DoNotEmergeOnUnsupportedList()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ however, it has to be formatted properly to pass verification tests.
5959
- Fixed missing tooltips in PlayerInputManagerEditor for the Player Limit and Fixed Splitscreen sizes labels ([case 1396945](https://issuetracker.unity3d.com/issues/player-input-manager-pops-up-placeholder-text-when-hovering-over-it)).
6060
- Fixed DualShock 4 controllers not working in some scenarios by adding support for extended mode HID reports ([case 1281633](https://issuetracker.unity3d.com/issues/input-system-dualshock4-controller-returns-random-input-values-when-connected-via-bluetooth-while-steam-is-running), case 1409867).
6161
- Fixed `BackgroundBehavior.IgnoreFocus` having no effect when `Application.runInBackground` was false ([case 1400456](https://issuetracker.unity3d.com/issues/xr-head-tracking-lost-when-lost-focus-with-action-based-trackedposedriver-on-android)).
62+
- Fixed an issue where a device was left disabled when it was disconnected while an application was out-of-focus and then re-connected when in-focus (case 1404320).
6263

6364
#### Actions
6465

Packages/com.unity.inputsystem/InputSystem/InputManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,7 @@ private void OnNativeDeviceDiscovered(int deviceId, string deviceDescriptor)
22482248
device.m_DeviceId = deviceId;
22492249
device.m_DeviceFlags |= InputDevice.DeviceFlags.Native;
22502250
device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledInFrontend;
2251+
device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledWhileInBackground;
22512252
device.m_DeviceFlags &= ~InputDevice.DeviceFlags.DisabledStateHasBeenQueriedFromRuntime;
22522253

22532254
AddDevice(device);

0 commit comments

Comments
 (0)