[Xcb] [PATCH libxcb 1/1] add support for eventstruct
Christian Linhart
chris at demorecorder.com
Wed Jan 25 10:20:38 UTC 2017
eventstruct allows to use events as part of requests.
This is, e.g., needed by xcb_input_send_extension_event.
Signed-off-by: Christian Linhart <chris at demorecorder.com>
---
src/c_client.py | 32 +++++++++++++++++++++++++++++++-
src/xcb.h | 12 ++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/c_client.py b/src/c_client.py
index b0eb47c..0cbdf30 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -433,15 +433,19 @@ def _c_type_setup(self, name, postfix):
self.c_container = 'union' if self.is_union else 'struct'
prev_varsized_field = None
prev_varsized_offset = 0
first_field_after_varsized = None
for field in self.fields:
- field.c_field_type = _t(field.field_type)
+ if field.type.is_event:
+ field.c_field_type = _t(field.field_type + ('event',))
+ else:
+ field.c_field_type = _t(field.field_type)
+
field.c_field_const_type = ('' if field.type.nmemb == 1 else 'const ') + field.c_field_type
field.c_field_name = _cpp(field.field_name)
field.c_subscript = '[%d]' % field.type.nmemb if (field.type.nmemb and field.type.nmemb > 1) else ''
field.c_pointer = ' ' if field.type.nmemb == 1 else '*'
# correct the c_pointer field for variable size non-list types
if not field.type.fixed_size() and field.c_pointer == ' ':
@@ -3152,14 +3156,36 @@ def c_request(self, name):
_c_accessors_list(self, field)
elif _c_field_needs_field_accessor(field):
_c_accessors_field(self, field)
# We generate the manpage afterwards because _c_type_setup has been called.
# TODO: what about aux helpers?
_man_request(self, name, void=not self.reply, aux=False)
+
+def c_eventstruct(self, name):
+ #add fields that are needed to get the event-type in a generic way
+ self.fields.append( Field( tevent, tevent.name, 'event_header', False, True, True) )
+
+ if self.contains_ge_events:
+ #TODO: add header of ge-events as an extra field
+ raise Exception( 'eventstructs with ge-events are not yet supported' )
+
+ _c_type_setup(self, name, ())
+
+ #correct the format of the field names
+ for field in self.fields:
+ field.c_field_name = _n_item(field.c_field_name).lower()
+
+ _c_complex(self)
+ _c_iterator(self, name)
+
+ if not self.fixed_size():
+ #TODO: Create sizeof function (and maybe other accessors) for var-sized eventstructs
+ raise Exception( 'var sized eventstructs are not yet supported' )
+
def c_event(self, name):
'''
Exported function that handles event declarations.
'''
# The generic event structure xcb_ge_event_t has the full_sequence field
# at the 32byte boundary. That's why we've to inject this field into GE
@@ -3249,14 +3275,15 @@ def c_error(self, name):
output = {'open' : c_open,
'close' : c_close,
'simple' : c_simple,
'enum' : c_enum,
'struct' : c_struct,
'union' : c_union,
'request' : c_request,
+ 'eventstruct' : c_eventstruct,
'event' : c_event,
'error' : c_error,
}
# Boilerplate below this point
# Check for the argument that specifies path to the xcbgen python package.
@@ -3292,14 +3319,17 @@ Failed to load the xcbgen Python package!
Make sure that xcb/proto installed it on your Python path.
If not, you will need to create a .pth file or define $PYTHONPATH
to extend the path.
Refer to the README file in xcb/proto for more info.
''')
raise
+# predefined datatype globals.
+tevent = SimpleType(('xcb_raw_generic_event_t',), 32)
+
# Ensure the man subdirectory exists
try:
os.mkdir('man')
except OSError as e:
if e.errno != errno.EEXIST:
raise
diff --git a/src/xcb.h b/src/xcb.h
index 6873e79..cbc0f2b 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -139,14 +139,26 @@ typedef struct {
uint8_t pad0; /**< Padding */
uint16_t sequence; /**< Sequence number */
uint32_t pad[7]; /**< Padding */
uint32_t full_sequence; /**< full sequence */
} xcb_generic_event_t;
/**
+ * @brief Raw Generic event.
+ *
+ * A generic event structure as used on the wire, i.e., without the full_sequence field
+ */
+typedef struct {
+ uint8_t response_type; /**< Type of the response */
+ uint8_t pad0; /**< Padding */
+ uint16_t sequence; /**< Sequence number */
+ uint32_t pad[7]; /**< Padding */
+} xcb_raw_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.
*
* @deprecated Since some fields in this struct have unfortunate names, it is
* recommended to use xcb_ge_generic_event_t instead.
--
2.1.4
More information about the Xcb
mailing list