-
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
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(); | ||
| ScheduleFocusEvent(false); | ||
| InputSystem.Update(); | ||
|
|
||
| // Disconnect. | ||
|
|
@@ -1534,7 +1535,7 @@ public void Devices_CanReconnectDevice_WhenDisconnectedWhileAppIsOutOfFocus() | |
| Assert.That(InputSystem.devices, Is.Empty); | ||
|
|
||
| // Regain focus. | ||
| runtime.PlayerFocusGained(); | ||
| ScheduleFocusEvent(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(); | ||
| ScheduleFocusEvent(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(); | ||
| ScheduleFocusEvent(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(); | ||
| ScheduleFocusEvent(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(); | ||
| ScheduleFocusEvent(true); | ||
|
|
||
| // Run update to try process events accordingly once focus is gained | ||
| InputSystem.Update(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,11 +158,10 @@ public void EnhancedTouch_SupportsEditorUpdates(InputSettings.UpdateMode updateM | |
| Assert.That(Touch.activeTouches, Has.Count.EqualTo(1)); | ||
|
|
||
| // And make sure we're not seeing the data in the editor. | ||
| runtime.PlayerFocusLost(); | ||
| ScheduleFocusEvent(false); | ||
|
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. Minor: It is only semantics, by I personally think a test fixture helper like is should be named what it does instead of reflecting implementation details (that changing focus leads to scheduling an event). E.g. Nitpick: When using trivial arguments like this, I think it's helpful to pass as named argument since
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. I only write this comment once even though it applies to all tests here, e.g. row 174 |
||
| InputSystem.Update(InputUpdateType.Editor); | ||
|
|
||
| Assert.That(Touch.activeTouches, Is.Empty); | ||
|
|
||
| // Feed some data into editor state. | ||
| BeginTouch(2, new Vector2(0.234f, 0.345f), queueEventOnly: true); | ||
| InputSystem.Update(InputUpdateType.Editor); | ||
|
|
@@ -171,8 +170,25 @@ public void EnhancedTouch_SupportsEditorUpdates(InputSettings.UpdateMode updateM | |
| Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(2)); | ||
|
|
||
| // Switch back to player. | ||
| runtime.PlayerFocusGained(); | ||
| InputSystem.Update(); | ||
| ScheduleFocusEvent(true); | ||
|
|
||
| // Explicitly schedule the player's configured update type rather than relying on the default. | ||
| // Without explicit scheduling, defaultUpdateType would be Editor (since focus has not yet been | ||
| // gained during update), causing the editor buffer to be used instead of the player buffer, | ||
| // which would retrieve the wrong active touch. A proper fix would require removing defaultUpdateType | ||
| // and splitting player/editor update loops into separate methods. | ||
| switch (updateMode) | ||
|
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. I think it would be cleaner, and separate concerns, if the type transform from I suspect that conversion happens in multiple places so such a conversion is likely reusable to reduce code-bloat as well. |
||
| { | ||
| case InputSettings.UpdateMode.ProcessEventsInDynamicUpdate: | ||
| InputSystem.Update(InputUpdateType.Dynamic); | ||
| break; | ||
| case InputSettings.UpdateMode.ProcessEventsInFixedUpdate: | ||
| InputSystem.Update(InputUpdateType.Fixed); | ||
| break; | ||
| case InputSettings.UpdateMode.ProcessEventsManually: | ||
| InputSystem.Update(InputUpdateType.Manual); | ||
| break; | ||
| } | ||
|
|
||
| Assert.That(Touch.activeTouches, Has.Count.EqualTo(1)); | ||
| Assert.That(Touch.activeTouches[0].touchId, Is.EqualTo(1)); | ||
|
|
@@ -1160,7 +1176,7 @@ public void EnhancedTouch_ActiveTouchesGetCanceledOnFocusLoss_WithRunInBackgroun | |
| Assert.That(Touch.activeTouches, Has.Count.EqualTo(1)); | ||
| Assert.That(Touch.activeTouches[0].phase, Is.EqualTo(TouchPhase.Began)); | ||
|
|
||
| runtime.PlayerFocusLost(); | ||
| ScheduleFocusEvent(false); | ||
|
|
||
| if (runInBackground) | ||
| { | ||
|
|
@@ -1171,7 +1187,7 @@ public void EnhancedTouch_ActiveTouchesGetCanceledOnFocusLoss_WithRunInBackgroun | |
| else | ||
| { | ||
| // When not running in the background, the same thing happens but only on focus gain. | ||
| runtime.PlayerFocusGained(); | ||
| ScheduleFocusEvent(true); | ||
| InputSystem.Update(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I have no problem with this approach or filtering at all. The first thing that strikes me though is that it sounds like the test is based on observing an exact number of events. This means that the test is very brittle and would brake down when any new (or user plugin injected) event is added. To avoid that, maybe it would make sense to instead only count the events relevant to the test to make it future proof? The system should be resilient to new events being added IMO. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That whole test is a mess IMO, it's the 800 line test and needs to be completely broken up, and yes having the test depend on event count makes it brittle. That is the reason I had to do the check there so it only counts the tests that it should for that test. I would say we leave it for now and instead just do a full refactor of this test as a separate pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a jira card for this as something that we need to do at some point. Which is looking at all the tests there and see if they make sense