summaryrefslogtreecommitdiff
path: root/src/libinput-util.c
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2014-11-25 11:46:42 -0600
committerPeter Hutterer <peter.hutterer@who-t.net>2014-12-02 10:16:31 +1000
commit188d20b2012e73a29b7995eb911605ebdc3ae4a2 (patch)
treebd710d4a992587cbcf2fd30e72b7feeb8082fc1a /src/libinput-util.c
parentd7106544ea1200d06ee940464e63e4c21ba450e7 (diff)
evdev: Query mouse DPI from udev
Instead of using a hard coded mouse DPI value, we query it from udev. If it's not present or the property is obviously broken we fall back to default. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'src/libinput-util.c')
-rw-r--r--src/libinput-util.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 34d55496..923e1162 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -28,7 +28,9 @@
#include "config.h"
+#include <ctype.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -113,3 +115,56 @@ ratelimit_test(struct ratelimit *r)
return RATELIMIT_EXCEEDED;
}
+
+/* Helper function to parse the mouse DPI tag from udev.
+ * The tag is of the form:
+ * MOUSE_DPI=400 *1000 2000
+ * or
+ * MOUSE_DPI=400@125 *1000@125 2000@125
+ * Where the * indicates the default value and @number indicates device poll
+ * rate.
+ * Numbers should be in ascending order, and if rates are present they should
+ * be present for all entries.
+ *
+ * When parsing the mouse DPI property, if we find an error we just return 0
+ * since it's obviously invalid, the caller will treat that as an error and
+ * use a reasonable default instead. If the property contains multiple DPI
+ * settings but none flagged as default, we return the last because we're
+ * lazy and that's a silly way to set the property anyway.
+ */
+int
+parse_mouse_dpi_property(const char *prop)
+{
+ bool is_default = false;
+ int nread, dpi = 0, rate;
+
+ while (*prop != 0) {
+ if (*prop == ' ') {
+ prop++;
+ continue;
+ }
+ if (*prop == '*') {
+ prop++;
+ is_default = true;
+ if (!isdigit(prop[0]))
+ return 0;
+ }
+
+ /* While we don't do anything with the rate right now we
+ * will validate that, if it's present, it is non-zero and
+ * positive
+ */
+ rate = 1;
+ nread = 0;
+ sscanf(prop, "%d@%d%n", &dpi, &rate, &nread);
+ if (!nread)
+ sscanf(prop, "%d%n", &dpi, &nread);
+ if (!nread || dpi <= 0 || rate <= 0 || prop[nread] == '@')
+ return 0;
+
+ if (is_default)
+ break;
+ prop += nread;
+ }
+ return dpi;
+}