[Xcb] [PATCH:xwininfo] Remove dependency on xcb-event.c

Alan Coopersmith alan.coopersmith at oracle.com
Fri Jun 25 21:46:33 PDT 2010


(to be squashed into xcb port commit)

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 configure.ac |    2 +-
 dsimple.c    |  133 ++++++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 93 insertions(+), 42 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6da2984..3337c6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,7 +41,7 @@ XORG_DEFAULT_OPTIONS
 AC_CHECK_FUNCS([strlcat])
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(XWININFO, [xcb >= 1.6] xcb-event xcb-icccm xcb-shape)
+PKG_CHECK_MODULES(XWININFO, [xcb >= 1.6] xcb-icccm xcb-shape)
 # Even when using xcb, xproto is still required for Xfuncproto.h
 # and libX11 headers for cursorfont.h
 PKG_CHECK_MODULES(XLIB, x11 [xproto >= 7.0.17])
diff --git a/dsimple.c b/dsimple.c
index b7c6048..95757bd 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -50,7 +50,6 @@ from The Open Group.
 
 #include <xcb/xcb.h>
 #include <xcb/xproto.h>
-#include <xcb/xcb_event.h>
 #include <xcb/xcb_icccm.h>
 #include <X11/cursorfont.h>
 #include <stdio.h>
@@ -184,7 +183,7 @@ xcb_window_t Select_Window(xcb_connection_t *dpy,
 	xcb_allow_events (dpy, XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME);
 	xcb_flush (dpy);
 	event = xcb_wait_for_event (dpy);
-	switch (XCB_EVENT_RESPONSE_TYPE(event)) {
+	switch (event->response_type & 0x7f) {
 	case XCB_BUTTON_PRESS:
 	{
 	    xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event;
@@ -349,62 +348,114 @@ Print_X_Error (
     xcb_generic_error_t *err
     )
 {
-    const char *label;
-    char buffer[256];
+    char buffer[256] = "";
 
     if ((err == NULL) || (err->response_type != 0)) /* not an error */
 	return;
 
-    label = xcb_event_get_error_label (err->error_code);
-    if (!label)
-    {
-	snprintf (buffer, sizeof(buffer), "Error code %d", err->error_code);
-	label = buffer;
-    }
-    fprintf (stderr, "X Error:  %s\n", label);
-
-    if (err->major_code < 128)
-	label = xcb_event_get_request_label (err->major_code);
-    else
-    {
-	// XXX: find extension name
-	label = NULL;
-    }
-    fprintf (stderr, "  Request Major code: %d (%s)\n", err->major_code,
-	     label ? label : "unknown");
-
-    if (err->major_code >= 128)
-    {
-	fprintf (stderr, "  Request Minor code: %d\n", err->minor_code);
-    }
-
+    /* Todo: find a more user friendly way to show request/extension info */
     if (err->error_code >= 128)
     {
-	// XXX: find extension that defined this error
+	fprintf (stderr, "X Extension Error:  Error code %d\n",
+		 err->error_code);
     }
     else
     {
 	switch (err->error_code)
 	{
-	    case XCB_EVENT_ERROR_BAD_VALUE:
-		fprintf(stderr, "   Value: 0x%x\n", err->resource_id);
+	    case XCB_REQUEST:
+		snprintf (buffer, sizeof(buffer), ": Bad Request");
+		break;
+
+	    case XCB_VALUE:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Value: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_WINDOW:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Window: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_PIXMAP:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Pixmap: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_ATOM:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Atom: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_CURSOR:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Cursor: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_FONT:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Font: 0x%x", err->resource_id);
 		break;
 
-	    case XCB_EVENT_ERROR_BAD_ATOM:
-		fprintf(stderr, "   AtomID: 0x%x\n", err->resource_id);
+	    case XCB_MATCH:
+		snprintf (buffer, sizeof(buffer), ": Bad Match");
 		break;
 
-	    case XCB_EVENT_ERROR_BAD_WINDOW:
-	    case XCB_EVENT_ERROR_BAD_PIXMAP:
-	    case XCB_EVENT_ERROR_BAD_CURSOR:
-	    case XCB_EVENT_ERROR_BAD_FONT:
-	    case XCB_EVENT_ERROR_BAD_DRAWABLE:
-	    case XCB_EVENT_ERROR_BAD_COLOR:
-	    case XCB_EVENT_ERROR_BAD_GC:
-	    case XCB_EVENT_ERROR_BAD_ID_CHOICE:
-		fprintf(stderr, "   ResourceID: 0x%x\n", err->resource_id);
+	    case XCB_DRAWABLE:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Drawable: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_ACCESS:
+		snprintf (buffer, sizeof(buffer), ": Access Denied");
+		break;
+
+	    case XCB_ALLOC:
+		snprintf (buffer, sizeof(buffer),
+			  ": Server Memory Allocation Failure");
+		break;
+
+	    case XCB_COLORMAP:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Color: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_G_CONTEXT:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad GC: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_ID_CHOICE:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad XID: 0x%x", err->resource_id);
+		break;
+
+	    case XCB_NAME:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Name");
+		break;
+
+	    case XCB_LENGTH:
+		snprintf (buffer, sizeof(buffer),
+			  ": Bad Request Length");
+		break;
+
+	    case XCB_IMPLEMENTATION:
+		snprintf (buffer, sizeof(buffer),
+			  ": Server Implementation Failure");
+		break;
+
+	    default:
+		snprintf (buffer, sizeof(buffer), ": Unknown error");
 		break;
 	}
+	fprintf (stderr, "X Error: %d%s\n", err->error_code, buffer);
+    }
+
+    fprintf (stderr, "  Request Major code: %d\n", err->major_code);
+    if (err->major_code >= 128)
+    {
+	fprintf (stderr, "  Request Minor code: %d\n", err->minor_code);
     }
 
     fprintf (stderr, "  Request serial number: %d\n", err->full_sequence);
-- 
1.5.6.5



More information about the Xcb mailing list