nixos-config/modules/scroll-boost/b7b5c5ef5f34802fc5f57e68493afaea5db7cdb4.diff
Sean Buckley ca2edd4ae8 add files
2020-09-18 09:54:09 -04:00

176 lines
7 KiB
Diff

diff --git a/include/libinput-properties.h b/include/libinput-properties.h
index a701316890d3d45511199f40207145bb08de4b4f..3dd659fbd157ecbe6be8382b9bf5d9bd8a8f4beb 100644
--- a/include/libinput-properties.h
+++ b/include/libinput-properties.h
@@ -109,6 +109,12 @@
only one is enabled at a time at max, read-only */
#define LIBINPUT_PROP_SCROLL_METHOD_ENABLED_DEFAULT "libinput Scroll Method Enabled Default"
+/* Scroll distance scale: FLOAT, 2 values, 32 bit */
+#define LIBINPUT_PROP_SCROLL_DISTANCE_SCALE "libinput Scroll Distance Scale"
+
+/* Scroll distance scale: FLOAT, 2 values, 32 bit, read only */
+#define LIBINPUT_PROP_SCROLL_DISTANCE_SCALE_DEFAULT "libinput Scroll Distance Scale Default"
+
/* Scroll button for button scrolling: 32-bit int, 1 value */
#define LIBINPUT_PROP_SCROLL_BUTTON "libinput Button Scrolling Button"
diff --git a/man/libinput.man b/man/libinput.man
index dbf7dee7621d1c2f463813569202896a61259cfd..008a36acba47739ff24dbe8f23f1f6e650822ab4 100644
--- a/man/libinput.man
+++ b/man/libinput.man
@@ -264,6 +264,9 @@ Indicates which scroll methods are available on this device.
3 boolean values (8 bit, 0 or 1), in order "two-finger", "edge", "button".
Indicates which scroll method is currently enabled on this device.
.TP 7
+.BI "libinput Scroll Distance Scale"
+2 32-bit float values. Scroll distance is multiplied by this before being
+passed to the client. First is vertical scale, second is horizontal scale.
.BI "libinput Send Events Modes Available"
2 boolean values (8 bit, 0 or 1), in order "disabled" and
"disabled-on-external-mouse". Indicates which send-event modes are available
diff --git a/src/xf86libinput.c b/src/xf86libinput.c
index ff76895cbbe55ac3c5ed999cb54cefb1e7493063..05ac092615a447be19b25d47e93f476833a6d222 100644
--- a/src/xf86libinput.c
+++ b/src/xf86libinput.c
@@ -131,6 +131,7 @@ struct xf86libinput {
struct scroll_axis {
int dist;
double fraction;
+ double scale;
} v, h;
} scroll;
@@ -1651,6 +1652,18 @@ calculate_axis_value(struct xf86libinput *driver_data,
value = libinput_event_pointer_get_axis_value(event, axis);
}
+ //LogMessageVerb(X_INFO, 0, "scroll of %f on axis %d", value, axis);
+ switch (axis) {
+ case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
+ //LogMessageVerb(X_INFO, 0, "scaled by %f to %f\n", driver_data->scroll.h.scale, value);
+ value *= driver_data->scroll.h.scale;
+ break;
+ case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
+ //LogMessageVerb(X_INFO, 0, "scaled by %f to %f\n", driver_data->scroll.v.scale, value);
+ value *= driver_data->scroll.v.scale;
+ break;
+ }
+
*value_out = value;
return true;
@@ -3430,6 +3443,9 @@ xf86libinput_pre_init(InputDriverPtr drv,
driver_data->scroll.v.dist = 15;
driver_data->scroll.h.dist = 15;
+ driver_data->scroll.v.scale = 1;
+ driver_data->scroll.h.scale = 1;
+
if (!is_subdevice) {
if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
driver_data->capabilities |= CAP_POINTER;
@@ -3570,6 +3586,8 @@ static Atom prop_scroll_method_enabled;
static Atom prop_scroll_method_default;
static Atom prop_scroll_button;
static Atom prop_scroll_button_default;
+static Atom prop_scroll_distance_scale;
+static Atom prop_scroll_distance_scale_default;
static Atom prop_click_methods_available;
static Atom prop_click_method_enabled;
static Atom prop_click_method_default;
@@ -4147,6 +4165,35 @@ LibinputSetPropertyScrollButton(DeviceIntPtr dev,
return Success;
}
+static inline int
+LibinputSetPropertyScrollDistanceScale(DeviceIntPtr dev,
+ Atom atom,
+ XIPropertyValuePtr val,
+ BOOL checkonly)
+{
+ InputInfoPtr pInfo = dev->public.devicePrivate;
+ struct xf86libinput *driver_data = pInfo->private;
+ float *data;
+
+ if (val->format != 32 || val->size != 2 || val->type != prop_float) {
+ LogMessageVerb(X_INFO, 0, "bad match");
+ return BadMatch;
+ }
+
+ data = (float*)val->data;
+ LogMessageVerb(X_INFO, 0, "i want to set it to %f %f\n", data[0], data[1]);
+ if (checkonly) {
+ if (!xf86libinput_check_device(dev, atom))
+ return BadMatch;
+ } else {
+ LogMessageVerb(X_INFO, 0, "setting scroll.v.scale to %f and scroll.h.scale to %f\n", data[0], data[1]);
+ driver_data->scroll.v.scale = data[0];
+ driver_data->scroll.h.scale = data[1];
+ }
+
+ return Success;
+}
+
static inline int
LibinputSetPropertyClickMethod(DeviceIntPtr dev,
Atom atom,
@@ -4521,6 +4568,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
rc = LibinputSetPropertyScrollMethods(dev, atom, val, checkonly);
else if (atom == prop_scroll_button)
rc = LibinputSetPropertyScrollButton(dev, atom, val, checkonly);
+ else if (atom == prop_scroll_distance_scale)
+ rc = LibinputSetPropertyScrollDistanceScale(dev, atom, val, checkonly);
else if (atom == prop_click_method_enabled)
rc = LibinputSetPropertyClickMethod(dev, atom, val, checkonly);
else if (atom == prop_middle_emulation)
@@ -4561,6 +4610,7 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
atom == prop_scroll_method_default ||
atom == prop_scroll_methods_available ||
atom == prop_scroll_button_default ||
+ atom == prop_scroll_distance_scale_default ||
atom == prop_click_method_default ||
atom == prop_click_methods_available ||
atom == prop_middle_emulation_default ||
@@ -5072,6 +5122,33 @@ LibinputInitScrollMethodsProperty(DeviceIntPtr dev,
}
}
+static void
+LibinputInitScrollDistanceScaleProperty(DeviceIntPtr dev,
+ struct xf86libinput *driver_data,
+ struct libinput_device *device)
+{
+ float scroll_distance_scale[2] = {driver_data->scroll.v.scale, driver_data->scroll.h.scale};
+
+ if (!subdevice_has_capabilities(dev, CAP_POINTER))
+ return;
+
+ LogMessageVerb(X_INFO, 0, "making %s property with %f %f\n", LIBINPUT_PROP_SCROLL_DISTANCE_SCALE, scroll_distance_scale[0], scroll_distance_scale[1]);
+ prop_scroll_distance_scale = LibinputMakeProperty(dev,
+ LIBINPUT_PROP_SCROLL_DISTANCE_SCALE,
+ prop_float, 32,
+ 2, scroll_distance_scale);
+ if (!prop_scroll_distance_scale)
+ return;
+
+ scroll_distance_scale[0] = 1;
+ scroll_distance_scale[1] = 1;
+ LogMessageVerb(X_INFO, 0, "making %s property with %f %f\n", LIBINPUT_PROP_SCROLL_DISTANCE_SCALE_DEFAULT, scroll_distance_scale[0], scroll_distance_scale[1]);
+ prop_scroll_distance_scale_default = LibinputMakeProperty(dev,
+ LIBINPUT_PROP_SCROLL_DISTANCE_SCALE_DEFAULT,
+ prop_float, 32,
+ 2, scroll_distance_scale);
+}
+
static void
LibinputInitClickMethodsProperty(DeviceIntPtr dev,
struct xf86libinput *driver_data,
@@ -5476,6 +5553,7 @@ LibinputInitProperty(DeviceIntPtr dev)
LibinputInitNaturalScrollProperty(dev, driver_data, device);
LibinputInitDisableWhileTypingProperty(dev, driver_data, device);
LibinputInitScrollMethodsProperty(dev, driver_data, device);
+ LibinputInitScrollDistanceScaleProperty(dev, driver_data, device);
LibinputInitClickMethodsProperty(dev, driver_data, device);
LibinputInitMiddleEmulationProperty(dev, driver_data, device);
LibinputInitRotationAngleProperty(dev, driver_data, device);