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

Add a way to detect if an input device supports pressure #426

Open
SleepProgger opened this issue Jan 31, 2020 · 8 comments
Open

Add a way to detect if an input device supports pressure #426

SleepProgger opened this issue Jan 31, 2020 · 8 comments

Comments

@SleepProgger
Copy link

Describe the project you are working on:
NA

Describe the problem or limitation you are having in your project:
There doesn't seem to be a way to detect if the input device used supports pressure. In my cases at least pressure with a mouse is set to 0. This alone is not enough to decide if the device supports pressure though as graphic tablets also can produce a MouseMotionEvent with a pressure of 0 (at least with my Huion 420 using wacom driver on linux).
This mostly happens when stopping to draw (pen up).

Describe how this feature / enhancement will help you overcome this problem or limitation:
With that information i would be able to support mouse and pens with the same codebase.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
NA

Describe implementation detail for your proposal (in code), if possible:
The best way i can think of would be to add a is_pressure_supported attribute to the MouseMotionEvent.
An alternative would be to use -1 as default for unsupported devices, but might break existing scripts.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not that i am aware of.

Is there a reason why this should be core and not an add-on in the asset library?:
Addons can't really patch existing event classes.

@SleepProgger
Copy link
Author

Just in case someone else runs into this and need a (crude) workaround:
Simply keep a Dictionary for all seen device-id -> pressure support (boolean).
If a MouseMoveEvent with pressure != 0 comes in set pressure_support_map[event.device] = true-
Then if pressure_support_map.get(event.device) equals true you know that device supports pressure (and did send at least one movementEvent before).

It kinda works, but i am not really happy with it at all.

@SleepProgger
Copy link
Author

Never mind the previous comment. The device_id for my pen my mouse are the same.
So i can't think of any workaround at all.
I really hope that can be added soon.
I would be willing to send a PR for this, as without this i can't really use pressure in any useful fashion.

Something like a proper device_id would also be awesome tho ;)

@Calinou
Copy link
Member

Calinou commented Feb 6, 2020

I would be willing to send a PR for this, as without this i can't really use pressure in any useful fashion.

Feel free to do this 🙂

@SleepProgger
Copy link
Author

SleepProgger commented Feb 8, 2020

I could probably write and test this for X11 and windows, but would need help with the other platforms that support pressure (i think web export for example doesn't ?).

But the solution might be even easier.
If mouse pressure would be 1 by default, instead of 0 which it is currently, it should work as is for probably most use cases.
It would probably still be good to add a support_pressure flag, but not as important i think as it is now.
Not sure if changing a default would be considered a breaking change though.
I'd really like to have this problem solved in 3.2 to be honest.

Another alternative which would allow my above posted workaround to work would be to expose a proper DeviceId. This might be easier (but i am really not experienced with that whole area tbh.)

@SleepProgger
Copy link
Author

SleepProgger commented Feb 27, 2020

Ok, after some discussion on IRC it seems that on Macs pressure from devices not supporting pressure is set to 1 when the(a?) button is down and 0 otherwise.
Windows and Linux seem to always have the pressure set to 0 for devices not supporting pressure.

I suggest changing the windows and Linux backends so they behave like the Mac one.
On one hand this could be considered breaking changes, but on the other hand the current behaviour being different between platforms sounds like a Bug to me.
I could send in a PR to emulate Mac behaviour for Linux and Windows if that has any chance being accepted. (?)

Additional exposing a device ID would be really nice regardless as this would allow user to configure each device (Pressure curve, Default tilt and so on). But this would be way less important for me personally

@HEAVYPOLY
Copy link

HEAVYPOLY commented Apr 26, 2020

Agreed..I prefer the Mac way of handling devices that don't support pressure. (pressure 1 when button down, 0 when button up). For example if you are controlling opacity with pressure, it's better to have 1 by default vs 0.

@OverloadedOrama
Copy link
Contributor

OverloadedOrama commented May 7, 2020

Wouldn't it also be better if pressure was a property of InputEventMouse, instead of just InputEventMouseMotion? That way, InputEventMouseButton could also have access to pressure.

I tried the pressure changes in Godot 3.2.2 beta 2 with a mouse on Windows, and while the pressure is now 1 when I am moving the mouse and holding the left mouse button, if I just click without moving the mouse, the pressure is 0. I'm not sure what the behavior is on a tablet.

@SleepProgger
Copy link
Author

@OverloadedOrama Yes imo that would be better, but its probably better suited in another issue ?

I'll keep this proposal open since there is still no working deviceID, but the change to the default pressure at least made it workable again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants