Skip to content
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

FIX: ISXB-704 scroll wheel support windows raw input value #1946

Merged
merged 16 commits into from
Jul 4, 2024

Conversation

benoitalain
Copy link
Collaborator

@benoitalain benoitalain commented Jun 4, 2024

Description

Fixes ISXB-704. Based on recently landed trunk PR.

Details of what was changed and the thought process can be found in this Google Document:
https://docs.google.com/document/d/1XCC6GqaWzKf1M1jm-UmKRn6sIlmvF7rvF1C8Ws5Yxa4/edit?usp=sharing

This PR introduces a new Settings option for the InputSystem package. See screenshot:
image

When the "Keep Platform Specific Input Range" option is selected, InputSystem actions that result from a Scroll Wheel hardware input will be expressed in the OS native range when retrieved with the InputAction.CallbackContext.ReadValue<Vector2>() method. On Windows, the values should range between -120 to 120, whereas on other platforms it will remain between -1 and 1 in general.

The new setting's default option is "Uniform Across All Platforms". When that option is selected, InputSystem actions that result from a Scroll Wheel will always be expressed in the -1 to 1 range, regardless of platform.

Changes made

Please write down a short description of what changes were made.

Notes

Please write down any additional notes, remove the section if not applicable.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • FogBugz ticket attached, example ([case %number%](https://issuetracker.unity3d.com/issues/...)).
    • FogBugz is marked as "Resolved" with next release version correctly set.
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@unity-cla-assistant
Copy link

unity-cla-assistant commented Jun 4, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting for now until aligned on potential graceful version handling.

get => NativeInputSystem.normalizeScrollWheelDelta;
set => NativeInputSystem.normalizeScrollWheelDelta = value;
#else
get; set;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see what role these getter setters play when earlier Unity version? Wouldn't it make sense to remove the property completely instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or would have expected hard coded behavior, but the answer is - it depends)

public float scrollWheelDeltaPerTick
{
#if UNITY_6000_0_OR_NEWER
get { return NativeInputSystem.GetScrollWheelDeltaPerTick(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend being consistent with getter below and use the short-hand version with =>

var scrollDelta = ctx.ReadValue<Vector2>();
if (scrollDelta.sqrMagnitude < k_SmallestReportedMovementSqrDist)
// ISXB-704: convert input value to uniform ticks before sending them to UI.
var scrollTicks = ctx.ReadValue<Vector2>() / InputSystem.scrollWheelDeltaPerTick;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is InputSystem.scrollWheelDeltaPerTick guaranteed to never be zero (to make sure we never can run into division by zero)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an Assert on the native side in the trunk PR, is that enough? I'm not a fan of adding more asserts on all the stages where we propagate that value, do you recommend adding one here too? Only here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If trunk version guarantees that its never zero I believe its fine to not check it in package. Agree that its better to define the API contract on lower level.

if (scrollDelta.sqrMagnitude < k_SmallestReportedMovementSqrDist)
// ISXB-704: convert input value to uniform ticks before sending them to UI.
var scrollTicks = ctx.ReadValue<Vector2>() / InputSystem.scrollWheelDeltaPerTick;
if (scrollTicks.sqrMagnitude < k_SmallestReportedMovementSqrDist)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to avoid the sqr root

@@ -281,6 +281,25 @@ private void OnFocusChanged(bool focus)
public Vector2 screenSize => new Vector2(Screen.width, Screen.height);
public ScreenOrientation screenOrientation => Screen.orientation;

public bool normalizeScrollWheelDelta
{
#if UNITY_6000_0_OR_NEWER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we run into issues with UNITY 6 revision prior to trunk change landing but maybe ok if/when that revision is current or is there opportunity for a even more specific define in the asmdef to detect the exact expected version once the trunk change lands maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the general solution to this problem is. There are other places in the Input System package code where we have a similar problem, so if we find a solution for this we should apply it everywhere (at once) probably.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was after above was whether UNITY_6000_0_OR_NEWER was specific enough or whether to define a custom asmdef symbol based on version value to define a symbol more specifically reflecting the change as introduced into UNITY_6000 version. There are other examples here https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef but I noticed they very not specific on a "sub-version" level so probably ok.

[Category(kTestCategory)]
[TestCase(1.0f)]
[TestCase(120.0f)]
public void UIActionScroll_ReceivesNormalizedScrollWheelDelta(float scrollWheelDeltaPerTick)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these tests to cover scaling.

@ekcoh
Copy link
Collaborator

ekcoh commented Jun 4, 2024

Looks like a branch update and CI rerun might be in order.

@benoitalain benoitalain force-pushed the isxb-704-scrollwheelwindowsrawvaluesupport branch from 50f03a1 to 8bb47fd Compare June 5, 2024 15:35
@benoitalain benoitalain requested a review from duckets June 6, 2024 14:17
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this now, I saw some minor comments remain but ok with me to leave them as-is if you consider it to be preferable to have it as it currently is.

@@ -281,6 +281,25 @@ private void OnFocusChanged(bool focus)
public Vector2 screenSize => new Vector2(Screen.width, Screen.height);
public ScreenOrientation screenOrientation => Screen.orientation;

public bool normalizeScrollWheelDelta
{
#if UNITY_6000_0_OR_NEWER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was after above was whether UNITY_6000_0_OR_NEWER was specific enough or whether to define a custom asmdef symbol based on version value to define a symbol more specifically reflecting the change as introduced into UNITY_6000 version. There are other examples here https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef but I noticed they very not specific on a "sub-version" level so probably ok.

var scrollDelta = ctx.ReadValue<Vector2>();
if (scrollDelta.sqrMagnitude < k_SmallestReportedMovementSqrDist)
// ISXB-704: convert input value to uniform ticks before sending them to UI.
var scrollTicks = ctx.ReadValue<Vector2>() / InputSystem.scrollWheelDeltaPerTick;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If trunk version guarantees that its never zero I believe its fine to not check it in package. Agree that its better to define the API contract on lower level.

@benoitalain benoitalain requested a review from Pauliusd01 June 21, 2024 13:45
Copy link
Collaborator

@duckets duckets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with amendments to tooltip and API docs

Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of concerns from me:

  • I did not need these changes to fix the issue, simply opening the Editor version that has your latest changes is enough to fix it
  • The ifdefs for the code are not granular enough and I still get errors about missing Editor code on 6.0.6f1 Editor, should that be changed?

Also, please take a look at the slack discussion about this change in our input channel

@benoitalain
Copy link
Collaborator Author

Couple of concerns from me:

  • I did not need these changes to fix the issue, simply opening the Editor version that has your latest changes is enough to fix it
  • The ifdefs for the code are not granular enough and I still get errors about missing Editor code on 6.0.6f1 Editor, should that be changed?

Also, please take a look at the slack discussion about this change in our input channel

You say you only need the Editor changes, are you sure there's no copy of my package fixes that survived in your Library folder? Otherwise I can't see how the InputSystemUIInputModule fixes could come from the Editor only... makes no sense :-(

About the ifdefs not being granular enough, I'll comment in the slack discussion but I'm not sure there's a clean solution.

@Pauliusd01
Copy link
Collaborator

Couple of concerns from me:

  • I did not need these changes to fix the issue, simply opening the Editor version that has your latest changes is enough to fix it
  • The ifdefs for the code are not granular enough and I still get errors about missing Editor code on 6.0.6f1 Editor, should that be changed?

Also, please take a look at the slack discussion about this change in our input channel

You say you only need the Editor changes, are you sure there's no copy of my package fixes that survived in your Library folder? Otherwise I can't see how the InputSystemUIInputModule fixes could come from the Editor only... makes no sense :-(

It's the user project from ISXB-704 with no library and 1.8.2 input system

@Pauliusd01 Pauliusd01 self-requested a review July 2, 2024 14:30
@benoitalain
Copy link
Collaborator Author

Couple of concerns from me:

  • I did not need these changes to fix the issue, simply opening the Editor version that has your latest changes is enough to fix it
  • The ifdefs for the code are not granular enough and I still get errors about missing Editor code on 6.0.6f1 Editor, should that be changed?

Also, please take a look at the slack discussion about this change in our input channel

You say you only need the Editor changes, are you sure there's no copy of my package fixes that survived in your Library folder? Otherwise I can't see how the InputSystemUIInputModule fixes could come from the Editor only... makes no sense :-(

It's the user project from ISXB-704 with no library and 1.8.2 input system

Hi! I've updated the PR description to emphasize the changes that this PR contains. It's not observable scroll range fixes in any of the UI systems, but just the option to allow InputSystem actions returning values in the -120 to 120 range.

…om:Unity-Technologies/InputSystem into isxb-704-scrollwheelwindowsrawvaluesupport

# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the extra info, lgtm. Do check the CI failures though, there's more than the usual culprit ones

@benoitalain benoitalain merged commit 78e4e0e into develop Jul 4, 2024
77 of 79 checks passed
@benoitalain benoitalain deleted the isxb-704-scrollwheelwindowsrawvaluesupport branch July 4, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants