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 mouse handler moving OS pen cursor #6534

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hwsmm
Copy link
Contributor

@hwsmm hwsmm commented Feb 20, 2025

I've had this issue for a while, and just found out that the new PenHandler was the culprit.
Whenever PenHandler moves the cursor, MouseHandler tries to forcefully move the cursor to the reported position because it is not self-feedback, but SDL3 PenHandler also represents OS cursor.

I think the process here is like: Pen reports a position -> PenHandler becomes mouseSource -> MouseHandler moves the OS cursor -> Pen moves -> OS cursor gets repositioned -> Pen somehow reports the forcefully moved position? -> Cursor is now stuck

I don't have a tablet driver installed on my Windows installation, so it's only tested on Linux. This is somehow only reproducible on X11 for me. The issue author was probably using Xwayland. Honestly, I don't know how moving a cursor (SDL_WarpMouseInWindow) is affecting an absolute positioning device, but I don't really want to dig deeper.

I'm not sure if isSelfFeedback is needed anymore, but I just focused on fixing the issue. Please tell me if there's a better way to fix it!

@rootino
Copy link

rootino commented Feb 21, 2025

This pr works for me.
Sorry for the confusion earlier, i was under the wrong impression.

@Susko3
Copy link
Member

Susko3 commented Feb 21, 2025

FeedbackMousePositionChange() is working as intended here. It's whole purpose is to position the OS cursor to the OTD / SDL pen position. For reference, it works fine on Windows+OTD with high precision mouse disabled.

OS cursor gets repositioned -> Pen somehow reports the forcefully moved position?

This seems like a bug in SDL or your desktop environment. We are calling SDL_WarpMouseInWindow(), it should not affect the pen position.

Please enable SDL_EVENT_LOGGING=2, add logging to handleMouseMotionEvent() and provide the full logs. I guess you can put the logs in the issue thread ppy/osu#31948.

@hwsmm
Copy link
Contributor Author

hwsmm commented Feb 21, 2025

ppy/osu#31948 (comment)

Comment on lines 140 to 145
public virtual void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback)
public virtual void FeedbackMousePositionChange(Vector2 position, bool isSelfFeedback, bool isOsCursor)
{
if (!Enabled.Value)
return;

if (!isSelfFeedback && isActive.Value)
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a bug in SDL3 on X11, I would make an ugly hack to to make this work on linux. Instead of adding in a nice isOsCursor, making this seem as expected behaviour, I would instead make FeedbackMousePositionChange(Vector2 position, InputHandler handler).

And them simply:

if (handler != this && isActive.Value && !(handler is PenHandler && RuntimeInfo.OS == Platform.Linux && FrameworkEnvironment.UseSDL3))

Or maybe create a LinuxSDL3MouseHandler and override the warping decision making there.

Copy link
Contributor Author

@hwsmm hwsmm Feb 21, 2025

Choose a reason for hiding this comment

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

This is a bug in X11/SDL, but I think this is also a logical issue on o!f side, too. Why should we move the 'mouse' cursor to the 'pen' position when they are essentially sharing the same cursor?

I'm fine with the diff to fix the issue on X11, but I just want to clarify.

Copy link
Member

Choose a reason for hiding this comment

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

They are not the same cursor when using Windows Ink or built-in OpenTabletDriver.

Copy link
Contributor Author

@hwsmm hwsmm Feb 22, 2025

Choose a reason for hiding this comment

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

Built-in OTD is not affected by this PR since it is not handled by PenHandler. I just tested Windows Ink, and Windows (or driver?) seems to save position of tablet and mouse separately, so the cursor is moved to the most recent mouse position once mouse take the cursor back after the pen goes out of a range. I'm not sure if moving a mouse cursor for pen is a desired behavior when Windows Ink is in use since a pen cursor is also an OS cursor, but I'll make it exclusive to Linux for now.

Copy link
Member

@Susko3 Susko3 left a comment

Choose a reason for hiding this comment

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

LGTM otherwise.

{
if (!Enabled.Value)
return;

if (!isSelfFeedback && isActive.Value)
// https://github.com/ppy/osu/issues/31948
// Pen malfunctions if MouseHandler tries to move the mouse cursor to pen position on Linux/X11.
Copy link
Member

Choose a reason for hiding this comment

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

The original issue mentions this happening on Wayland. Maybe putting X11 here is a bit misleading, unless your testing has proven otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was only reproducible on X11 for me, but I'll just remove X11 for less confusion.

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

Successfully merging this pull request may close these issues.

[Linux/wayland] cursor doesn't move when using tablet.
4 participants