On 06/24/2012 06:21 PM, Peter Hutterer wrote:
On Fri, Jun 22, 2012 at 01:45:47PM -0700, Aaron Plattner wrote:
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.

great addition, thanks. one suggestion though: please make this a
comma-separate list so one can select for a few masks instead of just a
single one.

You can specify -event multiple times, is that sufficient if I make it more obvious in the man page and help text?

-- Aaron

Cheers,
   Peter

Signed-off-by: Aaron Plattner <aplatt...@nvidia.com>
Reviewed-by: Andy Ritger <arit...@nvidia.com>
---
  man/xev.man |    6 ++++
  xev.c       |  109 +++++++++++++++++++++++++++++++++++++++++++++++++----------
  2 files changed, 97 insertions(+), 18 deletions(-)

diff --git a/man/xev.man b/man/xev.man
index d13f022..eb3a901 100644
--- a/man/xev.man
+++ b/man/xev.man
@@ -52,6 +52,12 @@ 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.
+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..6242bd4 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,10 @@ 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",
  "",
  NULL};
      const char **cpp;
@@ -909,6 +919,65 @@ parse_backing_store (char *s)
      usage ();
  }

+static Bool
+parse_event_mask (const char *s, long event_masks[], Bool all)
+{
+    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 (all || !strcmp(s, events[i].name)) {
+            event_masks[events[i].mask_index] |= events[i].mask;
+            if (!all) return True;

I'd prefer a line break here

+        }
+    }
+
+    return False;
+}
+
  int
  main (int argc, char **argv)
  {
@@ -931,6 +1000,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 +1010,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 +1068,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, False))
+                   usage ();
+               event_mask_specified = True;
+               continue;
              default:
                usage ();
            }                           /* end switch on - */
@@ -1002,6 +1081,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, True);
+
      dpy = XOpenDisplay (displayname);
      if (!dpy) {
        fprintf (stderr, "%s:  unable to open display '%s'\n",
@@ -1046,19 +1129,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 +1197,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);
          }
      }
--
1.7.9.5
_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to