summaryrefslogtreecommitdiff
path: root/src/libinput-util.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-06-30 12:00:53 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2015-07-14 10:12:12 +1000
commit5bebd4aea487203dedca985e7c8333261bdb677f (patch)
tree05af2f3b861a11f6c70547b7fa5fb610fa63a53d /src/libinput-util.c
parent35fb5412c5a481f6c045f628241d34c5c970f052 (diff)
util: add a helper function to parse a "WIDTHxHEIGHT" property
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.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 3a9c8db5..a383fa17 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -234,3 +234,33 @@ parse_trackpoint_accel_property(const char *prop)
return accel;
}
+
+/**
+ * Parses a simple dimension string in the form of "10x40". The two
+ * numbers must be positive integers in decimal notation.
+ * On success, the two numbers are stored in w and h. On failure, w and h
+ * are unmodified.
+ *
+ * @param prop The value of the property
+ * @param w Returns the first component of the dimension
+ * @param h Returns the second component of the dimension
+ * @return true on success, false otherwise
+ */
+bool
+parse_dimension_property(const char *prop, size_t *w, size_t *h)
+{
+ int x, y;
+
+ if (!prop)
+ return false;
+
+ if (sscanf(prop, "%dx%d", &x, &y) != 2)
+ return false;
+
+ if (x < 0 || y < 0)
+ return false;
+
+ *w = (size_t)x;
+ *h = (size_t)y;
+ return true;
+}