-
Notifications
You must be signed in to change notification settings - Fork 332
NEW: Added Focus Events to Input Event Queue #2365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
af12382
00f9a33
431a40f
07b6445
4533fbf
e1e5c26
687cd5a
2adf1d3
21c13f2
84a848d
48b2e53
1f99472
c527198
e63d74d
700c8dd
a97d931
45a64eb
df8c990
5b92fe7
2aad9f2
eb257b0
eeb7e1c
8c159e8
2bdf412
4ab32cb
e12c5ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| using UnityEngine.Scripting; | ||
| using UnityEngine.TestTools; | ||
| using UnityEngine.TestTools.Utils; | ||
| using UnityEngineInternal.Input; | ||
| using Gyroscope = UnityEngine.InputSystem.Gyroscope; | ||
| using UnityEngine.TestTools.Constraints; | ||
| using Is = NUnit.Framework.Is; | ||
|
|
@@ -1522,7 +1523,7 @@ public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus() | |
| Assert.That(device, Is.Not.Null); | ||
|
|
||
| // Loose focus. | ||
| runtime.PlayerFocusLost(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: false); | ||
| InputSystem.Update(); | ||
|
|
||
| // Disconnect. | ||
|
|
@@ -1534,7 +1535,7 @@ public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus() | |
| Assert.That(InputSystem.devices, Is.Empty); | ||
|
|
||
| // Regain focus. | ||
| runtime.PlayerFocusGained(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: true); | ||
| InputSystem.Update(); | ||
|
|
||
| var newDeviceId = runtime.ReportNewInputDevice(deviceDesc); | ||
|
|
@@ -4604,7 +4605,13 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change) | |
| InputSystem.onDeviceChange += DeviceChangeCallback; | ||
|
|
||
| var eventCount = 0; | ||
| InputSystem.onEvent += (eventPtr, _) => ++ eventCount; | ||
| InputSystem.onEvent += (eventPtr, _) => | ||
| { | ||
| // Focus events will always be processed no matter the state | ||
| // Since the test relies on counting events based on state, dont count focus events | ||
| if (eventPtr.data->type != (FourCC)FocusConstants.kEventType) | ||
| ++eventCount; | ||
| }; | ||
|
|
||
| Assert.That(trackedDevice.enabled, Is.True); | ||
| Assert.That(mouse.enabled, Is.True); | ||
|
|
@@ -4647,7 +4654,8 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change) | |
| } | ||
|
|
||
| // Lose focus. | ||
| runtime.PlayerFocusLost(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: false); | ||
| InputSystem.Update(InputUpdateType.Dynamic); | ||
|
|
||
| Assert.That(sensor.enabled, Is.False); | ||
| Assert.That(disabledDevice.enabled, Is.False); | ||
|
|
@@ -5068,7 +5076,8 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change) | |
| commands.Clear(); | ||
|
|
||
| // Regain focus. | ||
| runtime.PlayerFocusGained(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: true); | ||
| InputSystem.Update(InputUpdateType.Dynamic); | ||
|
|
||
| Assert.That(sensor.enabled, Is.False); | ||
| Assert.That(disabledDevice.enabled, Is.False); | ||
|
|
@@ -5275,13 +5284,10 @@ void DeviceChangeCallback(InputDevice device, InputDeviceChange change) | |
| "Sync Gamepad", "Sync Joystick", | ||
| "Sync TrackedDevice", "Sync TrackedDevice2", | ||
| "Sync Mouse", "Sync Mouse2", "Sync Mouse3", | ||
| "Sync Keyboard", "Reset Joystick" | ||
| })); | ||
| // Enabled devices that don't support syncs get reset. | ||
| Assert.That(changes, Is.EquivalentTo(new[] | ||
| { | ||
| "SoftReset Mouse1", "SoftReset Mouse3", "HardReset Joystick", "SoftReset TrackedDevice2" | ||
| "Sync Keyboard" | ||
| })); | ||
| // Enabled devices that don't support syncs dont get reset for Ignore Focus as we do not want to cancel any actions. | ||
VeraMommersteeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Assert.That(changes, Is.Empty); | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -5318,7 +5324,13 @@ public void Devices_CanSkipProcessingEventsWhileInBackground() | |
| Assert.That(performedCount, Is.EqualTo(1)); | ||
|
|
||
| // Lose focus | ||
| runtime.PlayerFocusLost(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: false); | ||
| #if UNITY_INPUTSYSTEM_SUPPORTS_FOCUS_EVENTS | ||
| // in the new system, we have to process the focus event to update the state of the devices. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: Avoid terms like "new" and "old", instead be specific, e.g. "Since Unity 6000.5.a8, we have..." (or whatever is the appropriate version). "New" is relative to something, and it is not clear to what, so this won't age well I am afraid.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively just skip what is before the "comma" since the define should also states the change version. |
||
| // In the old system, this wouldn't work and would make the test fal | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of "In the old system" maybe just "Previously"? |
||
| InputSystem.Update(); | ||
| #endif | ||
|
|
||
| Assert.That(gamepad.enabled, Is.False); | ||
|
|
||
| // Queue an event while in the background. We don't want to see this event to be processed once focus | ||
|
|
@@ -5329,7 +5341,7 @@ public void Devices_CanSkipProcessingEventsWhileInBackground() | |
| InputSystem.Update(); | ||
|
|
||
| // Gain focus | ||
| runtime.PlayerFocusGained(); | ||
| ScheduleFocusChangedEvent(applicationHasFocus: true); | ||
|
|
||
| // Run update to try process events accordingly once focus is gained | ||
| InputSystem.Update(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.