pqiv
pqiv copied to clipboard
Fullscreen mouse dragging incorrect under Wayland
When trying to drag the image with the mouse in fullscreen under Wayland, the image doesn't follow the mouse, but scrolls very fast and leaves the visible screen almost immediately. If started under XWayland by setting GDK_BACKEND=x11 it works correctly. Tested under sway and KDE-Plasma.
Thanks for reporting this! I don't currently have access to a wayland enabled machine, any help is greatly appreciated.
I don't understand exactly the calculations, but I think the dragging is implemented in the following lines? https://github.com/phillipberndt/pqiv/blob/c49c5f6db23a7a42587daf4cc16d104f30b92352/pqiv.c#L6953-L6954
If so, I inserted the following: printf("(%f, %f)\n", dev_x, dev_y); which produces values like the following under X11...
(0.000000, 24.980469)
(2.480469, 62.855469)
(-2.480469, 60.339844)
(-8.808594, 19.820312)
(-23.542969, 32.191406)
(-17.238281, 24.898438)
... and like the following under Wayland:
(956.000000, 322.000000)
(870.000000, 198.000000)
(870.000000, 198.000000)
(826.000000, 72.000000)
The numbers used in calculating dev_x and dev_y... https://github.com/phillipberndt/pqiv/blob/c49c5f6db23a7a42587daf4cc16d104f30b92352/pqiv.c#L6944-L6945 ... are the following under X11:
screen_geometry.width = 1704
screen_geometry.height = 960
screen_geometry.x = 0
screen_geometry.y = 0
event->x_root = 852
event->y_root = 480
screen_scale_factor = 1
... while under Wayland look like this:
screen_geometry.width = 3412
screen_geometry.height = 1920
screen_geometry.x = 0
screen_geometry.y = 0
event->x_root = 433
event->y_root = 555
screen_scale_factor = 2
One strange thing that I notice is that I've actually set my screen scale factor to 1.5 - if I reset it to 1, the problem remains, and the numbers change to:
screen_geometry.width = 2560
screen_geometry.height = 1440
event->x_root = 1045
event->y_root = 807
screen_scale_factor = 1
(of course, the event x_root and y_root values change while dragging the mouse, the above are just some examples) Do these help? The native screen resolution is 2560x1440.
GDK only supports integer scale factors. That explains why you don't see 1.5 there. I suspect the other misbehavior is a GTK issue as well :/
OK, thanks - I see that GDK is changing screen geometry and scale factor to maintain the correct ratio while keeping an integer scale factor, and that the calculation in pqiv's code finds the distance of the mouse event from the center of the screen - but in all cases the numbers seem to add up.
So, now I noticed the window_center_mouse() calls - if I understand correctly, you're warping the mouse to the center of the screen and trying to find how far it's being dragged to - but this doesn't work under Wayland. It seems that when using Xwayland the pointer warping is emulated (e.g. https://lists.x.org/archives/xorg-devel/2016-April/049351.html) but to support native Wayland another approach is needed - store the initial position on button press and work with positions relative to that, right?
The pointer is warped back to allow infinite dragging. Movement would stop as soon as you hit the screen boundary otherwise. So if we can find a way to fix this, that'd be my preferred approach. But using the last position sounds like a good hotfix!
I hadn't noticed that pqiv supports infinite dragging. That's a nice touch, other image viewers indeed stop dragging at screen edges - well done!
So, I investigated a little how it's done on Wayland, and as it turns out, there is a protocol extension to lock the pointer in place and get relative motion events. Unfortunately, GTK doesn't include support for it. For reference, it's used in Firefox, WebKit, and, as mentioned, xwayland [1] [2]
Using this extension, it's possible to fix this in the preferred way, but it needs a bunch of Wayland-specific code - would you find this acceptable? Not saying that I can provide these changes (it'll definitely take time to learn and put together everything needed) and I guess since you aren't on Wayland, it's not a big priority for you either. Just as a general question, since pqiv has a lean codebase.
Thanks!