summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2015-08-03 09:11:08 +0100
committerFrediano Ziglio <fziglio@redhat.com>2015-08-03 09:11:08 +0100
commitc5a32df387fcfe4e84cea6c0f5cbfe99e48d7e65 (patch)
tree03f9d589d7c3b5ad1a261ca744f13c9dff8483a0
parentc4f5a94670c635b5831ad94bc2c2fc13bebfdc28 (diff)
Start removing useless code from xev
-rw-r--r--Makefile.am22
-rw-r--r--configure.ac24
-rw-r--r--xev.c438
3 files changed, 41 insertions, 443 deletions
diff --git a/Makefile.am b/Makefile.am
index a100a1d..d66a082 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,23 +19,11 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
-SUBDIRS = man
-bin_PROGRAMS = xev
+bin_PROGRAMS = spice-replay
-AM_CFLAGS = $(CWARNFLAGS) $(XEV_CFLAGS)
-xev_LDADD = $(XEV_LIBS)
+AM_CFLAGS = $(CWARNFLAGS) $(REPLAY_CFLAGS)
+spice_replay_LDADD = $(REPLAY_LIBS)
-xev_SOURCES = \
+spice_replay_SOURCES = \
+ spice-replay.c \
xev.c
-
-MAINTAINERCLEANFILES = ChangeLog INSTALL
-
-.PHONY: ChangeLog INSTALL
-
-INSTALL:
- $(INSTALL_CMD)
-
-ChangeLog:
- $(CHANGELOG_CMD)
-
-dist-hook: ChangeLog INSTALL
diff --git a/configure.ac b/configure.ac
index 25a4b28..b64ff96 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,8 +22,7 @@ dnl Process this file with autoconf to create configure.
# Initialize Autoconf
AC_PREREQ([2.60])
-AC_INIT([xev], [1.2.1],
- [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xev])
+AC_INIT([spice-replay], [0.1])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
AC_USE_SYSTEM_EXTENSIONS
@@ -39,9 +38,20 @@ XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XEV, [xrandr >= 1.2 x11 xproto >= 7.0.17])
+PKG_CHECK_MODULES(REPLAY, [x11 xext xi >= 1.2 xproto >= 7.0.17])
-AC_CONFIG_FILES([
- Makefile
- man/Makefile])
-AC_OUTPUT
+# XI2 support
+PKG_CHECK_MODULES(XI2, [xi >= 1.2.99.2] [inputproto >= 1.9.99.15],
+ HAVE_XI2="yes"; AC_DEFINE(HAVE_XI2, 1, [XI2 available]),
+ HAVE_XI2="no");
+AM_CONDITIONAL(HAVE_XI2, [ test "$HAVE_XI2" = "yes" ])
+AC_SUBST(HAVE_XI2)
+
+# XI2.1 support
+PKG_CHECK_MODULES(XI21, [xi >= 1.4.99.1] [inputproto >= 2.0.99.1],
+ AC_DEFINE(HAVE_XI21, 1, [XI2.1 available]));
+# XI2.2 support
+PKG_CHECK_MODULES(XI22, [xi >= 1.5.99.1] [inputproto >= 2.1.99.1],
+ AC_DEFINE(HAVE_XI22, 1, [XI2.2 available]));
+
+AC_OUTPUT([Makefile])
diff --git a/xev.c b/xev.c
index 066da3a..443a207 100644
--- a/xev.c
+++ b/xev.c
@@ -43,44 +43,21 @@ from the X Consortium.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
-#include <X11/extensions/Xrandr.h>
-#define INNER_WINDOW_WIDTH 50
-#define INNER_WINDOW_HEIGHT 50
-#define INNER_WINDOW_BORDER 4
-#define INNER_WINDOW_X 10
-#define INNER_WINDOW_Y 10
-#define OUTER_WINDOW_MIN_WIDTH (INNER_WINDOW_WIDTH + \
- 2 * (INNER_WINDOW_BORDER + INNER_WINDOW_X))
-#define OUTER_WINDOW_MIN_HEIGHT (INNER_WINDOW_HEIGHT + \
- 2 * (INNER_WINDOW_BORDER + INNER_WINDOW_Y))
-#define OUTER_WINDOW_DEF_WIDTH (OUTER_WINDOW_MIN_WIDTH + 100)
-#define OUTER_WINDOW_DEF_HEIGHT (OUTER_WINDOW_MIN_HEIGHT + 100)
-#define OUTER_WINDOW_DEF_X 100
-#define OUTER_WINDOW_DEF_Y 100
+static const char Yes[] = "YES";
+static const char No[] = "NO";
+static const char Unknown[] = "unknown";
-typedef unsigned long Pixel;
+static const char *ProgramName;
+static Display *dpy;
-const char *Yes = "YES";
-const char *No = "NO";
-const char *Unknown = "unknown";
+static XIC xic = NULL;
-const char *ProgramName;
-Display *dpy;
-int screen;
-
-XIC xic = NULL;
-
-Atom wm_delete_window;
-Atom wm_protocols;
-
-Bool have_rr;
-int rr_event_base, rr_error_base;
+static Atom wm_protocols;
enum EventMaskIndex {
EVENT_MASK_INDEX_CORE,
- EVENT_MASK_INDEX_RANDR,
NUM_EVENT_MASKS
};
@@ -89,7 +66,7 @@ static void usage (void) _X_NORETURN;
static void
prologue (XEvent *eventp, const char *event_name)
{
- XAnyEvent *e = (XAnyEvent *) eventp;
+ XAnyEvent *e = &eventp->xany;
printf ("\n%s event, serial %ld, synthetic %s, window 0x%lx,\n",
event_name, e->serial, e->send_event ? Yes : No, e->window);
@@ -609,11 +586,6 @@ do_ClientMessage (XEvent *eventp)
}
XFree (mname);
-
- if (e->format == 32
- && e->message_type == wm_protocols
- && (Atom) e->data.l[0] == wm_delete_window)
- exit (0);
}
static void
@@ -635,258 +607,15 @@ do_MappingNotify (XEvent *eventp)
XRefreshKeyboardMapping(e);
}
-static void
-print_SubPixelOrder (SubpixelOrder subpixel_order)
-{
- switch (subpixel_order) {
- case SubPixelUnknown: printf ("SubPixelUnknown"); return;
- case SubPixelHorizontalRGB: printf ("SubPixelHorizontalRGB"); return;
- case SubPixelHorizontalBGR: printf ("SubPixelHorizontalBGR"); return;
- case SubPixelVerticalRGB: printf ("SubPixelVerticalRGB"); return;
- case SubPixelVerticalBGR: printf ("SubPixelVerticalBGR"); return;
- case SubPixelNone: printf ("SubPixelNone"); return;
- default: printf ("%d", subpixel_order);
- }
-}
-
-static void
-print_Rotation (Rotation rotation)
-{
- if (rotation & RR_Rotate_0)
- printf ("RR_Rotate_0");
- else if (rotation & RR_Rotate_90)
- printf ("RR_Rotate_90");
- else if (rotation & RR_Rotate_180)
- printf ("RR_Rotate_180");
- else if (rotation & RR_Rotate_270)
- printf ("RR_Rotate_270");
- else {
- printf ("%d", rotation);
- return;
- }
- if (rotation & RR_Reflect_X)
- printf (", RR_Reflect_X");
- if (rotation & RR_Reflect_Y)
- printf (", RR_Reflect_Y");
-}
-
-static void
-print_Connection (Connection connection)
-{
- switch (connection) {
- case RR_Connected: printf ("RR_Connected"); return;
- case RR_Disconnected: printf ("RR_Disconnected"); return;
- case RR_UnknownConnection: printf ("RR_UnknownConnection"); return;
- default: printf ("%d", connection);
- }
-}
-
-static void
-do_RRScreenChangeNotify (XEvent *eventp)
-{
- XRRScreenChangeNotifyEvent *e = (XRRScreenChangeNotifyEvent *) eventp;
-
- XRRUpdateConfiguration (eventp);
- printf (" root 0x%lx, timestamp %lu, config_timestamp %lu\n",
- e->root, e->timestamp, e->config_timestamp);
- printf (" size_index %hu", e->size_index);
- printf (", subpixel_order ");
- print_SubPixelOrder (e->subpixel_order);
- printf ("\n rotation ");
- print_Rotation (e->rotation);
- printf("\n width %d, height %d, mwidth %d, mheight %d\n",
- e->width, e->height, e->mwidth, e->mheight);
-}
-
-static void
-do_RRNotify_OutputChange (XEvent *eventp, XRRScreenResources *screen_resources)
-{
- XRROutputChangeNotifyEvent *e = (XRROutputChangeNotifyEvent *) eventp;
- XRROutputInfo *output_info = NULL;
- XRRModeInfo *mode_info = NULL;
-
- if (screen_resources) {
- int i;
-
- output_info = XRRGetOutputInfo (dpy, screen_resources, e->output);
- for (i = 0; i < screen_resources->nmode; i++)
- if (screen_resources->modes[i].id == e->mode) {
- mode_info = &screen_resources->modes[i]; break;
- }
- }
- printf (" subtype XRROutputChangeNotifyEvent\n");
- if (output_info)
- printf (" output %s, ", output_info->name);
- else
- printf (" output %lu, ", e->output);
- if (e->crtc)
- printf("crtc %lu, ", e->crtc);
- else
- printf("crtc None, ");
- if (mode_info)
- printf ("mode %s (%dx%d)\n", mode_info->name, mode_info->width,
- mode_info->height);
- else if (e->mode)
- printf ("mode %lu\n", e->mode);
- else
- printf("mode None\n");
- printf (" rotation ");
- print_Rotation (e->rotation);
- printf ("\n connection ");
- print_Connection (e->connection);
- printf (", subpixel_order ");
- print_SubPixelOrder (e->subpixel_order);
- printf ("\n");
- XRRFreeOutputInfo (output_info);
-}
-
-static void
-do_RRNotify_CrtcChange (XEvent *eventp, XRRScreenResources *screen_resources)
-{
- XRRCrtcChangeNotifyEvent *e = (XRRCrtcChangeNotifyEvent *) eventp;
- XRRModeInfo *mode_info = NULL;
-
- if (screen_resources) {
- int i;
-
- for (i = 0; i < screen_resources->nmode; i++)
- if (screen_resources->modes[i].id == e->mode) {
- mode_info = &screen_resources->modes[i]; break;
- }
- }
- printf (" subtype XRRCrtcChangeNotifyEvent\n");
- if (e->crtc)
- printf(" crtc %lu, ", e->crtc);
- else
- printf(" crtc None, ");
- if (mode_info)
- printf ("mode %s, ", mode_info->name);
- else if (e->mode)
- printf ("mode %lu, ", e->mode);
- else
- printf("mode None, ");
- printf ("rotation ");
- print_Rotation (e->rotation);
- printf ("\n x %d, y %d, width %d, height %d\n",
- e->x, e->y, e->width, e->height);
-}
-
-static void
-do_RRNotify_OutputProperty (XEvent *eventp,
- XRRScreenResources *screen_resources)
-{
- XRROutputPropertyNotifyEvent *e = (XRROutputPropertyNotifyEvent *) eventp;
- XRROutputInfo *output_info = NULL;
- char *property = XGetAtomName (dpy, e->property);
-
- if (screen_resources)
- output_info = XRRGetOutputInfo (dpy, screen_resources, e->output);
- printf (" subtype XRROutputPropertyChangeNotifyEvent\n");
- if (output_info)
- printf (" output %s, ", output_info->name);
- else
- printf (" output %lu, ", e->output);
- printf ("property %s, timestamp %lu, state ",
- property, e->timestamp);
- if (e->state == PropertyNewValue)
- printf ("NewValue\n");
- else if (e->state == PropertyDelete)
- printf ("Delete\n");
- else
- printf ("%d\n", e->state);
- XRRFreeOutputInfo (output_info);
- XFree (property);
-}
-
-static void
-do_RRNotify (XEvent *eventp)
-{
- XRRNotifyEvent *e = (XRRNotifyEvent *) eventp;
- XRRScreenResources *screen_resources;
-
- XRRUpdateConfiguration (eventp);
- screen_resources = XRRGetScreenResources (dpy, e->window);
- prologue (eventp, "RRNotify");
- switch (e->subtype) {
- case RRNotify_OutputChange:
- do_RRNotify_OutputChange (eventp, screen_resources); break;
- case RRNotify_CrtcChange:
- do_RRNotify_CrtcChange (eventp, screen_resources); break;
- case RRNotify_OutputProperty:
- do_RRNotify_OutputProperty (eventp, screen_resources); break;
- default:
- printf (" subtype %d\n", e->subtype);
- }
- XRRFreeScreenResources (screen_resources);
-}
-
static void
-set_sizehints (XSizeHints *hintp, int min_width, int min_height,
- int defwidth, int defheight, int defx, int defy,
- char *geom)
-{
- int geom_result;
-
- /* set the size hints, algorithm from xlib xbiff */
-
- hintp->width = hintp->min_width = min_width;
- hintp->height = hintp->min_height = min_height;
- hintp->flags = PMinSize;
- hintp->x = hintp->y = 0;
- geom_result = NoValue;
- if (geom != NULL) {
- geom_result = XParseGeometry (geom, &hintp->x, &hintp->y,
- (unsigned int *)&hintp->width,
- (unsigned int *)&hintp->height);
- if ((geom_result & WidthValue) && (geom_result & HeightValue)) {
-#ifndef max
-#define max(a,b) ((a) > (b) ? (a) : (b))
-#endif
- hintp->width = max (hintp->width, hintp->min_width);
- hintp->height = max (hintp->height, hintp->min_height);
- hintp->flags |= USSize;
- }
- if ((geom_result & XValue) && (geom_result & YValue)) {
- hintp->flags += USPosition;
- }
- }
- if (!(hintp->flags & USSize)) {
- hintp->width = defwidth;
- hintp->height = defheight;
- hintp->flags |= PSize;
- }
-/*
- if (!(hintp->flags & USPosition)) {
- hintp->x = defx;
- hintp->y = defy;
- hintp->flags |= PPosition;
- }
- */
- if (geom_result & XNegative) {
- hintp->x = DisplayWidth (dpy, DefaultScreen (dpy)) + hintp->x -
- hintp->width;
- }
- if (geom_result & YNegative) {
- hintp->y = DisplayHeight (dpy, DefaultScreen (dpy)) + hintp->y -
- hintp->height;
- }
-}
-
-static void
usage (void)
{
static const char *msg[] = {
" -display displayname X server to contact",
-" -geometry geom size and location of window",
-" -bw pixels border width in pixels",
-" -bs {NotUseful,WhenMapped,Always} backingstore attribute",
" -id windowid use existing window",
" -root use root window",
-" -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",
@@ -906,70 +635,43 @@ NULL};
exit (1);
}
-static int
-parse_backing_store (char *s)
-{
- size_t len = strlen (s);
-
- if (strncasecmp (s, "NotUseful", len) == 0) return (NotUseful);
- if (strncasecmp (s, "WhenMapped", len) == 0) return (WhenMapped);
- if (strncasecmp (s, "Always", len) == 0) return (Always);
-
- 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 }
+ { NULL, 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;
+ event_masks[EVENT_MASK_INDEX_CORE] |= events[i].mask;
if (s)
return True;
}
@@ -982,19 +684,12 @@ int
main (int argc, char **argv)
{
char *displayname = NULL;
- char *geom = NULL;
int i;
- XSizeHints hints;
- int borderwidth = 2;
- Window w, subw;
- XSetWindowAttributes attr;
+ Window w;
+ long event_mask;
XWindowAttributes wattr;
- unsigned long mask = 0L;
int done;
- const char *name = "Event Tester";
- Bool reverse = False;
Bool use_root = False;
- unsigned long back, fore;
XIM xim;
XIMStyles *xim_styles;
XIMStyle xim_style = 0;
@@ -1022,24 +717,6 @@ main (int argc, char **argv)
if (++i >= argc) usage ();
displayname = argv[i];
continue;
- case 'g': /* -geometry geom */
- if (++i >= argc) usage ();
- geom = argv[i];
- continue;
- case 'b':
- switch (arg[2]) {
- case 'w': /* -bw pixels */
- if (++i >= argc) usage ();
- borderwidth = atoi (argv[i]);
- continue;
- case 's': /* -bs type */
- if (++i >= argc) usage ();
- attr.backing_store = parse_backing_store (argv[i]);
- mask |= CWBackingStore;
- continue;
- default:
- usage ();
- }
case 'i': /* -id */
if (++i >= argc) usage ();
sscanf(argv[i], "0x%lx", &w);
@@ -1048,26 +725,15 @@ main (int argc, char **argv)
if (!w)
usage ();
continue;
- case 'n': /* -name */
- if (++i >= argc) usage ();
- name = argv[i];
- continue;
case 'r':
switch (arg[2]) {
case 'o': /* -root */
use_root = True;
continue;
- case 'v': /* -rv */
- reverse = True;
- continue;
default:
usage ();
}
continue;
- case 's': /* -s */
- attr.save_under = True;
- mask |= CWSaveUnder;
- continue;
case 'e': /* -event */
if (++i >= argc) usage ();
if (!parse_event_mask (argv[i], event_masks))
@@ -1127,59 +793,21 @@ main (int argc, char **argv)
}
}
- screen = DefaultScreen (dpy);
-
- attr.event_mask = event_masks[EVENT_MASK_INDEX_CORE];
+ event_mask = event_masks[EVENT_MASK_INDEX_CORE];
if (use_root)
- w = RootWindow(dpy, screen);
+ w = DefaultRootWindow(dpy);
if (w) {
XGetWindowAttributes(dpy, w, &wattr);
if (wattr.all_event_masks & ButtonPressMask)
- attr.event_mask &= ~ButtonPressMask;
- attr.event_mask &= ~SubstructureRedirectMask;
- XSelectInput(dpy, w, attr.event_mask);
- } else {
- set_sizehints (&hints, OUTER_WINDOW_MIN_WIDTH, OUTER_WINDOW_MIN_HEIGHT,
- OUTER_WINDOW_DEF_WIDTH, OUTER_WINDOW_DEF_HEIGHT,
- OUTER_WINDOW_DEF_X, OUTER_WINDOW_DEF_Y, geom);
-
- if (reverse) {
- back = BlackPixel(dpy,screen);
- fore = WhitePixel(dpy,screen);
- } else {
- back = WhitePixel(dpy,screen);
- fore = BlackPixel(dpy,screen);
- }
-
- attr.background_pixel = back;
- attr.border_pixel = fore;
- mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
-
- w = XCreateWindow (dpy, RootWindow (dpy, screen), hints.x, hints.y,
- hints.width, hints.height, borderwidth, 0,
- InputOutput, (Visual *)CopyFromParent,
- mask, &attr);
-
- XSetStandardProperties (dpy, w, name, NULL, (Pixmap) 0,
- argv, argc, &hints);
-
- subw = XCreateSimpleWindow (dpy, w, INNER_WINDOW_X, INNER_WINDOW_Y,
- INNER_WINDOW_WIDTH, INNER_WINDOW_HEIGHT,
- INNER_WINDOW_BORDER,
- attr.border_pixel, attr.background_pixel);
-
- wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
- wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
- XSetWMProtocols(dpy, w, &wm_delete_window, 1);
-
- XMapWindow (dpy, subw); /* map before w so that it appears */
- XMapWindow (dpy, w);
-
- printf ("Outer window is 0x%lx, inner window is 0x%lx\n", w, subw);
+ event_mask &= ~ButtonPressMask;
+ event_mask &= ~SubstructureRedirectMask;
+ XSelectInput(dpy, w, event_mask);
}
+ wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False);
+
if (xim && xim_style) {
xic = XCreateIC (xim,
XNInputStyle, xim_style,
@@ -1192,23 +820,6 @@ main (int argc, char **argv)
}
}
- have_rr = XRRQueryExtension (dpy, &rr_event_base, &rr_error_base);
- if (have_rr) {
- int rr_major, rr_minor;
-
- if (XRRQueryVersion (dpy, &rr_major, &rr_minor)) {
- int rr_mask = event_masks[EVENT_MASK_INDEX_RANDR];
-
- if (rr_major == 1 && rr_minor <= 1) {
- rr_mask &= ~(RRCrtcChangeNotifyMask |
- RROutputChangeNotifyMask |
- RROutputPropertyNotifyMask);
- }
-
- XRRSelectInput (dpy, w, rr_mask);
- }
- }
-
for (done = 0; !done; ) {
XEvent event;
@@ -1348,17 +959,6 @@ main (int argc, char **argv)
do_MappingNotify (&event);
break;
default:
- if (have_rr) {
- if (event.type == rr_event_base + RRScreenChangeNotify) {
- prologue (&event, "RRScreenChangeNotify");
- do_RRScreenChangeNotify (&event);
- break;
- }
- if (event.type == rr_event_base + RRNotify) {
- do_RRNotify (&event);
- break;
- }
- }
printf ("Unknown event type %d\n", event.type);
break;
}