[PATCH xfree86] Signed-off-by: Oleh Nykyforchyn <oleh.nyk at gmail.com>

Peter Hutterer peter.hutterer at who-t.net
Mon May 16 23:18:53 PDT 2011


On Mon, May 16, 2011 at 09:29:29PM +0300, Oleh R. Nykyforchyn wrote:
> xfree86: Allow "MatchLayout" string in config files
> 
> Usage example (tested on a dual-seat PC):
> Section "InputClass"
> 	Identifier "keyboard-all"
> 	MatchIsKeyboard "on"
> 	MatchDevicePath "/dev/input/event*"
> 	MatchLayout "!GeForce|!Matrox"
> 	Driver "evdev"
> 	Option "XkbLayout" "us"
> 	Option "XkbOptions" "terminate:ctrl_alt_bksp"
> EndSection
> 
> It disables auto keyboard configuration for layouts "GeForce" and "Matrox".
> 
> Signed-off-by: Oleh Nykyforchyn <oleh.nyk at gmail.com>
> ---
>  hw/xfree86/common/xf86Xinput.c |    7 +++++++
>  hw/xfree86/parser/InputClass.c |   21 +++++++++++++++++++++
>  hw/xfree86/parser/xf86Parser.h |    1 +
>  hw/xfree86/parser/xf86tokens.h |    1 +
>  4 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
> index 9462bad..0906c1c 100644
> --- a/hw/xfree86/common/xf86Xinput.c
> +++ b/hw/xfree86/common/xf86Xinput.c
> @@ -580,6 +580,13 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev,
>              return FALSE;
>      }
>  
> +    /* MatchLayout string */
> +    if (!list_is_empty(&iclass->match_layout)) {
> +        if (!MatchAttrToken((xf86ConfigLayout.id ? xf86ConfigLayout.id : ""),
> +            &iclass->match_layout, strcmp))
> +            return FALSE;

probably better to have a list_is_empty() && strlen(xf86ConfigLayout.id)
here instead of the rather convoluted ternary.

Rest looks good though

Cheers,
  Peter

> +    }
> +
>      /* MatchIs* booleans */
>      if (iclass->is_keyboard.set &&
>          iclass->is_keyboard.val != !!(attrs->flags & ATTR_KEYBOARD))
> diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
> index 9f88e7e..3f80170 100644
> --- a/hw/xfree86/parser/InputClass.c
> +++ b/hw/xfree86/parser/InputClass.c
> @@ -52,6 +52,7 @@ xf86ConfigSymTabRec InputClassTab[] =
>      {MATCH_USBID, "matchusbid"},
>      {MATCH_DRIVER, "matchdriver"},
>      {MATCH_TAG, "matchtag"},
> +    {MATCH_LAYOUT, "matchlayout"},
>      {MATCH_IS_KEYBOARD, "matchiskeyboard"},
>      {MATCH_IS_POINTER, "matchispointer"},
>      {MATCH_IS_JOYSTICK, "matchisjoystick"},
> @@ -94,6 +95,7 @@ xf86parseInputClassSection(void)
>      list_init(&ptr->match_usbid);
>      list_init(&ptr->match_driver);
>      list_init(&ptr->match_tag);
> +    list_init(&ptr->match_layout);
>  
>      while ((token = xf86getToken(InputClassTab)) != ENDSECTION) {
>          switch (token) {
> @@ -169,6 +171,12 @@ xf86parseInputClassSection(void)
>              add_group_entry(&ptr->match_tag,
>                              xstrtokenize(val.str, TOKEN_SEP));
>              break;
> +        case MATCH_LAYOUT:
> +            if (xf86getSubToken(&(ptr->comment)) != STRING)
> +                Error(QUOTE_MSG, "MatchLayout");
> +            add_group_entry(&ptr->match_layout,
> +                            xstrtokenize(val.str, TOKEN_SEP));
> +            break;
>          case MATCH_IS_KEYBOARD:
>              if (xf86getSubToken(&(ptr->comment)) != STRING)
>                  Error(QUOTE_MSG, "MatchIsKeyboard");
> @@ -307,6 +315,13 @@ xf86printInputClassSection (FILE * cf, XF86ConfInputClassPtr ptr)
>                          *cur);
>              fprintf(cf, "\"\n");
>          }
> +        list_for_each_entry(group, &ptr->match_layout, entry) {
> +            fprintf(cf, "\tMatchLayout     \"");
> +            for (cur = group->values; *cur; cur++)
> +                fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP,
> +                        *cur);
> +            fprintf(cf, "\"\n");
> +        }
>  
>          if (ptr->is_keyboard.set)
>              fprintf(cf, "\tIsKeyboard      \"%s\"\n",
> @@ -392,6 +407,12 @@ xf86freeInputClassList (XF86ConfInputClassPtr ptr)
>                  free(*list);
>              free(group);
>          }
> +        list_for_each_entry_safe(group, next, &ptr->match_layout, entry) {
> +            list_del(&group->entry);
> +            for (list = group->values; *list; list++)
> +                free(*list);
> +            free(group);
> +        }
>  
>          TestFree(ptr->comment);
>          xf86optionListFree(ptr->option_lst);
> diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
> index 4f279f1..a8785c5 100644
> --- a/hw/xfree86/parser/xf86Parser.h
> +++ b/hw/xfree86/parser/xf86Parser.h
> @@ -358,6 +358,7 @@ typedef struct
>  	struct list match_usbid;
>  	struct list match_driver;
>  	struct list match_tag;
> +	struct list match_layout;
>  	xf86TriState is_keyboard;
>  	xf86TriState is_pointer;
>  	xf86TriState is_joystick;
> diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h
> index 468a2ff..abcafcf 100644
> --- a/hw/xfree86/parser/xf86tokens.h
> +++ b/hw/xfree86/parser/xf86tokens.h
> @@ -282,6 +282,7 @@ typedef enum {
>      MATCH_USBID,
>      MATCH_DRIVER,
>      MATCH_TAG,
> +    MATCH_LAYOUT,
>      MATCH_IS_KEYBOARD,
>      MATCH_IS_POINTER,
>      MATCH_IS_JOYSTICK,
> -- 
> 1.7.4.4


More information about the xorg-devel mailing list