switchbrew / libnx

Library for Switch Homebrew

Home Page:https://switchbrew.github.io/libnx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mouse is unusable (positions clamped at 0..1280 and 0..720, no way to read all entries for velocities)

rsn8887 opened this issue · comments

hidReadMouse is useless as it is currently: it doesn't report relative mouse motion dx and dy correctly. It reports velocities and positions, but positions are clamped, and velocities only contain the value of the last entry of 17 entries per frame.

https://switchbrew.github.io/libnx/structHidMouse.html

The mouse report per frame should consist of 17 entries of velocities. Currently, only the latest one can be read out by apps using hidMouseRead. This is not enough detail to calculate accurate dx and dy values.

x and y is fine, but is clamped between 0...1280 and 0..720, so it is useless to read out relative mouse motion dx, dy, regardless of mouse position.

The relevant code is here:

HidMouseEntry *newMouseEntry = &sharedMem->mouse.entries[latestMouseEntry];

A new function is needed, or hidMouseRead could be modified to return all 17 report entries. Then dx and dy could be constructed as sum over ALL the velocity entries, I hope.

sdk-nso does have a func which can read multiple mouse entries - something similar could be added to libnx.

I am not sure how much it matters, but shouldn't velocityX and velocityY in MousePosition be signed integers? Or maybe even floats? For sure they can be negative.

See here: https://switchbrew.github.io/libnx/structMousePosition.html

Actually I found a way to use velocities. It works just fine if you ensure to only read once per frame.

Shall I close this issue, or do you want it to stay around?

I think it's worth leaving open for the time being.

FWIW, on my system with old sysver, (velocity)x/(velocity)y doesn't seem to properly update (even prior to above commit) - hence leaving the types for those alone for now.