[PATCH synaptics 1/3] Improve readability of the soft button areas

walter harms wharms at bfs.de
Wed Apr 3 00:09:08 PDT 2013



Am 03.04.2013 04:09, schrieb Peter Hutterer:
> Replace the hardcoded indices with enums that are somewhat expressive.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  src/synaptics.c | 78 +++++++++++++++++++++++++++++++++++----------------------
>  1 file changed, 48 insertions(+), 30 deletions(-)
> 
> diff --git a/src/synaptics.c b/src/synaptics.c
> index df092c0..50eb34b 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -367,42 +367,53 @@ SynapticsIsSoftButtonAreasValid(int *values)
>      Bool right_disabled = FALSE;
>      Bool middle_disabled = FALSE;
>  
> +    enum {
> +        RBL = 0,
> +        RBR = 1,
> +        RBT = 2,
> +        RBB = 3,
> +        MBL = 4,
> +        MBR = 5,
> +        MBT = 6,
> +        MBB = 7,
> +    };
> +
reading about readability; Could you please add a comment what RBL should mean ?
That would help people reading the code in future.

re,
 wh


>      /* 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 +1371,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;


More information about the xorg-devel mailing list