summaryrefslogtreecommitdiff
path: root/tools/libinput-debug-gui.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2018-11-22 10:24:54 +1000
committerJosé Expósito <jose.exposito89@gmail.com>2021-08-31 08:45:01 +0200
commit6bb02aaf307a38e60ec8e6b2198d8e0c30d59a95 (patch)
tree0078abc6aa906a55afbee130e49ca5baca619604 /tools/libinput-debug-gui.c
parent427c855d21b442620bf6472c2a0585ddca9673e0 (diff)
downloadlibinput-6bb02aaf307a38e60ec8e6b2198d8e0c30d59a95.tar.gz
High-resolution scroll wheel support
Starting with kernel v5.0 two new axes are available for high-resolution wheel scrolling: REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES. Both axes send data in fractions of 120 where each multiple of 120 amounts to one logical scroll event. Fractions of 120 indicate a wheel movement less than one detent. This commit adds a new API for scroll events. Three new event types that encode the axis source in the event type name and a new API to get a normalized-to-120 value that also used by Windows and the kernel (each multiple of 120 represents a logical scroll click). This addresses a main shortcoming with the existing API - it was unreliable to calculate the click angle based on the axis value+discrete events and thus any caller using the axis value alone would be left with some ambiguity. With the v120 API it's now possible to (usually) calculate the click angle, but more importantly it provides the simplest hw-independent way of scrolling by a click or a fraction of a click. A new event type is required, the only way to integrate the v120 value otherwise was to start sending events with a discrete value of 0. This would break existing xf86-input-libinput (divide by zero, fixed in 0.28.2) and weston (general confusion). mutter, kwin are unaffected. With the new API, the old POINTER_AXIS event are deprecated - callers should use the new API where available and discard any POINTER_AXIS events. Notable: REL_WHEEL/REL_HWHEEL are emulated by the kernel but there's no guarantee that they'll come every accumulated 120 values, e.g. Logitech mice often send events that don't add up to 120 per detent. We use the kernel's wheel click emulation instead of doing our own. libinput guarantees high-resolution events even on pre-5.0 kernels. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Diffstat (limited to 'tools/libinput-debug-gui.c')
-rw-r--r--tools/libinput-debug-gui.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index 861116e4..0ef66145 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -85,10 +85,6 @@ struct point {
double x, y;
};
-struct device_user_data {
- struct point scroll_accumulated;
-};
-
struct evdev_device {
struct list node;
struct libevdev *evdev;
@@ -1287,7 +1283,6 @@ register_evdev_device(struct window *w, struct libinput_device *dev)
const char *device_node;
int fd;
struct evdev_device *d;
- struct device_user_data *data;
ud = libinput_device_get_udev_device(dev);
device_node = udev_device_get_devnode(ud);
@@ -1310,9 +1305,6 @@ register_evdev_device(struct window *w, struct libinput_device *dev)
d->evdev = evdev;
d->libinput_device =libinput_device_ref(dev);
- data = zalloc(sizeof *data);
- libinput_device_set_user_data(dev, data);
-
c = g_io_channel_unix_new(fd);
g_io_channel_set_encoding(c, NULL, NULL);
d->source_id = g_io_add_watch(c, G_IO_IN,
@@ -1463,44 +1455,33 @@ static void
handle_event_axis(struct libinput_event *ev, struct window *w)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
- struct libinput_device *dev = libinput_event_get_device(ev);
- struct device_user_data *data = libinput_device_get_user_data(dev);
double value;
- int discrete;
+ enum libinput_pointer_axis axis;
+ enum libinput_event_type type;
- assert(data);
+ type = libinput_event_get_type(ev);
- if (libinput_event_pointer_has_axis(p,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
- value = libinput_event_pointer_get_axis_value(p,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+ axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
+ if (libinput_event_pointer_has_axis(p, axis)) {
+ value = libinput_event_pointer_get_scroll_value(p, axis);
w->scroll.vy += value;
w->scroll.vy = clip(w->scroll.vy, 0, w->height);
- data->scroll_accumulated.y += value;
- discrete = libinput_event_pointer_get_axis_value_discrete(p,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
- if (discrete) {
- w->scroll.vy_discrete += data->scroll_accumulated.y;
+ if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) {
+ w->scroll.vy_discrete += value;
w->scroll.vy_discrete = clip(w->scroll.vy_discrete, 0, w->height);
- data->scroll_accumulated.y = 0;
}
}
- if (libinput_event_pointer_has_axis(p,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
- value = libinput_event_pointer_get_axis_value(p,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
+ axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
+ if (libinput_event_pointer_has_axis(p, axis)) {
+ value = libinput_event_pointer_get_scroll_value(p, axis);
w->scroll.hx += value;
w->scroll.hx = clip(w->scroll.hx, 0, w->width);
- data->scroll_accumulated.x += value;
- discrete = libinput_event_pointer_get_axis_value_discrete(p,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
- if (discrete) {
- w->scroll.hx_discrete += data->scroll_accumulated.x;
+ if (type == LIBINPUT_EVENT_POINTER_SCROLL_WHEEL) {
+ w->scroll.hx_discrete += value;
w->scroll.hx_discrete = clip(w->scroll.hx_discrete, 0, w->width);
- data->scroll_accumulated.x = 0;
}
}
}
@@ -1798,6 +1779,11 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
case LIBINPUT_EVENT_TOUCH_FRAME:
break;
case LIBINPUT_EVENT_POINTER_AXIS:
+ /* ignore */
+ break;
+ case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
+ case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
+ case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
handle_event_axis(ev, w);
break;
case LIBINPUT_EVENT_POINTER_BUTTON: