Skip to content

Conversation

@Kiisu-Master
Copy link
Contributor

@Kiisu-Master Kiisu-Master commented Nov 1, 2025

fixes #64296
Note: I have no idea if how i did things is correct, this is my second time working with c++ and godot source.
I just tried to follow how things were done in the surrounding code.

Pointer warp protocol links:

https://invent.kde.org/plasma/kwin/-/merge_requests/6460
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/337
https://wayland.app/protocols/pointer-warp-v1

Tested on latest kwin plasma 6.5, seems to work. I haven't tested multiple windows.
The project i tested it with is GodSVG.
Pointer warping in the editor viewport doesn't seem to work though.

@Kiisu-Master
Copy link
Contributor Author

It seems the commit hash in thirdparty/README.md for wayland-protocols didn't get updated here ae74c0c

I just copied the pointer warp xml file from the main branch, should i include the one from 1.45 if its different?

Comment on lines +4433 to +4454
if (!ss) {
return;
}

WindowState *ws = window_get_state(ss->pointer_data.pointed_id);

int wl_pos_x = 0;
int wl_pos_y = 0;

if (ws) {
// NOTE: It looks like it's not really recommended to convert from
// "godot-space" to "wayland-space" and in general I received mixed feelings
// discussing about this. I'm not really sure about the maths behind this but,
// oh well, we're setting a cursor hint. ¯\_(ツ)_/¯
// See: https://oftc.irclog.whitequark.org/wayland/2023-08-23#1692756914-1692816818
wl_pos_x = std::round(p_to.x / window_state_get_scale_factor(ws));
wl_pos_y = std::round(p_to.y / window_state_get_scale_factor(ws));
}

if (ss) {
seat_state_warp_pointer(ss, wl_pos_x, wl_pos_y);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied this code from pointer_set_hint, should there be a function to remove the duplicate scaling code?
What about the comment?

Comment on lines +460 to +465
// WaylandThread::PointerConstraint old_constraint = wayland_thread.pointer_get_constraint();
wayland_thread.pointer_warp(p_to);
// wayland_thread.pointer_set_constraint(WaylandThread::PointerConstraint::LOCKED);
// wayland_thread.pointer_set_hint(p_to);

wayland_thread.pointer_set_constraint(WaylandThread::PointerConstraint::LOCKED);
wayland_thread.pointer_set_hint(p_to);

wayland_thread.pointer_set_constraint(old_constraint);
// wayland_thread.pointer_set_constraint(old_constraint);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this try to use the old logic in case the pointer-warp protocol isn't supported?
This old code didn't seem to work on kwin

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, it was very wonky (and I think that I might've done something wrong actually, like, regarding surface commit timing or something) but it's better than nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How should i check if the pointer-warp protocol is available?
It seems the registry is a private field.

@deralmas
Copy link
Contributor

deralmas commented Nov 2, 2025

I just copied the pointer warp xml file from the main branch, should i include the one from 1.45 if its different?

Yea, as wayland-protocols is at that version. If the protocol is not available there feel free to make a PR updating it.

Copied this code from pointer_set_hint, should there be a function to remove the duplicate scaling code?

Nah, it's done in only two places now and it's something that we should generally not do, as pointed out by the big comment.

What about the comment?

Not sure tbh. I'll be fair, in these cases I just keep them there, duplicated. You never know if the other half will be there by the time you'll need to read that comment again :P

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.

modifiying mouse position doesn't work (Linux Wayland)

3 participants