Skip to content

Commit 9972e7c

Browse files
ekcohEricFultonjamesmcgill
authored
NEW: Expose displayIndex for multi-display support (#1623)
* Add support for distinguishing pointer events from multiple displays Tests should cover every new code path. * remove virtual keyword and add missing layout entry * fix array out of bounds exception due to EraseAtWithCapacity mutating count * update precompiled layout for FastTouchscreen * remove uneeded displayIndex setter * remove platform specific defines * more cleanup on TouchSimulatorArray handling * improve displayIndex property inline doc * set displayIndex outside of getIndex function * Fixed formatting violations in UITests.cs * Updating tests for multi-display input changes * formatting * Fixing multi-input test * Ignore 3 failing tvos tests. Seem related to ISX-448 * remove unwanted changes to DefaultInputActions * fix changelog conflict and moved to Added section Co-authored-by: Eric Fulton <[email protected]> Co-authored-by: James McGill <[email protected]> Co-authored-by: James McGill <[email protected]>
1 parent 3342f7e commit 9972e7c

File tree

13 files changed

+1310
-592
lines changed

13 files changed

+1310
-592
lines changed

Assets/Tests/InputSystem/Plugins/UITests.cs

Lines changed: 310 additions & 20 deletions
Large diffs are not rendered by default.

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests.
1717
- Added the ability to change the origin positioning and movement behaviour of the OnScreenStick (`OnScreenStick.cs`) via the new `behaviour` property. This currently supports three modes of operation, two of which are new in addition to the previous behaviour. Based on the user contribution from [eblabs](https://github.com/eblabs) in [#658](https://github.com/Unity-Technologies/InputSystem/pull/658).
1818
- Significantly optimized cost of `InputAction.ReadValue` and `InputControl.ReadValue` calls by introducing caching behaviour to input controls. Input controls now keep track of whether their underlying state has been changed and only read the value from the underlying state and apply processors when absolutely necessary. Optimization is opt-in for now, please call `InputSystem.settings.SetInternalFeatureFlag("USE_READ_VALUE_CACHING", true);` in your project to enable it. If there are issues try enabling `InputSystem.settings.SetInternalFeatureFlag("PARANOID_READ_VALUE_CACHING_CHECKS", true);` and check in the console if there are any errors regarding caching.
1919
- Added a note in the [supported devices page](Documentation~/SupportedDevices.md) about DualSense support for Android devices.
20+
- Exposed `displayIndex` property for `Pointer`, `Touchscreen`, `TouchControl`, `TouchState`, `Mouse`, `MouseState` which enables look up of the logical screen associated with a pointer event via (display documentation)[https://docs.unity3d.com/ScriptReference/Display.html]
2021

2122
### Fixed
2223
- Fixed composite bindings incorrectly getting a control scheme assigned when pasting into input asset editor with a control scheme selected.

Packages/com.unity.inputsystem/InputSystem/Controls/TouchControl.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public class TouchControl : InputControl<TouchState>
3535
/// <seealso cref="phase"/>
3636
public TouchPressControl press { get; set; }
3737

38+
/// <summary>
39+
/// Gets the index of the display that was touched.
40+
/// <see href="https://docs.unity3d.com/ScriptReference/Display.html"/>
41+
/// </summary>
42+
public IntegerControl displayIndex { get; set; }
43+
3844
/// <summary>
3945
/// The ID of the touch contact as reported by the underlying system.
4046
/// </summary>
@@ -202,6 +208,7 @@ public TouchControl()
202208
protected override void FinishSetup()
203209
{
204210
press = GetChildControl<TouchPressControl>("press");
211+
displayIndex = GetChildControl<IntegerControl>("displayIndex");
205212
touchId = GetChildControl<IntegerControl>("touchId");
206213
position = GetChildControl<Vector2Control>("position");
207214
delta = GetChildControl<DeltaControl>("delta");

Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ public struct MouseState : IInputStateTypeInfo
7979
[InputControl(name = "pointerId", layout = "Digital", format = "BIT", sizeInBits = 1, offset = InputStateBlock.AutomaticOffset)] // Will stay at 0.
8080
public ushort buttons;
8181

82-
// Not currently used, but still needed in this struct for padding,
83-
// as il2cpp does not implement FieldOffset.
82+
/// <summary>
83+
/// The index of the display that was moused.
84+
/// </summary>
85+
[InputControl(name = "displayIndex", layout = "Integer", displayName = "Display Index")]
8486
[FieldOffset(26)]
85-
ushort displayIndex;
87+
public ushort displayIndex;
8688

8789
/// <summary>
8890
/// Number of clicks performed in succession.
8991
/// </summary>
9092
/// <value>Successive click count.</value>
9193
/// <seealso cref="Mouse.clickCount"/>
92-
[InputControl(layout = "Integer", displayName = "Click Count", synthetic = true)]
94+
[InputControl(name = "clickCount", layout = "Integer", displayName = "Click Count", synthetic = true)]
9395
[FieldOffset(28)]
9496
public ushort clickCount;
9597

@@ -286,6 +288,7 @@ protected override void FinishSetup()
286288
rightButton = GetChildControl<ButtonControl>("rightButton");
287289
forwardButton = GetChildControl<ButtonControl>("forwardButton");
288290
backButton = GetChildControl<ButtonControl>("backButton");
291+
displayIndex = GetChildControl<IntegerControl>("displayIndex");
289292
clickCount = GetChildControl<IntegerControl>("clickCount");
290293
base.FinishSetup();
291294
}

Packages/com.unity.inputsystem/InputSystem/Devices/Pointer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ internal struct PointerState : IInputStateTypeInfo
6060
[InputControl(name = "press", displayName = "Press", layout = "Button", format = "BIT", bit = 0)]
6161
public ushort buttons;
6262

63+
[InputControl(name = "displayIndex", layout = "Integer", displayName = "Display Index")]
64+
public ushort displayIndex;
65+
6366
public FourCC format => kFormat;
6467
}
6568
}
@@ -180,6 +183,13 @@ public class Pointer : InputDevice, IInputStateCallbackReceiver
180183
/// </remarks>
181184
public ButtonControl press { get; protected set; }
182185

186+
/// <summary>
187+
/// The index of the display the Pointer is currently on. This is useful for multiple screen setups.
188+
/// This may not be supported on all platforms. When unsupported, this will always produce the index of the primary display i.e. zero.
189+
/// <see href="https://docs.unity3d.com/ScriptReference/Display.html"/>
190+
/// </summary>
191+
public IntegerControl displayIndex { get; protected set; }
192+
183193
/// <summary>
184194
/// The pointer that was added or used last by the user or <c>null</c> if there is no pointer
185195
/// device connected to the system.
@@ -210,6 +220,7 @@ protected override void FinishSetup()
210220
radius = GetChildControl<Vector2Control>("radius");
211221
pressure = GetChildControl<AxisControl>("pressure");
212222
press = GetChildControl<ButtonControl>("press");
223+
displayIndex = GetChildControl<IntegerControl>("displayIndex");
213224

214225
base.FinishSetup();
215226
}

0 commit comments

Comments
 (0)