[Xcb] [PATCH] Add support for X Generic Extension events

Daniel Martin consume.noise at gmail.com
Wed Jan 9 04:15:09 PST 2013


With these patches, we are able to mark an XGE event as such and
generate the correct header for it.

Additionally, in xtypes.py we inject a full_sequence field after the
32byte boundary. libxcb uses it for additional informations and would
overwrite event fields if we wouldn't have it.
The full_sequence field will be injected into every XGE event, even if
it is not necessary (event has no fields behind the 32byte boundary),
for consistency.

XGE events can be found in the X Input Extension v2++.

Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
 doc/xml-xcb.txt  |  8 +++++++-
 src/xcb.xsd      |  1 +
 xcbgen/xtypes.py | 48 +++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/doc/xml-xcb.txt b/doc/xml-xcb.txt
index 7057727..1ec9d5f 100644
--- a/doc/xml-xcb.txt
+++ b/doc/xml-xcb.txt
@@ -128,7 +128,8 @@ Top-Level Elements
   requests of the same type may be combined into a single request without
   affecting the semantics of the requests.
 
-<event name="identifier" number="integer" [no-sequence-number="true"]>
+<event name="identifier" number="integer"
+       [[no-sequence-number="true"] | [xge="true"]]>
   structure contents
 </event>
 
@@ -142,6 +143,11 @@ Top-Level Elements
   include a sequence number.  This is a special-case for the KeymapNotify
   event in the core protocol, and should not be used in any other event.
 
+  If the optional xge attribute is true, the event is an X Generic Event and
+  will be treated as such.
+
+  The no-sequence-number and xge attribute can not be combined.
+
 <error name="identifier" number="integer">
   structure contents
 </error>
diff --git a/src/xcb.xsd b/src/xcb.xsd
index cfa90c9..bea6bbd 100644
--- a/src/xcb.xsd
+++ b/src/xcb.xsd
@@ -324,6 +324,7 @@ authorization from the authors.
               </xsd:sequence>
               <xsd:attribute name="no-sequence-number" type="xsd:boolean"
                              use="optional" />
+              <xsd:attribute name="xge" type="xsd:boolean" use="optional" />
             </xsd:extension>
           </xsd:complexContent>
         </xsd:complexType>
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index f6d4634..7f96907 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -596,27 +596,65 @@ class Event(ComplexType):
         tmp = elt.get('no-sequence-number')
         self.has_seq = (tmp == None or tmp.lower() == 'false' or tmp == '0')
 
+        tmp = elt.get('xge')
+        self.is_ge_event = (tmp and (tmp.lower() == 'true' or tmp == '1'))
+
         self.doc = None
         for item in list(elt):
             if item.tag == 'doc':
                 self.doc = Doc(name, item)
-            
+
     def add_opcode(self, opcode, name, main):
         self.opcodes[name] = opcode
         if main:
             self.name = name
 
     def resolve(self, module):
+        def add_event_header():
+            self.fields.append(Field(tcard8, tcard8.name, 'response_type', False, True, True))
+            if self.has_seq:
+                self.fields.append(_placeholder_byte)
+                self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+
+        def add_ge_event_header():
+            self.fields.append(Field(tcard8,  tcard8.name,  'response_type', False, True, True))
+            self.fields.append(Field(tcard8,  tcard8.name,  'extension', False, True, True))
+            self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+            self.fields.append(Field(tcard32, tcard32.name, 'length', False, True, True))
+            self.fields.append(Field(tcard16, tcard16.name, 'evtype', False, True, True))
+
+        def add_full_seq_field():
+            size = 0
+            idx = 0
+            for m in self.fields:
+                if m.type.fixed_size():
+                    size = size + (m.type.size * m.type.nmemb)
+                else:
+                    raise Exception('variadic field before 32b boundary in event %s' % str(self.name))
+
+                if size == 32:
+                    idx = self.fields.index(m) + 1
+                    break
+
+            if idx:
+                self.fields.insert(idx, Field(tcard32, tcard32.name, 'full_sequence', False, True, True))
+            else:
+                raise Exception('could not find 32b boundary in event %s' % str(self.name))
+
         if self.resolved:
             return
 
         # Add the automatic protocol fields
-        self.fields.append(Field(tcard8, tcard8.name, 'response_type', False, True, True))
-        if self.has_seq:
-            self.fields.append(_placeholder_byte)
-            self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+        if self.is_ge_event:
+            add_ge_event_header()
+        else:
+            add_event_header()
+
         ComplexType.resolve(self, module)
 
+        if self.is_ge_event:
+            add_full_seq_field()
+
     out = __main__.output['event']
 
 
-- 
1.8.0.3



More information about the Xcb mailing list