[PATCH xev v3] Add a -event parameter to control the event mask

Aaron Plattner aplattner at nvidia.com
Mon Jun 25 17:01:20 PDT 2012


On 06/25/2012 04:52 PM, Peter Hutterer wrote:
> From: Aaron Plattner <aplattner at nvidia.com>
>
> It's annoying to have to sift through a lot of unrelated events if all you care
> about is one specific class of events (e.g. RandR events).  Add a -event
> parameter that can be used to tune which events to select.  When not specified,
> all events are selected.
>
> Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
> Reviewed-by: Andy Ritger <aritger at nvidia.com>
> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> Changes to v2:
> - "all" parameter wasn't necessary, we can just assume all events on a NULL
> string

That's a little magic behavior-y for my tastes, but sure.  Do you want to push 
the change, or should I?

Sorry I didn't notice the missing line break you requested.

-- Aaron

>   man/xev.man |    9 +++++
>   xev.c       |  112 +++++++++++++++++++++++++++++++++++++++++++++++++----------
>   2 files changed, 103 insertions(+), 18 deletions(-)
>
> diff --git a/man/xev.man b/man/xev.man
> index d13f022..ca38d56 100644
> --- a/man/xev.man
> +++ b/man/xev.man
> @@ -52,6 +52,15 @@ This option specifies the name to assign to the created window.
>   .TP 8
>   .B \-rv
>   This option specifies that the window should be in reverse video.
> +.TP 8
> +.B \-event \fIevent_mask\fP
> +Select which events to display.
> +The
> +.B \-event
> +option can be specified multiple times to select multiple types of events.
> +When not specified, all events are selected.
> +Available event masks: keyboard mouse expose visibility structure substructure
> +focus property colormap owner_grab_button randr
>   .SH "SEE ALSO"
>   X(__miscmansuffix__), xwininfo(__appmansuffix__), xdpyinfo(__appmansuffix__), Xlib Programmers Manual, X Protocol
>   Specification
> diff --git a/xev.c b/xev.c
> index 9f9111a..e6ad831 100644
> --- a/xev.c
> +++ b/xev.c
> @@ -75,6 +75,12 @@ Atom wm_protocols;
>   Bool have_rr;
>   int rr_event_base, rr_error_base;
>
> +enum EventMaskIndex {
> +    EVENT_MASK_INDEX_CORE,
> +    EVENT_MASK_INDEX_RANDR,
> +    NUM_EVENT_MASKS
> +};
> +
>   static void usage (void) _X_NORETURN;
>
>   static void
> @@ -878,6 +884,12 @@ usage (void)
>   "    -s                                  set save-unders attribute",
>   "    -name string                        window name",
>   "    -rv                                 reverse video",
> +"    -event event_mask                   select 'event_mask' events",
> +"           Supported event masks: keyboard mouse expose visibility structure",
> +"                                  substructure focus property colormap",
> +"                                  owner_grab_button randr",
> +"           This option can be specified multiple times to select multiple",
> +"           event masks.",
>   "",
>   NULL};
>       const char **cpp;
> @@ -909,6 +921,66 @@ parse_backing_store (char *s)
>       usage ();
>   }
>
> +static Bool
> +parse_event_mask (const char *s, long event_masks[])
> +{
> +    const struct {
> +        const char *name;
> +        enum EventMaskIndex mask_index;
> +        long mask;
> +    } events[] = {
> +        { "keyboard",
> +          EVENT_MASK_INDEX_CORE,
> +          KeyPressMask | KeyReleaseMask | KeymapStateMask },
> +        { "mouse",
> +          EVENT_MASK_INDEX_CORE,
> +          ButtonPressMask | ButtonReleaseMask | EnterWindowMask |
> +          LeaveWindowMask | PointerMotionMask | Button1MotionMask |
> +          Button2MotionMask | Button3MotionMask | Button4MotionMask |
> +          Button5MotionMask | ButtonMotionMask },
> +        { "expose",
> +          EVENT_MASK_INDEX_CORE,
> +          ExposureMask },
> +        { "visibility",
> +          EVENT_MASK_INDEX_CORE,
> +          VisibilityChangeMask },
> +        { "structure",
> +          EVENT_MASK_INDEX_CORE,
> +          StructureNotifyMask },
> +        { "substructure",
> +          EVENT_MASK_INDEX_CORE,
> +          SubstructureNotifyMask | SubstructureRedirectMask },
> +        { "focus",
> +          EVENT_MASK_INDEX_CORE,
> +          FocusChangeMask },
> +        { "property",
> +          EVENT_MASK_INDEX_CORE,
> +          PropertyChangeMask },
> +        { "colormap",
> +          EVENT_MASK_INDEX_CORE,
> +          ColormapChangeMask },
> +        { "owner_grab_button",
> +          EVENT_MASK_INDEX_CORE,
> +          OwnerGrabButtonMask },
> +        { "randr",
> +          EVENT_MASK_INDEX_RANDR,
> +          RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask |
> +          RROutputChangeNotifyMask | RROutputPropertyNotifyMask },
> +        { NULL, 0, 0 }
> +    };
> +    int i;
> +
> +    for (i = 0; events[i].name; i++) {
> +        if (!s || !strcmp(s, events[i].name)) {
> +            event_masks[events[i].mask_index] |= events[i].mask;
> +            if (s)
> +                return True;
> +        }
> +    }
> +
> +    return False;
> +}
> +
>   int
>   main (int argc, char **argv)
>   {
> @@ -931,6 +1003,8 @@ main (int argc, char **argv)
>       XIMStyle xim_style = 0;
>       char *modifiers;
>       char *imvalret;
> +    long event_masks[NUM_EVENT_MASKS];
> +    Bool event_mask_specified = False;
>
>       ProgramName = argv[0];
>
> @@ -939,6 +1013,8 @@ main (int argc, char **argv)
>   		ProgramName);
>       }
>
> +    memset(event_masks, 0, sizeof(event_masks));
> +
>       w = 0;
>       for (i = 1; i < argc; i++) {
>   	char *arg = argv[i];
> @@ -995,6 +1071,12 @@ main (int argc, char **argv)
>   		attr.save_under = True;
>   		mask |= CWSaveUnder;
>   		continue;
> +	      case 'e':			/* -event */
> +		if (++i >= argc) usage ();
> +		if (!parse_event_mask (argv[i], event_masks))
> +		    usage ();
> +		event_mask_specified = True;
> +		continue;
>   	      default:
>   		usage ();
>   	    }				/* end switch on - */
> @@ -1002,6 +1084,10 @@ main (int argc, char **argv)
>   	  usage ();
>       }					/* end for over argc */
>
> +    /* if no -event options were specified, pretend all of them were */
> +    if (!event_mask_specified)
> +        parse_event_mask (NULL, event_masks);
> +
>       dpy = XOpenDisplay (displayname);
>       if (!dpy) {
>   	fprintf (stderr, "%s:  unable to open display '%s'\n",
> @@ -1046,19 +1132,7 @@ main (int argc, char **argv)
>
>       screen = DefaultScreen (dpy);
>
> -    /* select for all events */
> -    attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
> -			   ButtonReleaseMask | EnterWindowMask |
> -			   LeaveWindowMask | PointerMotionMask |
> -			   Button1MotionMask |
> -			   Button2MotionMask | Button3MotionMask |
> -			   Button4MotionMask | Button5MotionMask |
> -			   ButtonMotionMask | KeymapStateMask |
> -			   ExposureMask | VisibilityChangeMask |
> -			   StructureNotifyMask | /* ResizeRedirectMask | */
> -			   SubstructureNotifyMask | SubstructureRedirectMask |
> -			   FocusChangeMask | PropertyChangeMask |
> -			   ColormapChangeMask | OwnerGrabButtonMask;
> +    attr.event_mask = event_masks[EVENT_MASK_INDEX_CORE];
>
>       if (use_root)
>   	w = RootWindow(dpy, screen);
> @@ -1126,12 +1200,14 @@ main (int argc, char **argv)
>           int rr_major, rr_minor;
>
>           if (XRRQueryVersion (dpy, &rr_major, &rr_minor)) {
> -            int rr_mask = RRScreenChangeNotifyMask;
> +            int rr_mask = event_masks[EVENT_MASK_INDEX_RANDR];
> +
> +            if (rr_major == 1 && rr_minor <= 1) {
> +                rr_mask &= ~(RRCrtcChangeNotifyMask |
> +                             RROutputChangeNotifyMask |
> +                             RROutputPropertyNotifyMask);
> +            }
>
> -            if (rr_major > 1
> -                || (rr_major == 1 && rr_minor >= 2))
> -                rr_mask |= RRCrtcChangeNotifyMask | RROutputChangeNotifyMask |
> -                           RROutputPropertyNotifyMask;
>               XRRSelectInput (dpy, w, rr_mask);
>           }
>       }
>




More information about the xorg-devel mailing list