[PATCH] evdev-touchpad: Set some options using weston.ini

Armin K krejzi at email.com
Sat Jul 13 02:26:00 PDT 2013


This patch adds 3 new options to weston.ini to allow
the user to change default constant_accel_factor,
min_accel_factor and max_accel_factor. If no options
are set, it falls back using defaults as it did before.
---
 src/evdev-touchpad.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
 weston.ini           |  5 +++++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/evdev-touchpad.c b/src/evdev-touchpad.c
index 53300ce..996276f 100644
--- a/src/evdev-touchpad.c
+++ b/src/evdev-touchpad.c
@@ -26,10 +26,12 @@
 #include <math.h>
 #include <string.h>
 #include <stdbool.h>
+#include <unistd.h>
 #include <linux/input.h>
 
 #include "filter.h"
 #include "evdev.h"
+#include "../shared/config-parser.h"
 
 /* Default values */
 #define DEFAULT_CONSTANT_ACCEL_NUMERATOR 50
@@ -670,6 +672,44 @@ struct evdev_dispatch_interface touchpad_interface = {
 	touchpad_destroy
 };
 
+static void
+touchpad_parse_config(struct touchpad_dispatch *touchpad, double *diagonal)
+{
+	struct weston_config *config;
+	struct weston_config_section *s;
+	int config_fd;
+
+	char *constant_accel_factor;
+	char *min_accel_factor;
+	char *max_accel_factor;
+
+	config_fd = open_config_file("weston.ini");
+	config = weston_config_parse(config_fd);
+	close(config_fd);
+
+	s = weston_config_get_section(config, "touchpad", NULL, NULL);
+	weston_config_section_get_string(s, "constant_accel_factor", &constant_accel_factor, NULL);
+	weston_config_section_get_string(s, "min_accel_factor", &min_accel_factor, NULL);
+	weston_config_section_get_string(s, "max_accel_factor", &max_accel_factor, NULL);
+
+	if(constant_accel_factor)
+		touchpad->constant_accel_factor =
+			 atof(constant_accel_factor) / *diagonal;
+	else
+		touchpad->constant_accel_factor =
+			DEFAULT_CONSTANT_ACCEL_NUMERATOR / *diagonal;
+
+	if(min_accel_factor)
+		touchpad->min_accel_factor = atof(min_accel_factor);
+	else
+		touchpad->min_accel_factor = DEFAULT_MIN_ACCEL_FACTOR;
+
+	if(max_accel_factor)
+		touchpad->max_accel_factor = atof(max_accel_factor);
+	else
+		touchpad->max_accel_factor = DEFAULT_MAX_ACCEL_FACTOR;
+}
+
 static int
 touchpad_init(struct touchpad_dispatch *touchpad,
 	      struct evdev_device *device)
@@ -710,11 +750,7 @@ touchpad_init(struct touchpad_dispatch *touchpad,
 	height = abs(device->abs.max_y - device->abs.min_y);
 	diagonal = sqrt(width*width + height*height);
 
-	touchpad->constant_accel_factor =
-		DEFAULT_CONSTANT_ACCEL_NUMERATOR / diagonal;
-
-	touchpad->min_accel_factor = DEFAULT_MIN_ACCEL_FACTOR;
-	touchpad->max_accel_factor = DEFAULT_MAX_ACCEL_FACTOR;
+	touchpad_parse_config(touchpad, &diagonal);
 
 	touchpad->hysteresis.margin_x =
 		diagonal / DEFAULT_HYSTERESIS_MARGIN_DENOMINATOR;
diff --git a/weston.ini b/weston.ini
index f2abceb..ff0f3ba 100644
--- a/weston.ini
+++ b/weston.ini
@@ -57,3 +57,8 @@ path=/usr/libexec/weston-keyboard
 #name=X1
 #mode=1024x768
 #transform=flipped-270
+
+#[touchpad]
+#constant_accel_factor = 50
+#min_accel_factor = 0.16
+#max_accel_factor = 1.0
-- 
1.8.3.2



More information about the wayland-devel mailing list