[PATCH app/xev] parse state to describe in-use modifiers

walter harms wharms at bfs.de
Wed Aug 14 12:34:51 UTC 2019



Am 14.08.2019 04:36, schrieb Benjamin Elijah Griffin:
> Example for <ctrl-c>:
> 
> KeyPress event, serial 28, synthetic NO, window 0x2a00001,
>     root 0x176, subw 0x0, time 605237548, (-825,547), root:(303,559),
>     state 0x4, keycode 54 (keysym 0x63, c), same_screen YES,
>     modifier: control
>     XLookupString gives 1 bytes: (03) ""
>     XmbLookupString gives 1 bytes: (03) ""
>     XFilterEvent returns: False
> 
> Signed-off-by: Benjamin Elijah Griffin <freedesktop at eli.users.panix.com>
> ---
>  configure.ac |  2 +-
>  xev.c        | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 6adaa43..72d22b4 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -22,7 +22,7 @@ dnl Process this file with autoconf to create configure.
> 
>  # Initialize Autoconf
>  AC_PREREQ([2.60])
> -AC_INIT([xev], [1.2.3],
> +AC_INIT([xev], [1.2.4],
>          [https://gitlab.freedesktop.org/xorg/app/xev/issues], [xev])
>  AC_CONFIG_SRCDIR([Makefile.am])
>  AC_CONFIG_HEADERS([config.h])
> diff --git a/xev.c b/xev.c
> index 4c6115f..f5cc32b 100644
> --- a/xev.c
> +++ b/xev.c
> @@ -106,6 +106,43 @@ dump(char *str, int len)
>  }
> 
>  static void
> +show_Modifiers(int state)
> +{
> +    int i, smask, sflag = 1;
> +
> +    printf("    modifier: ");
> +    if (state & sflag)
> +        printf("shift ");
> +    sflag <<= 1;
> +    if (state & sflag)
> +        printf("lock ");
> +    sflag <<= 1;
> +    if (state & sflag)
> +        printf("control ");
> +    sflag <<= 1;
> +
> +    for (i = 3; i < 8; i++) {
> +       if (state & sflag)
> +            printf("mod%d ", i - 2);
> +        sflag <<= 1;
> +    }
> +
> +    /* Mouse buttons are also modifiers */
> +    for (i = 8; i < 13; i++) {
> +       if (state & sflag)
> +            printf("Button%d ", i - 7);
> +        sflag <<= 1;
> +    }
> +
> +    /* Any bits in state that we didn't already test? */
> +    smask = ~ (sflag - 1);
> +    if (state & smask)
> +        printf("other: 0x%x", (state & smask));
> +
> +    printf("\n");
> +}
> +
> +static void
>  do_KeyPress(XEvent *eventp)
>  {
>      XKeyEvent *e = (XKeyEvent *) eventp;
> @@ -151,6 +188,10 @@ do_KeyPress(XEvent *eventp)
>      printf("    state 0x%x, keycode %u (keysym 0x%lx, %s), same_screen %s,\n",
>             e->state, e->keycode, (unsigned long) ks, ksname,
>             e->same_screen ? Yes : No);
> +    if (e->state) {
> +        show_Modifiers(e->state);
> +    }
> +
>      if (kc_set && e->keycode != kc)
>          printf("    XKeysymToKeycode returns keycode: %u\n", kc);
>      if (nbytes < 0)
> @@ -198,6 +239,9 @@ do_ButtonPress(XEvent *eventp)
>             e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
>      printf("    state 0x%x, button %u, same_screen %s\n",
>             e->state, e->button, e->same_screen ? Yes : No);
> +    if (e->state) {
> +        show_Modifiers(e->state);
> +    }
>  }
> 

You can make you life more easy when you move the check into show_Modifiers()
perhaps this is a case for "none" ?

JM2C

re,
 wh


>  static void
> @@ -215,6 +259,9 @@ do_MotionNotify(XEvent *eventp)
>             e->root, e->subwindow, e->time, e->x, e->y, e->x_root, e->y_root);
>      printf("    state 0x%x, is_hint %u, same_screen %s\n",
>             e->state, e->is_hint, e->same_screen ? Yes : No);
> +    if (e->state) {
> +        show_Modifiers(e->state);
> +    }
>  }
> 
>  static void
> --
> 2.7.4
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel


More information about the xorg-devel mailing list