From b667107d1acea44bd2b4e62cf4a9976d375881fd Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Thu, 8 Aug 2024 17:29:43 +0900 Subject: [PATCH] input: move to section This allows per-device configuration of scroll factor (e.g. setting different scroll factors for mice and touchpads). --- docs/labwc-config.5.scd | 7 ++++--- docs/rc.xml.all | 3 ++- include/config/libinput.h | 1 + include/config/rcxml.h | 1 - include/labwc.h | 2 ++ src/config/libinput.c | 1 + src/config/rcxml.c | 20 +++++++++++++++++--- src/input/cursor.c | 11 +++++++++-- src/seat.c | 9 +++++++++ 9 files changed, 45 insertions(+), 10 deletions(-) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index 7ff83625..6da0af34 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -603,9 +603,6 @@ extending outward from the snapped edge. ** Set double click time in milliseconds. Default is 500. -** - Set scroll factor. Default is 1.0. - ** Multiple ** can exist within one **; and multiple ** can exist within one **. @@ -814,6 +811,7 @@ extending outward from the snapped edge. + 1.0 ``` @@ -939,6 +937,9 @@ The most common matrices are: visit https://wayland.freedesktop.org/libinput/doc/latest/absolute-axes.html#calibration-of-absolute-devices for more information. +** + Set scroll factor. Default is 1.0. + ## WINDOW RULES Two types of window rules are supported, actions and properties. They are diff --git a/docs/rc.xml.all b/docs/rc.xml.all index b3b7821f..ab462a14 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -330,7 +330,6 @@ 500 - 1.0 @@ -559,6 +558,7 @@ - clickMethod [none|buttonAreas|clickfinger] - sendEventsMode [yes|no|disabledOnExternalMouse] - calibrationMatrix [six float values split by space] + - scrollFactor [float] --> @@ -575,6 +575,7 @@ + 1.0 diff --git a/include/config/libinput.h b/include/config/libinput.h index 0c211613..94a99a3a 100644 --- a/include/config/libinput.h +++ b/include/config/libinput.h @@ -31,6 +31,7 @@ struct libinput_category { int click_method; /* -1 or libinput_config_click_method */ int send_events_mode; /* -1 or libinput_config_send_events_mode */ bool have_calibration_matrix; + double scroll_factor; float calibration_matrix[6]; }; diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 03a25881..cb56d473 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -110,7 +110,6 @@ struct rcxml { /* mouse */ long doubleclick_time; /* in ms */ struct wl_list mousebinds; /* struct mousebind.link */ - double scroll_factor; /* touch tablet */ struct wl_list touch_configs; diff --git a/include/labwc.h b/include/labwc.h index 14ce607c..30f9fbaf 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -71,6 +71,8 @@ enum input_mode { struct input { struct wlr_input_device *wlr_input_device; struct seat *seat; + /* Set for pointer/touch devices */ + double scroll_factor; struct wl_listener destroy; struct wl_list link; /* seat.inputs */ }; diff --git a/src/config/libinput.c b/src/config/libinput.c index af4f1bd0..42ec647a 100644 --- a/src/config/libinput.c +++ b/src/config/libinput.c @@ -26,6 +26,7 @@ libinput_category_init(struct libinput_category *l) l->click_method = -1; l->send_events_mode = -1; l->have_calibration_matrix = false; + l->scroll_factor = 1.0; } enum lab_libinput_device_type diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 923822fc..30fd6afe 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -63,6 +63,8 @@ static struct window_rule *current_window_rule; static struct action *current_window_rule_action; static struct view_query *current_view_query; static struct action *current_child_action; +/* for backword compatibility of */ +static double mouse_scroll_factor = -1; enum font_place { FONT_PLACE_NONE = 0, @@ -733,6 +735,8 @@ fill_libinput_category(char *nodename, char *content) current_libinput_category->have_calibration_matrix = false; } g_strfreev(elements); + } else if (!strcasecmp(nodename, "scrollFactor")) { + set_double(content, ¤t_libinput_category->scroll_factor); } } @@ -1011,7 +1015,8 @@ entry(xmlNode *node, char *nodename, char *content) wlr_log(WLR_ERROR, "invalid doubleClickTime"); } } else if (!strcasecmp(nodename, "scrollFactor.mouse")) { - set_double(content, &rc.scroll_factor); + /* This is deprecated. Show an error message in post_processing() */ + set_double(content, &mouse_scroll_factor); } else if (!strcasecmp(nodename, "name.context.mouse")) { current_mouse_context = content; current_mousebind = NULL; @@ -1345,7 +1350,6 @@ rcxml_init(void) rc.raise_on_focus = false; rc.doubleclick_time = 500; - rc.scroll_factor = 1.0; rc.tablet.force_mouse_emulation = false; rc.tablet.output_name = NULL; @@ -1596,12 +1600,21 @@ post_processing(void) rc.font_osd.name = xstrdup("sans"); } if (!libinput_category_get_default()) { - /* So we still allow tap to click by default */ + /* So we set default values of and */ struct libinput_category *l = libinput_category_create(); /* Prevents unused variable warning when compiled without asserts */ (void)l; assert(l && libinput_category_get_default() == l); } + if (mouse_scroll_factor >= 0) { + wlr_log(WLR_ERROR, " is deprecated" + " and overwrites ." + " Use only ."); + struct libinput_category *l; + wl_list_for_each(l, &rc.libinput_categories, link) { + l->scroll_factor = mouse_scroll_factor; + } + } int nr_workspaces = wl_list_length(&rc.workspace_config.workspaces); if (nr_workspaces < rc.workspace_config.min_nr_workspaces) { @@ -1884,4 +1897,5 @@ rcxml_finish(void) current_field = NULL; current_window_rule = NULL; current_window_rule_action = NULL; + mouse_scroll_factor = -1; } diff --git a/src/input/cursor.c b/src/input/cursor.c index 3b2583f0..cd28cf44 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -1335,6 +1335,13 @@ cursor_axis(struct wl_listener *listener, void *data) struct seat *seat = wl_container_of(listener, seat, cursor_axis); struct wlr_pointer_axis_event *event = data; struct server *server = seat->server; + + /* input->scroll_factor is set for pointer/touch devices */ + assert(event->pointer->base.type == WLR_INPUT_DEVICE_POINTER + || event->pointer->base.type == WLR_INPUT_DEVICE_TOUCH); + struct input *input = event->pointer->base.data; + double scroll_factor = input->scroll_factor; + struct cursor_context ctx = get_cursor_context(server); idle_manager_notify_activity(seat->seat); @@ -1349,8 +1356,8 @@ cursor_axis(struct wl_listener *listener, void *data) /* Notify the client with pointer focus of the axis event. */ wlr_seat_pointer_notify_axis(seat->seat, event->time_msec, - event->orientation, rc.scroll_factor * event->delta, - round(rc.scroll_factor * event->delta_discrete), + event->orientation, scroll_factor * event->delta, + round(scroll_factor * event->delta_discrete), event->source, event->relative_direction); } } diff --git a/src/seat.c b/src/seat.c index 49f317cc..004b610e 100644 --- a/src/seat.c +++ b/src/seat.c @@ -114,7 +114,11 @@ configure_libinput(struct wlr_input_device *wlr_input_device) wlr_log(WLR_ERROR, "no wlr_input_device"); return; } + struct input *input = wlr_input_device->data; + + /* Set scroll factor to 1.0 for Wayland/X11 backends or virtual pointers */ if (!wlr_input_device_is_libinput(wlr_input_device)) { + input->scroll_factor = 1.0; return; } @@ -247,6 +251,9 @@ configure_libinput(struct wlr_input_device *wlr_input_device) wlr_log(WLR_INFO, "calibration matrix configured"); libinput_device_config_calibration_set_matrix(libinput_dev, dc->calibration_matrix); } + + wlr_log(WLR_INFO, "scroll factor configured"); + input->scroll_factor = dc->scroll_factor; } static struct wlr_output * @@ -286,6 +293,7 @@ new_pointer(struct seat *seat, struct wlr_input_device *dev) { struct input *input = znew(*input); input->wlr_input_device = dev; + dev->data = input; configure_libinput(dev); wlr_cursor_attach_input_device(seat->cursor, dev); @@ -354,6 +362,7 @@ new_touch(struct seat *seat, struct wlr_input_device *dev) { struct input *input = znew(*input); input->wlr_input_device = dev; + dev->data = input; configure_libinput(dev); wlr_cursor_attach_input_device(seat->cursor, dev); /* In support of running with WLR_WL_OUTPUTS set to >=2 */