Add xcb_ge_event_t and handling for long events.
authorPeter Hutterer <peter@cs.unisa.edu.au>
Tue, 15 May 2007 06:58:19 +0000 (16:28 +0930)
committerPeter Hutterer <peter@cs.unisa.edu.au>
Wed, 21 May 2008 11:52:13 +0000 (21:22 +0930)
GenericEvent can be more than 32 bytes long. Ensure that the required data is
pulled off the wire and tack it onto the event.

Due to the structure of the xcb_generic_event_t, the data is appended AFTER
the full_sequence field.

src/xcb.h
src/xcb_in.c

index 5a1c01a..d24ef95 100644 (file)
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -115,6 +115,23 @@ typedef struct {
     uint32_t full_sequence;  /**< full sequence */
 } xcb_generic_event_t;
 
+/**
+ * @brief GE event
+ *
+ * An event as sent by the XGE extension. The length field specifies the
+ * number of 4-byte blocks trailing the struct.
+ */
+typedef struct {
+    uint8_t  response_type;  /**< Type of the response */
+    uint8_t  pad0;           /**< Padding */
+    uint16_t sequence;       /**< Sequence number */
+    uint32_t length;
+    uint16_t event_type;
+    uint16_t pad1;
+    uint32_t pad[5];         /**< Padding */
+    uint32_t full_sequence;  /**< full sequence */
+} xcb_ge_event_t;
+
 /**
  * @brief Generic error.
  *
index 2997de4..27ccc99 100644 (file)
@@ -39,6 +39,7 @@
 
 #define XCB_ERROR 0
 #define XCB_REPLY 1
+#define XCB_XGE_EVENT 35
 
 struct event_list {
     xcb_generic_event_t *event;
@@ -76,7 +77,8 @@ static void wake_up_next_reader(xcb_connection_t *c)
 static int read_packet(xcb_connection_t *c)
 {
     xcb_generic_reply_t genrep;
-    int length = 32;
+    int length = 32,
+        eventlength = 0; /* length after first 32 bytes for GenericEvents */
     void *buf;
     pending_reply *pend = 0;
     struct event_list *event;
@@ -141,17 +143,36 @@ static int read_packet(xcb_connection_t *c)
         length += genrep.length * 4;
     }
 
-    buf = malloc(length + (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)));
+    /* XGE events may have sizes > 32 */
+    if (genrep.response_type == XCB_XGE_EVENT)
+    {
+        eventlength = ((xcb_ge_event_t*)&genrep)->length * 4;
+    }
+
+    buf = malloc(length + eventlength +
+            (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)));
     if(!buf)
     {
         _xcb_conn_shutdown(c);
         return 0;
     }
+
     if(_xcb_in_read_block(c, buf, length) <= 0)
     {
         free(buf);
         return 0;
     }
+
+    /* pull in XGE event data if available, append after event struct */
+    if (eventlength)
+    {
+        if(_xcb_in_read_block(c, &((xcb_generic_event_t*)buf)[1], eventlength) <= 0)
+        {
+            free(buf);
+            return 0;
+        }
+    }
+
     if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY))
     {
         free(buf);