backends/x11: Emit discrete scroll events for accumulated smooth events

MetaVirtualInputDeviceX11 currently doesn't handle smooth scroll events
at all.
So, if a user of the remote desktop API uses smooth scroll events, then
only the wayland backend handles these events.
The user of the remote desktop API however, might not know which
backend is being used and actually the user should not even have to
care about it.

Actual smooth events cannot be emulated in the X11 events.
What can be done however is accumulating smooth events and then when
the accumulated steps surpass the DISCRETE_SCROLL_STEP value, emit a
discrete scroll event.
So, do exactly that, to make smooth scroll events work when the remote
desktop API is used with the x11 backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1727>
This commit is contained in:
Pascal Nowack 2021-02-11 12:12:09 +01:00
parent 64834aee23
commit a5d692582d

View File

@ -28,9 +28,14 @@
#include "meta-keymap-x11.h" #include "meta-keymap-x11.h"
#include "meta-virtual-input-device-x11.h" #include "meta-virtual-input-device-x11.h"
#define DISCRETE_SCROLL_STEP 10.0
struct _MetaVirtualInputDeviceX11 struct _MetaVirtualInputDeviceX11
{ {
ClutterVirtualInputDevice parent; ClutterVirtualInputDevice parent;
double accum_scroll_dx;
double accum_scroll_dy;
}; };
G_DEFINE_TYPE (MetaVirtualInputDeviceX11, G_DEFINE_TYPE (MetaVirtualInputDeviceX11,
@ -112,6 +117,39 @@ meta_virtual_input_device_x11_notify_scroll_continuous (ClutterVirtualInputDevic
ClutterScrollSource scroll_source, ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags) ClutterScrollFinishFlags finish_flags)
{ {
MetaVirtualInputDeviceX11 *virtual_device_x11;
ClutterScrollDirection direction;
int i, n_xscrolls, n_yscrolls;
virtual_device_x11 = META_VIRTUAL_INPUT_DEVICE_X11 (virtual_device);
virtual_device_x11->accum_scroll_dx += dx;
virtual_device_x11->accum_scroll_dy += dy;
n_xscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dx) + DBL_EPSILON) /
DISCRETE_SCROLL_STEP);
n_yscrolls = floor ((fabs (virtual_device_x11->accum_scroll_dy) + DBL_EPSILON) /
DISCRETE_SCROLL_STEP);
direction = virtual_device_x11->accum_scroll_dx > 0 ? CLUTTER_SCROLL_RIGHT
: CLUTTER_SCROLL_LEFT;
for (i = 0; i < n_xscrolls; ++i)
{
meta_virtual_input_device_x11_notify_discrete_scroll (
virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
}
direction = virtual_device_x11->accum_scroll_dy > 0 ? CLUTTER_SCROLL_DOWN
: CLUTTER_SCROLL_UP;
for (i = 0; i < n_yscrolls; ++i)
{
meta_virtual_input_device_x11_notify_discrete_scroll (
virtual_device, time_us, direction, CLUTTER_SCROLL_SOURCE_WHEEL);
}
virtual_device_x11->accum_scroll_dx =
fmod (virtual_device_x11->accum_scroll_dx, DISCRETE_SCROLL_STEP);
virtual_device_x11->accum_scroll_dy =
fmod (virtual_device_x11->accum_scroll_dy, DISCRETE_SCROLL_STEP);
} }
static void static void