xwayland: Implement smooth scrolling
We don't even need to simulate button clicks; it's done automatically. This also fixes scrolling in Qt5 apps. Signed-off-by: Dima Ryazanov <dima@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
9ff89a2e46
commit
81a51a6cac
|
@ -43,7 +43,7 @@ static int
|
||||||
xwl_pointer_proc(DeviceIntPtr device, int what)
|
xwl_pointer_proc(DeviceIntPtr device, int what)
|
||||||
{
|
{
|
||||||
#define NBUTTONS 10
|
#define NBUTTONS 10
|
||||||
#define NAXES 2
|
#define NAXES 4
|
||||||
BYTE map[NBUTTONS + 1];
|
BYTE map[NBUTTONS + 1];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Atom btn_labels[NBUTTONS] = { 0 };
|
Atom btn_labels[NBUTTONS] = { 0 };
|
||||||
|
@ -67,8 +67,10 @@ xwl_pointer_proc(DeviceIntPtr device, int what)
|
||||||
|
|
||||||
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
|
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
|
||||||
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
|
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
|
||||||
|
axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HWHEEL);
|
||||||
|
axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_WHEEL);
|
||||||
|
|
||||||
if (!InitValuatorClassDeviceStruct(device, 2, btn_labels,
|
if (!InitValuatorClassDeviceStruct(device, NAXES, btn_labels,
|
||||||
GetMotionHistorySize(), Absolute))
|
GetMotionHistorySize(), Absolute))
|
||||||
return BadValue;
|
return BadValue;
|
||||||
|
|
||||||
|
@ -77,6 +79,13 @@ xwl_pointer_proc(DeviceIntPtr device, int what)
|
||||||
0, 0xFFFF, 10000, 0, 10000, Absolute);
|
0, 0xFFFF, 10000, 0, 10000, Absolute);
|
||||||
InitValuatorAxisStruct(device, 1, axes_labels[1],
|
InitValuatorAxisStruct(device, 1, axes_labels[1],
|
||||||
0, 0xFFFF, 10000, 0, 10000, Absolute);
|
0, 0xFFFF, 10000, 0, 10000, Absolute);
|
||||||
|
InitValuatorAxisStruct(device, 2, axes_labels[2],
|
||||||
|
NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
|
||||||
|
InitValuatorAxisStruct(device, 3, axes_labels[3],
|
||||||
|
NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
|
||||||
|
|
||||||
|
SetScrollValuator(device, 2, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE);
|
||||||
|
SetScrollValuator(device, 3, SCROLL_TYPE_VERTICAL, 1.0, SCROLL_FLAG_PREFERRED);
|
||||||
|
|
||||||
if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
|
if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
|
||||||
return BadValue;
|
return BadValue;
|
||||||
|
@ -259,54 +268,24 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
||||||
uint32_t time, uint32_t axis, wl_fixed_t value)
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
||||||
{
|
{
|
||||||
struct xwl_seat *xwl_seat = data;
|
struct xwl_seat *xwl_seat = data;
|
||||||
int index, count;
|
int index;
|
||||||
int i, val;
|
|
||||||
const int divisor = 10;
|
const int divisor = 10;
|
||||||
ValuatorMask mask;
|
ValuatorMask mask;
|
||||||
|
|
||||||
if (time - xwl_seat->scroll_time > 2000) {
|
|
||||||
xwl_seat->vertical_scroll = 0;
|
|
||||||
xwl_seat->horizontal_scroll = 0;
|
|
||||||
}
|
|
||||||
xwl_seat->scroll_time = time;
|
|
||||||
|
|
||||||
/* FIXME: Need to do proper smooth scrolling here! */
|
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case WL_POINTER_AXIS_VERTICAL_SCROLL:
|
case WL_POINTER_AXIS_VERTICAL_SCROLL:
|
||||||
xwl_seat->vertical_scroll += value / divisor;
|
index = 3;
|
||||||
val = wl_fixed_to_int(xwl_seat->vertical_scroll);
|
|
||||||
xwl_seat->vertical_scroll -= wl_fixed_from_int(val);
|
|
||||||
|
|
||||||
if (val <= -1)
|
|
||||||
index = 4;
|
|
||||||
else if (val >= 1)
|
|
||||||
index = 5;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
break;
|
break;
|
||||||
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
|
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
|
||||||
xwl_seat->horizontal_scroll += value / divisor;
|
index = 2;
|
||||||
val = wl_fixed_to_int(xwl_seat->horizontal_scroll);
|
|
||||||
xwl_seat->horizontal_scroll -= wl_fixed_from_int(val);
|
|
||||||
|
|
||||||
if (val <= -1)
|
|
||||||
index = 6;
|
|
||||||
else if (val >= 1)
|
|
||||||
index = 7;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
valuator_mask_zero(&mask);
|
valuator_mask_zero(&mask);
|
||||||
|
valuator_mask_set_double(&mask, index, wl_fixed_to_double(value) / divisor);
|
||||||
count = abs(val);
|
QueuePointerEvents(xwl_seat->pointer, MotionNotify, 0, POINTER_RELATIVE, &mask);
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
QueuePointerEvents(xwl_seat->pointer, ButtonPress, index, 0, &mask);
|
|
||||||
QueuePointerEvents(xwl_seat->pointer, ButtonRelease, index, 0, &mask);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_pointer_listener pointer_listener = {
|
static const struct wl_pointer_listener pointer_listener = {
|
||||||
|
|
|
@ -122,10 +122,6 @@ struct xwl_seat {
|
||||||
struct xorg_list link;
|
struct xorg_list link;
|
||||||
CursorPtr x_cursor;
|
CursorPtr x_cursor;
|
||||||
|
|
||||||
wl_fixed_t horizontal_scroll;
|
|
||||||
wl_fixed_t vertical_scroll;
|
|
||||||
uint32_t scroll_time;
|
|
||||||
|
|
||||||
size_t keymap_size;
|
size_t keymap_size;
|
||||||
char *keymap;
|
char *keymap;
|
||||||
struct wl_surface *keyboard_focus;
|
struct wl_surface *keyboard_focus;
|
||||||
|
|
Loading…
Reference in New Issue