summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-04-03 10:34:28 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-04-05 10:43:12 +1000
commit148afc2dd55bb5d256d8b251542c90bcca7aaf84 (patch)
treeafdd2a77a12812f2eb45a4293225b6a61c07f47e
parent691e8db4d8a5e35eb31f62d1e54523917e2830cd (diff)
Improve readability of the soft button areas
Replace the hardcoded indices with enums that are somewhat expressive. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/synaptics.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/src/synaptics.c b/src/synaptics.c
index df092c0..3437d9d 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -367,42 +367,55 @@ SynapticsIsSoftButtonAreasValid(int *values)
Bool right_disabled = FALSE;
Bool middle_disabled = FALSE;
+ enum {
+ /* right button left, right, top, bottom */
+ RBL = 0,
+ RBR = 1,
+ RBT = 2,
+ RBB = 3,
+ /* middle button left, right, top, bottom */
+ MBL = 4,
+ MBR = 5,
+ MBT = 6,
+ MBB = 7,
+ };
+
/* Check right button area */
- if ((((values[0] != 0) && (values[1] != 0)) && (values[0] > values[1])) ||
- (((values[2] != 0) && (values[3] != 0)) && (values[2] > values[3])))
+ if ((((values[RBL] != 0) && (values[RBR] != 0)) && (values[RBL] > values[RBR])) ||
+ (((values[RBT] != 0) && (values[RBB] != 0)) && (values[RBT] > values[RBB])))
return FALSE;
/* Check middle button area */
- if ((((values[4] != 0) && (values[5] != 0)) && (values[4] > values[5])) ||
- (((values[6] != 0) && (values[7] != 0)) && (values[6] > values[7])))
+ if ((((values[MBL] != 0) && (values[MBR] != 0)) && (values[MBL] > values[MBR])) ||
+ (((values[MBT] != 0) && (values[MBB] != 0)) && (values[MBT] > values[MBB])))
return FALSE;
- if (values[0] == 0 && values[1] == 0 && values[2] == 0 && values[3] == 0)
+ if (values[RBL] == 0 && values[RBR] == 0 && values[RBT] == 0 && values[RBB] == 0)
right_disabled = TRUE;
- if (values[4] == 0 && values[5] == 0 && values[6] == 0 && values[7] == 0)
+ if (values[MBL] == 0 && values[MBR] == 0 && values[MBT] == 0 && values[MBB] == 0)
middle_disabled = TRUE;
if (!right_disabled &&
- ((values[0] && values[0] == values[1]) ||
- (values[2] && values[2] == values[3])))
+ ((values[RBL] && values[RBL] == values[RBR]) ||
+ (values[RBT] && values[RBT] == values[RBB])))
return FALSE;
if (!middle_disabled &&
- ((values[4] && values[4] == values[5]) ||
- (values[6] && values[6] == values[7])))
+ ((values[MBL] && values[MBL] == values[MBR]) ||
+ (values[MBT] && values[MBT] == values[MBB])))
return FALSE;
/* Check for overlapping button areas */
if (!right_disabled && !middle_disabled) {
- int right_left = values[0] ? values[0] : INT_MIN;
- int right_right = values[1] ? values[1] : INT_MAX;
- int right_top = values[2] ? values[2] : INT_MIN;
- int right_bottom = values[3] ? values[3] : INT_MAX;
- int middle_left = values[4] ? values[4] : INT_MIN;
- int middle_right = values[5] ? values[5] : INT_MAX;
- int middle_top = values[6] ? values[6] : INT_MIN;
- int middle_bottom = values[7] ? values[7] : INT_MAX;
+ int right_left = values[RBL] ? values[RBL] : INT_MIN;
+ int right_right = values[RBR] ? values[RBR] : INT_MAX;
+ int right_top = values[RBT] ? values[RBT] : INT_MIN;
+ int right_bottom = values[RBB] ? values[RBB] : INT_MAX;
+ int middle_left = values[MBL] ? values[MBL] : INT_MIN;
+ int middle_right = values[MBR] ? values[MBR] : INT_MAX;
+ int middle_top = values[MBT] ? values[MBT] : INT_MIN;
+ int middle_bottom = values[MBB] ? values[MBB] : INT_MAX;
/* If areas overlap in the Y axis */
if ((right_bottom <= middle_bottom && right_bottom >= middle_top) ||
@@ -1360,23 +1373,30 @@ is_inside_button_area(SynapticsParameters * para, int which, int x, int y)
{
Bool inside_area = TRUE;
- if (para->softbutton_areas[which][0] == 0 &&
- para->softbutton_areas[which][1] == 0 &&
- para->softbutton_areas[which][2] == 0 &&
- para->softbutton_areas[which][3] == 0)
+ enum {
+ LEFT = 0,
+ RIGHT = 1,
+ TOP = 2,
+ BOTTOM = 3
+ };
+
+ if (para->softbutton_areas[which][LEFT] == 0 &&
+ para->softbutton_areas[which][RIGHT] == 0 &&
+ para->softbutton_areas[which][TOP] == 0 &&
+ para->softbutton_areas[which][BOTTOM] == 0)
return FALSE;
- if (para->softbutton_areas[which][0] &&
- x < para->softbutton_areas[which][0])
+ if (para->softbutton_areas[which][LEFT] &&
+ x < para->softbutton_areas[which][LEFT])
inside_area = FALSE;
- else if (para->softbutton_areas[which][1] &&
- x > para->softbutton_areas[which][1])
+ else if (para->softbutton_areas[which][RIGHT] &&
+ x > para->softbutton_areas[which][RIGHT])
inside_area = FALSE;
- else if (para->softbutton_areas[which][2] &&
- y < para->softbutton_areas[which][2])
+ else if (para->softbutton_areas[which][TOP] &&
+ y < para->softbutton_areas[which][TOP])
inside_area = FALSE;
- else if (para->softbutton_areas[which][3] &&
- y > para->softbutton_areas[which][3])
+ else if (para->softbutton_areas[which][BOTTOM] &&
+ y > para->softbutton_areas[which][BOTTOM])
inside_area = FALSE;
return inside_area;