[Xcb-commit] src

Peter Hutterer whot at kemper.freedesktop.org
Wed May 21 16:19:32 PDT 2008


 src/xcb.h    |   17 +++++++++++++++++
 src/xcb_in.c |   25 +++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit 6532c715c3805128b9976ab208f1426f691056a2
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Tue May 15 16:28:19 2007 +0930

    Add xcb_ge_event_t and handling for long events.
    
    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.

diff --git a/src/xcb.h b/src/xcb.h
index 5a1c01a..d24ef95 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -116,6 +116,23 @@ typedef struct {
 } 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.
  *
  * A generic error structure.
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 2997de4..27ccc99 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -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);


More information about the xcb-commit mailing list