summaryrefslogtreecommitdiff
path: root/src/libinput-util.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2017-02-09 10:25:50 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2017-02-09 11:54:03 +1000
commit784241427ba66eabc23996db2e07c18f225cb6d6 (patch)
treebd10612d557d2ccc73e75e7503503f72a5146c6b /src/libinput-util.c
parent07860e5db680cf570c4bdb2985d8e210841bb9e2 (diff)
evdev: split calibration property parsing into a helper
So we can test it externally. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/libinput-util.c')
-rw-r--r--src/libinput-util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libinput-util.c b/src/libinput-util.c
index aa69a37b..d75955cf 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -278,6 +278,44 @@ parse_dimension_property(const char *prop, size_t *w, size_t *h)
return true;
}
+/**
+ * Parses a set of 6 space-separated floats.
+ *
+ * @param prop The string value of the property
+ * @param calibration Returns the six components
+ * @return true on success, false otherwise
+ */
+bool
+parse_calibration_property(const char *prop, float calibration_out[6])
+{
+ int idx;
+ char **strv;
+ float calibration[6];
+
+ if (!prop)
+ return false;
+
+ strv = strv_from_string(prop, " ");
+ if (!strv)
+ return false;
+
+ for (idx = 0; idx < 6; idx++) {
+ double v;
+ if (strv[idx] == NULL || !safe_atod(strv[idx], &v)) {
+ strv_free(strv);
+ return false;
+ }
+
+ calibration[idx] = v;
+ }
+
+ strv_free(strv);
+
+ memcpy(calibration_out, calibration, sizeof(calibration));
+
+ return true;
+}
+
bool
parse_switch_reliability_property(const char *prop,
enum switch_reliability *reliability)