summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-03-14 16:47:26 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-03-22 14:51:10 +1000
commitcea97dd5e09b165c2a4b2bbbb5741a03f152ed37 (patch)
treeb39106bdeaa6216376c1d6c6a57bb5cd84835521
parentb3348eb7e4e2187e11aa3c1cec2a58512759e6aa (diff)
Allow soft button areas to be specified in % of the touchpad
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--man/synaptics.man2
-rw-r--r--src/synaptics.c30
2 files changed, 30 insertions, 2 deletions
diff --git a/man/synaptics.man b/man/synaptics.man
index 23862e3..864a95f 100644
--- a/man/synaptics.man
+++ b/man/synaptics.man
@@ -526,6 +526,8 @@ parameters define the area of the right button, and the second four parameters
define the area of the middle button. The areas are defined by the left, right,
top, and bottom edges as sequential values of the property. If any edge is set
to 0, the button is assumed to extend to infinity in the given direction.
+Any of the values may be given as percentage of the touchpad width or
+height, whichever applies.
.
When the user performs a click within the defined soft button areas, the right
or middle click action is performed.
diff --git a/src/synaptics.c b/src/synaptics.c
index 3c5b12d..789de81 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -511,10 +511,12 @@ static void set_softbutton_areas_option(InputInfoPtr pInfo)
SynapticsPrivate *priv = pInfo->private;
SynapticsParameters *pars = &priv->synpara;
int values[8];
+ int in_percent = 0; /* bitmask for which ones are in % */
char *option_string;
char *next_num;
char *end_str;
int i;
+ int width, height;
if (!pars->clickpad)
return;
@@ -534,12 +536,36 @@ static void set_softbutton_areas_option(InputInfoPtr pInfo)
values[i] = value;
if (next_num != end_str)
+ {
+ if (end_str && *end_str == '%')
+ {
+ in_percent |= 1 << i;
+ end_str++;
+ }
next_num = end_str;
- else
+ } else
goto fail;
}
- if (i < 8 || *next_num != '\0' || !SynapticsIsSoftButtonAreasValid(values))
+ if (i < 8 || *next_num != '\0')
+ goto fail;
+
+ width = priv->maxx - priv->minx;
+ height = priv->maxy - priv->miny;
+
+ for (i = 0; in_percent && i < 8; i++)
+ {
+ int base, size;
+
+ if ((in_percent & (1 << i)) == 0 || values[i] == 0)
+ continue;
+
+ size = ((i % 4) < 2) ? width : height;
+ base = ((i % 4) < 2) ? priv->minx : priv->miny;
+ values[i] = base + size * values[i]/100.0;
+ }
+
+ if (!SynapticsIsSoftButtonAreasValid(values))
goto fail;
memcpy(pars->softbutton_areas[0], values, 4 * sizeof(int));