From d33b2c81bd931d581e5ce4b36f99ee60a76e740d Mon Sep 17 00:00:00 2001 From: Aaron Plattner Date: Mon, 25 Jun 2012 15:36:23 -0700 Subject: 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 Reviewed-by: Andy Ritger Signed-off-by: Peter Hutterer --- xev.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 18 deletions(-) (limited to 'xev.c') 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); } } -- cgit v1.2.3