summaryrefslogtreecommitdiff
path: root/src/libinput-util.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-01-12 08:39:47 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2015-01-13 13:35:42 +1000
commitc35885e87dabdcba016cbfa124c384dd440411f1 (patch)
tree95f82dca798afb4dfcadae7cf446c5eae2317cc8 /src/libinput-util.c
parent2708be27b29ad7f7cc5d99a8ba0ebba490847e01 (diff)
Parse the MOUSE_WHEEL_CLICK_ANGLE udev property if present
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
Diffstat (limited to 'src/libinput-util.c')
-rw-r--r--src/libinput-util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libinput-util.c b/src/libinput-util.c
index c16de1b..49e297a 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -171,3 +171,33 @@ parse_mouse_dpi_property(const char *prop)
}
return dpi;
}
+
+/**
+ * Helper function to parse the MOUSE_WHEEL_CLICK_ANGLE property from udev.
+ * Property is of the form:
+ * MOUSE_WHEEL_CLICK_ANGLE=<integer>
+ * Where the number indicates the degrees travelled for each click.
+ *
+ * We skip preceding whitespaces and parse the first number seen. If
+ * multiple numbers are specified, we ignore those.
+ *
+ * @param prop The value of the udev property (without the MOUSE_WHEEL_CLICK_ANGLE=)
+ * @return The angle of the wheel (may be negative) or 0 on error.
+ */
+int
+parse_mouse_wheel_click_angle_property(const char *prop)
+{
+ int angle = 0,
+ nread = 0;
+
+ while(*prop != 0 && *prop == ' ')
+ prop++;
+
+ sscanf(prop, "%d%n", &angle, &nread);
+ if (nread == 0 || angle == 0 || abs(angle) > 360)
+ return 0;
+ if (prop[nread] != ' ' && prop[nread] != '\0')
+ return 0;
+
+ return angle;
+}