<struct name="KTMapEntry">
<field name="active" type="BOOL" />
+ <!-- Xlib uses a different arrangement of fields
<field name="mods_mask" type="CARD8" mask="ModMask" />
<field name="level" type="CARD8" />
+ -->
+ <field name="level" type="CARD8" />
+ <field name="mods_mask" type="CARD8" mask="ModMask" />
<field name="mods_mods" type="CARD8" mask="ModMask" />
<field name="mods_vmods" type="CARD16" mask="VMod" />
<pad bytes="2" />
<bitcase>
<enumref ref="NameDetail">KTLevelNames</enumref>
<list name="nLevelsPerType" type="CARD8">
- <fieldref>nKTLevels</fieldref>
+ <!-- Xlib uses NTypes here -
+ the spec says nKTLevels is correct, but
+ it does not work in reality
+ <fieldref>nKTLevels</fieldref> -->
+ <fieldref>nTypes</fieldref>
</list>
<list name="ktLevelNames" type="ATOM">
<sumof ref="nLevelsPerType" />
<pad bytes="16" />
<switch name="replies">
<fieldref>reported</fieldref>
- <bitcase>
+ <bitcase name="types">
<enumref ref="GBNDetail">Types</enumref>
+ <!-- from the spec, this has to be a GetMap reply -->
+ <field name="type" type="CARD8" />
+ <!-- done 'emulating' GetMap reply header-->
<field name="typeDeviceID" type="CARD8" />
+ <!-- from the spec, this has to be a GetMap reply -->
+ <field name="sequence" type="CARD16" />
+ <field name="length" type="CARD32" />
+ <!-- done 'emulating' GetMap reply header-->
<pad bytes="2" />
<field name="typeMinKeyCode" type="KEYCODE" />
<field name="typeMaxKeyCode" type="KEYCODE" />
</bitcase>
</switch>
</bitcase>
- <bitcase>
+ <bitcase name="compat_map">
<enumref ref="GBNDetail">CompatMap</enumref>
<field name="compatDeviceID" type="CARD8" />
<field name="groupsRtrn" type="CARD8" mask="SetOfGroup" />
</popcount>
</list>
</bitcase>
- <bitcase>
+ <bitcase name="client_symbols">
<enumref ref="GBNDetail">ClientSymbols</enumref>
<field name="clientDeviceID" type="CARD8" />
<pad bytes="2" />
</bitcase>
</switch>
</bitcase>
- <bitcase>
+ <bitcase name="server_symbols">
<enumref ref="GBNDetail">ServerSymbols</enumref>
<field name="serverDeviceID" type="CARD8" />
<pad bytes="2" />
</bitcase>
</switch>
</bitcase>
- <bitcase>
+ <bitcase name="indicator_maps">
<enumref ref="GBNDetail">IndicatorMaps</enumref>
<field name="indicatorDeviceID" type="CARD8" />
<field name="which" type="CARD32" />
<fieldref>nIndicators</fieldref>
</list>
</bitcase>
- <bitcase>
+ <bitcase name="key_names">
<enumref ref="GBNDetail">KeyNames</enumref>
<field name="keyDeviceID" type="CARD8" />
<field name="which" type="CARD32" mask="NameDetail" />
</bitcase>
</switch>
</bitcase>
- <bitcase>
+ <bitcase name="other_names">
<enumref ref="GBNDetail">OtherNames</enumref>
<field name="otherDeviceID" type="CARD8" />
<field name="which" type="CARD32" mask="NameDetail" />
</bitcase>
</switch>
</bitcase>
- <bitcase>
+ <bitcase name="geometry">
<enumref ref="GBNDetail">Geometry</enumref>
<field name="geometryDeviceID" type="CARD8" />
<field name="name" type="ATOM" />
<item name="Static"> <value>10</value></item>
</enum>
+ <enum name="BorderPixmap">
+ <item name="CopyFromParent"><value>0</value></item>
+ </enum>
+
+ <enum name="ColorMap">
+ <item name="CopyFromParent"><value>0</value></item>
+ </enum>
+
<request name="CreateWindow" opcode="1">
<field type="CARD8" name="depth" />
<field type="WINDOW" name="wid" />
<field type="CARD16" name="border_width" />
<field type="CARD16" name="class" enum="WindowClass" />
<field type="VISUALID" name="visual" />
- <valueparam value-mask-type="CARD32"
- value-mask-name="value_mask"
- value-list-name="value_list" />
+ <field type="CARD32" name="value_mask" enum="CW" />
+ <switch name="value_list" fixed_type="CARD32">
+ <fieldref>value_mask</fieldref>
+ <bitcase>
+ <enumref ref="CW">BackPixmap</enumref>
+ <field name="background_pixmap" type="PIXMAP" altenum="BackPixmap" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BackPixel</enumref>
+ <field name="background_pixel" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BorderPixmap</enumref>
+ <field name="border_pixmap" type="PIXMAP" altenum="BorderPixmap" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BorderPixel</enumref>
+ <field name="border_pixel" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BitGravity</enumref>
+ <field name="bit_gravity" type="CARD32" enum="Gravity" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">WinGravity</enumref>
+ <field name="win_gravity" type="CARD32" enum="Gravity" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BackingStore</enumref>
+ <field name="backing_store" type="CARD32" enum="BackingStore" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BackingPlanes</enumref>
+ <field name="backing_planes" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">BackingPixel</enumref>
+ <field name="backing_pixel" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">OverrideRedirect</enumref>
+ <field name="override_redirect" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">SaveUnder</enumref>
+ <field name="save_under" type="CARD32" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">EventMask</enumref>
+ <field name="event_mask" type="CARD32" enum="EventMask" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">DontPropagate</enumref>
+ <field name="dont_propagate" type="CARD32" enum="EventMask" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">Colormap</enumref>
+ <field name="colormap" type="COLORMAP" altenum="ColorMap" />
+ </bitcase>
+ <bitcase>
+ <enumref ref="CW">Cursor</enumref>
+ <field name="cursor" type="CURSOR" altenum="Cursor" />
+ </bitcase>
+ </switch>
</request>
<request name="ChangeWindowAttributes" opcode="2">
self.is_reply = False
self.is_union = False
self.is_pad = False
+ self.is_switch = False
+ self.is_bitcase = False
def resolve(self, module):
'''
complex_type.fields.append(new_field)
+
class SimpleType(Type):
'''
Derived class which represents a cardinal type like CARD32 or char.
parent is the structure type containing the list.
expr is an Expression object containing the length information, for variable-sized lists.
'''
- def __init__(self, elt, member, parent):
+ def __init__(self, elt, member, *parent):
Type.__init__(self, member.name)
self.is_list = True
self.member = member
- self.parent = parent
+ self.parents = list(parent)
if elt.tag == 'list':
elts = list(elt)
needlen = True
# See if the length field is already in the structure.
- for field in self.parent.fields:
- if field.field_name == lenfield_name:
- needlen = False
+ for parent in self.parents:
+ for field in parent.fields:
+ if field.field_name == lenfield_name:
+ needlen = False
# It isn't, so we need to add it to the structure ourself.
if needlen:
if self.resolved:
return
self.member.resolve(module)
+ self.expr.resolve(module, self.parents)
# Find my length field again. We need the actual Field object in the expr.
# This is needed because we might have added it ourself above.
if not self.fixed_size():
- for field in self.parent.fields:
- if field.field_name == self.expr.lenfield_name and field.wire:
- self.expr.lenfield = field
- break
-
+ for parent in self.parents:
+ for field in parent.fields:
+ if field.field_name == self.expr.lenfield_name and field.wire:
+ self.expr.lenfield = field
+ break
+
self.resolved = True
def fixed_size(self):
Public fields added:
expr is an Expression object containing the value of the field.
'''
- def __init__(self, elt, member, parent):
+ def __init__(self, elt, member, *parent):
Type.__init__(self, member.name)
self.is_expr = True
self.member = member
self.fields = []
self.nmemb = 1
self.size = 0
+ self.lenfield_parent = [self]
def resolve(self, module):
if self.resolved:
elif child.tag == 'exprfield':
field_name = child.get('name')
fkey = child.get('type')
- type = ExprType(child, module.get_type(fkey), self)
+ type = ExprType(child, module.get_type(fkey), *self.lenfield_parent)
visible = False
elif child.tag == 'list':
field_name = child.get('name')
fkey = child.get('type')
- type = ListType(child, module.get_type(fkey), self)
+ type = ListType(child, module.get_type(fkey), *self.lenfield_parent)
visible = True
elif child.tag == 'valueparam':
field_name = child.get('value-list-name')
fkey = 'CARD32'
- type = ListType(child, module.get_type(fkey), self)
+ type = ListType(child, module.get_type(fkey), *self.lenfield_parent)
+ visible = True
+ elif child.tag == 'switch':
+ field_name = child.get('name')
+ # construct the switch type name from the parent type and the field name
+ field_type = self.name + (field_name,)
+ type = SwitchType(field_type, child, *self.lenfield_parent)
visible = True
+ type.make_member_of(module, self, field_type, field_name, visible, True, False)
+ type.resolve(module)
+ continue
else:
# Hit this on Reply
continue
return False
return True
+class SwitchType(ComplexType):
+ '''
+ Derived class which represents a List of Items.
+
+ Public fields added:
+ bitcases is an array of Bitcase objects describing the list items
+ '''
+
+ def __init__(self, name, elt, *parents):
+ ComplexType.__init__(self, name, elt)
+ self.parents = parents
+ # FIXME: switch cannot store lenfields, so it should just delegate the parents
+ self.lenfield_parent = list(parents) + [self]
+ # self.fields contains all possible fields collected from the Bitcase objects,
+ # whereas self.items contains the Bitcase objects themselves
+ self.bitcases = []
+
+ self.is_switch = True
+ elts = list(elt)
+ self.expr = Expression(elts[0] if len(elts) else elt, self)
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+# pads = 0
+
+ parents = list(self.parents) + [self]
+
+ # Resolve all of our field datatypes.
+ for index, child in enumerate(list(self.elt)):
+ if child.tag == 'bitcase':
+ field_name = child.get('name')
+ if field_name is None:
+ field_type = self.name + ('bitcase%d' % index,)
+ else:
+ field_type = self.name + (field_name,)
+
+ # use self.parent to indicate anchestor,
+ # as switch does not contain named fields itself
+ type = BitcaseType(index, field_type, child, *parents)
+ # construct the switch type name from the parent type and the field name
+ if field_name is None:
+ type.has_name = False
+ # Get the full type name for the field
+ field_type = type.name
+ visible = True
+
+ # add the field to ourself
+ type.make_member_of(module, self, field_type, field_name, visible, True, False)
+
+ # recursively resolve the type (could be another structure, list)
+ type.resolve(module)
+ inserted = False
+ for new_field in type.fields:
+ # We dump the _placeholder_byte if any fields are added.
+ for (idx, field) in enumerate(self.fields):
+ if field == _placeholder_byte:
+ self.fields[idx] = new_field
+ inserted = True
+ break
+ if False == inserted:
+ self.fields.append(new_field)
+
+ self.calc_size() # Figure out how big we are
+ self.resolved = True
+
+ def make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto):
+ if not self.fixed_size():
+ # We need a length field.
+ # Ask our Expression object for it's name, type, and whether it's on the wire.
+ lenfid = self.expr.lenfield_type
+ lenfield_name = self.expr.lenfield_name
+ lenwire = self.expr.lenwire
+ needlen = True
+
+ # See if the length field is already in the structure.
+ for parent in self.parents:
+ for field in parent.fields:
+ if field.field_name == lenfield_name:
+ needlen = False
+
+ # It isn't, so we need to add it to the structure ourself.
+ if needlen:
+ type = module.get_type(lenfid)
+ lenfield_type = module.get_type_name(lenfid)
+ type.make_member_of(module, complex_type, lenfield_type, lenfield_name, True, lenwire, False)
+
+ # Add ourself to the structure by calling our original method.
+ Type.make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto)
+
+ # size for switch can only be calculated at runtime
+ def calc_size(self):
+ pass
+
+ # note: switch is _always_ of variable size, but we indicate here wether
+ # it contains elements that are variable-sized themselves
+ def fixed_size(self):
+ return False
+# for m in self.fields:
+# if not m.type.fixed_size():
+# return False
+# return True
+
class Struct(ComplexType):
'''
out = __main__.output['union']
+class BitcaseType(ComplexType):
+ '''
+ Derived class representing a struct data type.
+ '''
+ def __init__(self, index, name, elt, *parent):
+ elts = list(elt)
+ self.expr = Expression(elts[0] if len(elts) else elt, self)
+ ComplexType.__init__(self, name, elts[1:])
+ self.has_name = True
+ self.index = 1
+ self.lenfield_parent = list(parent) + [self]
+ self.parents = list(parent)
+ self.is_bitcase = True
+
+ def make_member_of(self, module, switch_type, field_type, field_name, visible, wire, auto):
+ '''
+ register BitcaseType with the corresponding SwitchType
+
+ module is the global module object.
+ complex_type is the structure object.
+ see Field for the meaning of the other parameters.
+ '''
+ new_field = Field(self, field_type, field_name, visible, wire, auto)
+
+ # We dump the _placeholder_byte if any bitcases are added.
+ for (idx, field) in enumerate(switch_type.bitcases):
+ if field == _placeholder_byte:
+ switch_type.bitcases[idx] = new_field
+ return
+
+ switch_type.bitcases.append(new_field)
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+
+ self.expr.resolve(module, self.parents+[self])
+
+ # Resolve the bitcase expression
+ ComplexType.resolve(self, module)
+
+
class Reply(ComplexType):
'''
Derived class representing a reply. Only found as a field of Request.