summaryrefslogtreecommitdiff
path: root/xev.c
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2012-06-25 15:36:23 -0700
committerPeter Hutterer <peter.hutterer@who-t.net>2012-06-26 09:51:29 +1000
commitd33b2c81bd931d581e5ce4b36f99ee60a76e740d (patch)
tree5fb50aafdf89172eb32833409e5fb5836aeb22b7 /xev.c
parent96b24e2c353bb4c9b7a0e2fff4f13d015fdb25b9 (diff)
Add a -event parameter to control the event mask
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@nvidia.com> Reviewed-by: Andy Ritger <aritger@nvidia.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'xev.c')
-rw-r--r--xev.c112
1 files changed, 94 insertions, 18 deletions
diff --git a/xev.c b/xev.c
index 9f9111a..b130b2f 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);
}
}