The Great XCB Renaming

Rename API to follow a new naming convention:
* XCB_CONSTANTS_UPPERCASE_WITH_UNDERSCORES
* xcb_functions_lowercase_with_underscores
* xcb_types_lowercase_with_underscores_and_suffix_t
* expand all abbreviations like "req", "rep", and "iter"

Word boundaries for the names in the protocol descriptions fall:
* Wherever the protocol descriptions already have an underscore
* Between a lowercase letter and a subsequent uppercase letter
* Before the last uppercase letter in a string of uppercase letters followed
  by a lowercase letter (such as in LSBFirst between LSB and First)
* Before and after a string of digits (with exceptions for sized types like
  xcb_char2b_t and xcb_glx_float32_t to match the stdint.h convention)

Also fix up some particular naming issues:
* Rename shape_op and shape_kind to drop the "shape_" prefix, since otherwise
  these types end up as xcb_shape_shape_{op,kind}_t.
* Remove leading underscores from enums in the GLX protocol description,
  previously needed to ensure a word separator, but now redundant.

This renaming breaks code written for the previous API naming convention.  The
scripts in XCB's tools directory will convert code written for the old API to
use the new API; they work well enough that we used them to convert the
non-program-generated code in XCB, and when run on the old program-generated
code, they almost exactly reproduce the new program-generated code (modulo
whitespace and bugs in the old code generator).

Authors: Vincent Torri, Thomas Hunger, Josh Triplett
This commit is contained in:
Josh Triplett 2006-09-23 12:22:22 -07:00
parent ca72e77774
commit a3bd6f4760
14 changed files with 505 additions and 391 deletions

View File

@ -26,7 +26,11 @@ authorization from the authors.
--> -->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" version="1.0"
xmlns:e="http://exslt.org/common"> xmlns:e="http://exslt.org/common"
xmlns:func="http://exslt.org/functions"
xmlns:str="http://exslt.org/strings"
xmlns:xcb="http://xcb.freedesktop.org"
extension-element-prefixes="func str xcb">
<xsl:output method="text" /> <xsl:output method="text" />
@ -49,6 +53,8 @@ authorization from the authors.
<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> <xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="letters" select="concat($ucase, $lcase)" />
<xsl:variable name="digits" select="'0123456789'" />
<xsl:variable name="header" select="/xcb/@header" /> <xsl:variable name="header" select="/xcb/@header" />
<xsl:variable name="ucase-header" <xsl:variable name="ucase-header"
@ -80,19 +86,134 @@ authorization from the authors.
<xcb> <xcb>
<xsl:copy-of select="@*" /> <xsl:copy-of select="@*" />
<xsl:if test="$ext"> <xsl:if test="$ext">
<constant type="XCBExtension" name="XCB{$ext}Id"> <constant type="xcb_extension_t" name="{xcb:xcb-prefix()}_id">
<xsl:attribute name="value">{ "<xsl:value-of select="@extension-xname" />" }</xsl:attribute> <xsl:attribute name="value">{ "<xsl:value-of select="@extension-xname" />" }</xsl:attribute>
</constant> </constant>
<function type="const XCBQueryExtensionRep *" name="XCB{$ext}Init"> <function type="const xcb_query_extension_reply_t *" name="{xcb:xcb-prefix('init')}">
<field type="XCBConnection *" name="c" /> <field type="xcb_connection_t *" name="c" />
<l>return XCBGetExtensionData(c, &amp;XCB<!-- <l>return xcb_get_extension_data(c, &amp;<!--
--><xsl:value-of select="$ext" />Id);</l> --><xsl:value-of select="xcb:xcb-prefix()" />_id);</l>
</function> </function>
</xsl:if> </xsl:if>
<xsl:apply-templates mode="pass1" /> <xsl:apply-templates mode="pass1" />
</xcb> </xcb>
</xsl:template> </xsl:template>
<func:function name="xcb:xcb-prefix">
<xsl:param name="name" />
<func:result>
<xsl:text>xcb</xsl:text>
<xsl:choose>
<xsl:when test="/xcb/@extension-name = 'RandR'">
<xsl:text>_randr</xsl:text>
</xsl:when>
<xsl:when test="/xcb/@extension-name = 'ScreenSaver'">
<xsl:text>_screensaver</xsl:text>
</xsl:when>
<xsl:when test="/xcb/@extension-name = 'XF86Dri'">
<xsl:text>_xf86dri</xsl:text>
</xsl:when>
<xsl:when test="/xcb/@extension-name = 'XFixes'">
<xsl:text>_xfixes</xsl:text>
</xsl:when>
<xsl:when test="/xcb/@extension-name = 'XvMC'">
<xsl:text>_xvmc</xsl:text>
</xsl:when>
<xsl:when test="/xcb/@extension-name">
<xsl:text>_</xsl:text>
<xsl:call-template name="camelcase-to-underscore">
<xsl:with-param name="camelcase" select="/xcb/@extension-name" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$name">
<xsl:text>_</xsl:text>
<xsl:call-template name="camelcase-to-underscore">
<xsl:with-param name="camelcase" select="$name" />
</xsl:call-template>
</xsl:if>
</func:result>
</func:function>
<func:function name="xcb:lowercase">
<xsl:param name="name" />
<func:result>
<xsl:call-template name="camelcase-to-underscore">
<xsl:with-param name="camelcase" select="$name" />
</xsl:call-template>
</func:result>
</func:function>
<func:function name="xcb:get-char-void">
<xsl:param name="name" />
<xsl:variable name="ctype" select="substring-before($name, '_t')" />
<func:result>
<xsl:choose>
<xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
<xsl:value-of select="$ctype" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name" />
</xsl:otherwise>
</xsl:choose>
</func:result>
</func:function>
<func:function name="xcb:remove-void">
<xsl:param name="name" />
<xsl:variable name="ctype" select="substring-before($name, '_t')" />
<func:result>
<xsl:choose>
<xsl:when test="$ctype = 'char' or $ctype = 'void' or $ctype = 'float' or $ctype = 'double'">
<xsl:choose>
<xsl:when test="$ctype = 'void'">
<xsl:text>char</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ctype" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name" />
</xsl:otherwise>
</xsl:choose>
</func:result>
</func:function>
<!-- split camel case into words and insert underscore -->
<xsl:template name="camelcase-to-underscore">
<xsl:param name="camelcase"/>
<xsl:choose>
<xsl:when test="$camelcase='CHAR2B' or $camelcase='INT64'
or $camelcase='FLOAT32' or $camelcase='FLOAT64'
or $camelcase='BOOL32' or $camelcase='STRING8'
or $camelcase='Family_DECnet'">
<xsl:value-of select="translate($camelcase, $ucase, $lcase)"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="str:split($camelcase, '')">
<xsl:variable name="a" select="."/>
<xsl:variable name="b" select="following::*[1]"/>
<xsl:variable name="c" select="following::*[2]"/>
<xsl:value-of select="translate(., $ucase, $lcase)"/>
<xsl:if test="($b and contains($lcase, $a) and contains($ucase, $b))
or ($b and contains($digits, $a)
and contains($letters, $b))
or ($b and contains($letters, $a)
and contains($digits, $b))
or ($c and contains($ucase, $a)
and contains($ucase, $b)
and contains($lcase, $c))">
<xsl:text>_</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Modify names that conflict with C++ keywords by prefixing them with an <!-- Modify names that conflict with C++ keywords by prefixing them with an
underscore. If the name parameter is not specified, it defaults to the underscore. If the name parameter is not specified, it defaults to the
value of the name attribute on the context node. --> value of the name attribute on the context node. -->
@ -107,27 +228,26 @@ authorization from the authors.
<!-- List of core types, for use in canonical-type-name. --> <!-- List of core types, for use in canonical-type-name. -->
<xsl:variable name="core-types-rtf"> <xsl:variable name="core-types-rtf">
<type name="BOOL" /> <type name="BOOL" newname="uint8" />
<type name="BYTE" /> <type name="BYTE" newname="uint8" />
<type name="CARD8" /> <type name="CARD8" newname="uint8" />
<type name="CARD16" /> <type name="CARD16" newname="uint16" />
<type name="CARD32" /> <type name="CARD32" newname="uint32" />
<type name="INT8" /> <type name="INT8" newname="int8" />
<type name="INT16" /> <type name="INT16" newname="int16" />
<type name="INT32" /> <type name="INT32" newname="int32" />
<type name="char" /> <type name="char" newname="char" />
<type name="void" /> <type name="void" newname="void" />
<type name="float" /> <type name="float" newname="float" />
<type name="double" /> <type name="double" newname="double" />
<type name="XID" />
</xsl:variable> </xsl:variable>
<xsl:variable name="core-types" select="e:node-set($core-types-rtf)" /> <xsl:variable name="core-types" select="e:node-set($core-types-rtf)" />
<!-- <!--
Output the canonical name for a type. This will be Output the canonical name for a type. This will be
XCB{extension-containing-Type-if-any}Type, wherever the type is found in xcb_{extension-containing-type-if-any}_type, wherever the type is found in
the search path, or just Type if not found. If the type parameter is not the search path, or just type if not found. If the type parameter is not
specified, it defaults to the value of the type attribute on the context specified, it defaults to the value of the type attribute on the context
node. node.
--> -->
@ -149,7 +269,7 @@ authorization from the authors.
<xsl:choose> <xsl:choose>
<xsl:when test="$is-unqualified and $core-types/type[@name=$type]"> <xsl:when test="$is-unqualified and $core-types/type[@name=$type]">
<xsl:value-of select="$type" /> <xsl:value-of select="$core-types/type[@name=$type]/@newname" />
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:variable name="type-definitions" <xsl:variable name="type-definitions"
@ -165,9 +285,7 @@ authorization from the authors.
<xsl:choose> <xsl:choose>
<xsl:when test="count($type-definitions) = 1"> <xsl:when test="count($type-definitions) = 1">
<xsl:for-each select="$type-definitions"> <xsl:for-each select="$type-definitions">
<xsl:text>XCB</xsl:text> <xsl:value-of select="xcb:xcb-prefix($unqualified-type)" />
<xsl:value-of select="concat(/xcb/@extension-name,
$unqualified-type)" />
</xsl:for-each> </xsl:for-each>
</xsl:when> </xsl:when>
<xsl:when test="count($type-definitions) > 1"> <xsl:when test="count($type-definitions) > 1">
@ -205,16 +323,15 @@ authorization from the authors.
context node. --> context node. -->
<xsl:template name="cookie-type"> <xsl:template name="cookie-type">
<xsl:param name="request" select="." /> <xsl:param name="request" select="." />
<xsl:text>XCB</xsl:text>
<xsl:choose> <xsl:choose>
<xsl:when test="$request/reply"> <xsl:when test="$request/reply">
<xsl:value-of select="concat($ext, $request/@name)" /> <xsl:value-of select="xcb:xcb-prefix($request/@name)" />
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:text>Void</xsl:text> <xsl:text>xcb_void</xsl:text>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
<xsl:text>Cookie</xsl:text> <xsl:text>_cookie_t</xsl:text>
</xsl:template> </xsl:template>
<xsl:template name="request-function"> <xsl:template name="request-function">
@ -222,20 +339,18 @@ authorization from the authors.
<xsl:param name="req" /> <xsl:param name="req" />
<function> <function>
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:text>XCB</xsl:text> <xsl:value-of select="xcb:xcb-prefix($req/@name)" />
<xsl:value-of select="$ext" /> <xsl:if test="$checked='true' and not($req/reply)">_checked</xsl:if>
<xsl:value-of select="$req/@name" /> <xsl:if test="$checked='false' and $req/reply">_unchecked</xsl:if>
<xsl:if test="$checked='true' and not($req/reply)">Checked</xsl:if>
<xsl:if test="$checked='false' and $req/reply">Unchecked</xsl:if>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="type"> <xsl:attribute name="type">
<xsl:call-template name="cookie-type"> <xsl:call-template name="cookie-type">
<xsl:with-param name="request" select="$req" /> <xsl:with-param name="request" select="$req" />
</xsl:call-template> </xsl:call-template>
</xsl:attribute> </xsl:attribute>
<field type="XCBConnection *" name="c" /> <field type="xcb_connection_t *" name="c" />
<xsl:apply-templates select="$req/*[not(self::reply)]" mode="param" /> <xsl:apply-templates select="$req/*[not(self::reply)]" mode="param" />
<do-request ref="XCB{$ext}{$req/@name}Req" opcode="{$req/@opcode}" <do-request ref="{xcb:xcb-prefix($req/@name)}_request_t" opcode="{$req/@opcode}"
checked="{$checked}"> checked="{$checked}">
<xsl:if test="$req/reply"> <xsl:if test="$req/reply">
<xsl:attribute name="has-reply">true</xsl:attribute> <xsl:attribute name="has-reply">true</xsl:attribute>
@ -247,18 +362,18 @@ authorization from the authors.
<xsl:template match="request" mode="pass1"> <xsl:template match="request" mode="pass1">
<xsl:variable name="req" select="." /> <xsl:variable name="req" select="." />
<xsl:if test="reply"> <xsl:if test="reply">
<struct name="XCB{$ext}{@name}Cookie"> <struct name="{xcb:xcb-prefix(@name)}_cookie_t">
<field type="unsigned int" name="sequence" /> <field type="unsigned int" name="sequence" />
</struct> </struct>
</xsl:if> </xsl:if>
<struct name="XCB{$ext}{@name}Req"> <struct name="{xcb:xcb-prefix(@name)}_request_t">
<field type="CARD8" name="major_opcode" no-assign="true" /> <field type="uint8_t" name="major_opcode" no-assign="true" />
<xsl:if test="$ext"> <xsl:if test="$ext">
<field type="CARD8" name="minor_opcode" no-assign="true" /> <field type="uint8_t" name="minor_opcode" no-assign="true" />
</xsl:if> </xsl:if>
<xsl:apply-templates select="*[not(self::reply)]" mode="field" /> <xsl:apply-templates select="*[not(self::reply)]" mode="field" />
<middle> <middle>
<field type="CARD16" name="length" no-assign="true" /> <field type="uint16_t" name="length" no-assign="true" />
</middle> </middle>
</struct> </struct>
<xsl:call-template name="request-function"> <xsl:call-template name="request-function">
@ -270,83 +385,83 @@ authorization from the authors.
<xsl:with-param name="req" select="$req" /> <xsl:with-param name="req" select="$req" />
</xsl:call-template> </xsl:call-template>
<xsl:if test="reply"> <xsl:if test="reply">
<struct name="XCB{$ext}{@name}Rep"> <struct name="{xcb:xcb-prefix(@name)}_reply_t">
<field type="BYTE" name="response_type" /> <field type="uint8_t" name="response_type" />
<xsl:apply-templates select="reply/*" mode="field" /> <xsl:apply-templates select="reply/*" mode="field" />
<middle> <middle>
<field type="CARD16" name="sequence" /> <field type="uint16_t" name="sequence" />
<field type="CARD32" name="length" /> <field type="uint32_t" name="length" />
</middle> </middle>
</struct> </struct>
<iterator-functions ref="XCB{$ext}{@name}" kind="Rep" /> <iterator-functions ref="{xcb:xcb-prefix(@name)}" kind="_reply" />
<function type="XCB{$ext}{@name}Rep *" name="XCB{$ext}{@name}Reply"> <function type="{xcb:xcb-prefix(@name)}_reply_t *" name="{xcb:xcb-prefix(@name)}_reply">
<field type="XCBConnection *" name="c" /> <field type="xcb_connection_t *" name="c" />
<field name="cookie"> <field name="cookie">
<xsl:attribute name="type"> <xsl:attribute name="type">
<xsl:call-template name="cookie-type" /> <xsl:call-template name="cookie-type" />
</xsl:attribute> </xsl:attribute>
</field> </field>
<field type="XCBGenericError **" name="e" /> <field type="xcb_generic_error_t **" name="e" />
<l>return (XCB<xsl:value-of select="concat($ext, @name)" />Rep *)<!-- <l>return (<xsl:value-of select="xcb:xcb-prefix(@name)" />_reply_t *)<!--
--> XCBWaitForReply(c, cookie.sequence, e);</l> --> xcb_wait_for_reply(c, cookie.sequence, e);</l>
</function> </function>
</xsl:if> </xsl:if>
</xsl:template> </xsl:template>
<xsl:template match="xidtype" mode="pass1"> <xsl:template match="xidtype" mode="pass1">
<struct name="XCB{$ext}{@name}"> <struct name="{xcb:xcb-prefix(@name)}_t">
<field type="CARD32" name="xid" /> <field type="uint32_t" name="xid" />
</struct> </struct>
<iterator ref="XCB{$ext}{@name}" /> <iterator ref="{xcb:xcb-prefix(@name)}" />
<iterator-functions ref="XCB{$ext}{@name}" /> <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
<function type="XCB{$ext}{@name}" name="XCB{$ext}{@name}New"> <function type="{xcb:xcb-prefix(@name)}_t" name="{xcb:xcb-prefix(@name)}_new">
<field type="XCBConnection *" name="c" /> <field type="xcb_connection_t *" name="c" />
<l>XCB<xsl:value-of select="concat($ext, @name)" /> ret;</l> <l><xsl:value-of select="concat(xcb:xcb-prefix(@name), '_t')" /> ret;</l>
<l>ret.xid = XCBGenerateID(c);</l> <l>ret.xid = xcb_generate_id(c);</l>
<l>return ret;</l> <l>return ret;</l>
</function> </function>
</xsl:template> </xsl:template>
<xsl:template match="struct|union" mode="pass1"> <xsl:template match="struct|union" mode="pass1">
<struct name="XCB{$ext}{@name}"> <struct name="{xcb:xcb-prefix(@name)}_t">
<xsl:if test="self::union"> <xsl:if test="self::union">
<xsl:attribute name="kind">union</xsl:attribute> <xsl:attribute name="kind">union</xsl:attribute>
</xsl:if> </xsl:if>
<xsl:apply-templates select="*" mode="field" /> <xsl:apply-templates select="*" mode="field" />
</struct> </struct>
<iterator ref="XCB{$ext}{@name}" /> <iterator ref="{xcb:xcb-prefix(@name)}" />
<iterator-functions ref="XCB{$ext}{@name}" /> <iterator-functions ref="{xcb:xcb-prefix(@name)}" />
</xsl:template> </xsl:template>
<xsl:template match="event|eventcopy|error|errorcopy" mode="pass1"> <xsl:template match="event|eventcopy|error|errorcopy" mode="pass1">
<xsl:variable name="suffix"> <xsl:variable name="suffix">
<xsl:choose> <xsl:choose>
<xsl:when test="self::event|self::eventcopy"> <xsl:when test="self::event|self::eventcopy">
<xsl:text>Event</xsl:text> <xsl:text>_event_t</xsl:text>
</xsl:when> </xsl:when>
<xsl:when test="self::error|self::errorcopy"> <xsl:when test="self::error|self::errorcopy">
<xsl:text>Error</xsl:text> <xsl:text>_error_t</xsl:text>
</xsl:when> </xsl:when>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<constant type="number" name="XCB{$ext}{@name}" value="{@number}" /> <constant type="number" name="{xcb:xcb-prefix(@name)}" value="{@number}" />
<xsl:choose> <xsl:choose>
<xsl:when test="self::event|self::error"> <xsl:when test="self::event|self::error">
<struct name="XCB{$ext}{@name}{$suffix}"> <struct name="{xcb:xcb-prefix(@name)}{$suffix}">
<field type="BYTE" name="response_type" /> <field type="uint8_t" name="response_type" />
<xsl:if test="self::error"> <xsl:if test="self::error">
<field type="BYTE" name="error_code" /> <field type="uint8_t" name="error_code" />
</xsl:if> </xsl:if>
<xsl:apply-templates select="*" mode="field" /> <xsl:apply-templates select="*" mode="field" />
<xsl:if test="not(self::event and boolean(@no-sequence-number))"> <xsl:if test="not(self::event and boolean(@no-sequence-number))">
<middle> <middle>
<field type="CARD16" name="sequence" /> <field type="uint16_t" name="sequence" />
</middle> </middle>
</xsl:if> </xsl:if>
</struct> </struct>
</xsl:when> </xsl:when>
<xsl:when test="self::eventcopy|self::errorcopy"> <xsl:when test="self::eventcopy|self::errorcopy">
<typedef newname="XCB{$ext}{@name}{$suffix}"> <typedef newname="{xcb:xcb-prefix(@name)}{$suffix}">
<xsl:attribute name="oldname"> <xsl:attribute name="oldname">
<xsl:call-template name="canonical-type-name"> <xsl:call-template name="canonical-type-name">
<xsl:with-param name="type" select="@ref" /> <xsl:with-param name="type" select="@ref" />
@ -364,21 +479,23 @@ authorization from the authors.
<xsl:call-template name="canonical-type-name"> <xsl:call-template name="canonical-type-name">
<xsl:with-param name="type" select="@oldname" /> <xsl:with-param name="type" select="@oldname" />
</xsl:call-template> </xsl:call-template>
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="newname"> <xsl:attribute name="newname">
<xsl:call-template name="canonical-type-name"> <xsl:call-template name="canonical-type-name">
<xsl:with-param name="type" select="@newname" /> <xsl:with-param name="type" select="@newname" />
</xsl:call-template> </xsl:call-template>
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
</typedef> </typedef>
<iterator ref="XCB{$ext}{@newname}" /> <iterator ref="{xcb:xcb-prefix(@newname)}" />
<iterator-functions ref="XCB{$ext}{@newname}" /> <iterator-functions ref="{xcb:xcb-prefix(@newname)}" />
</xsl:template> </xsl:template>
<xsl:template match="enum" mode="pass1"> <xsl:template match="enum" mode="pass1">
<enum name="XCB{$ext}{@name}"> <enum name="{xcb:xcb-prefix(@name)}_t">
<xsl:for-each select="item"> <xsl:for-each select="item">
<item name="XCB{$ext}{../@name}{@name}"> <item name="{translate(xcb:xcb-prefix(concat(../@name, concat('_', @name))), $lcase, $ucase)}">
<xsl:copy-of select="*" /> <xsl:copy-of select="*" />
</item> </item>
</xsl:for-each> </xsl:for-each>
@ -397,6 +514,7 @@ authorization from the authors.
<xsl:copy> <xsl:copy>
<xsl:attribute name="type"> <xsl:attribute name="type">
<xsl:call-template name="canonical-type-name" /> <xsl:call-template name="canonical-type-name" />
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name" /> <xsl:call-template name="canonical-var-name" />
@ -407,7 +525,8 @@ authorization from the authors.
<xsl:template match="list" mode="field"> <xsl:template match="list" mode="field">
<xsl:variable name="type"><!-- <xsl:variable name="type"><!--
--><xsl:call-template name="canonical-type-name" /><!-- --><xsl:call-template name="canonical-type-name" />
<xsl:text>_t</xsl:text><!--
--></xsl:variable> --></xsl:variable>
<list type="{$type}"> <list type="{$type}">
<xsl:attribute name="name"> <xsl:attribute name="name">
@ -458,6 +577,7 @@ authorization from the authors.
<xsl:call-template name="canonical-type-name"> <xsl:call-template name="canonical-type-name">
<xsl:with-param name="type" select="@value-mask-type" /> <xsl:with-param name="type" select="@value-mask-type" />
</xsl:call-template> </xsl:call-template>
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name"> <xsl:call-template name="canonical-var-name">
@ -465,13 +585,13 @@ authorization from the authors.
</xsl:call-template> </xsl:call-template>
</xsl:attribute> </xsl:attribute>
</field> </field>
<list type="CARD32"> <list type="uint32_t">
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name"> <xsl:call-template name="canonical-var-name">
<xsl:with-param name="name" select="@value-list-name" /> <xsl:with-param name="name" select="@value-list-name" />
</xsl:call-template> </xsl:call-template>
</xsl:attribute> </xsl:attribute>
<function-call name="XCBPopcount"> <function-call name="xcb_popcount">
<param> <param>
<fieldref> <fieldref>
<xsl:call-template name="canonical-var-name"> <xsl:call-template name="canonical-var-name">
@ -487,6 +607,7 @@ authorization from the authors.
<field> <field>
<xsl:attribute name="type"> <xsl:attribute name="type">
<xsl:call-template name="canonical-type-name" /> <xsl:call-template name="canonical-type-name" />
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name" /> <xsl:call-template name="canonical-var-name" />
@ -497,12 +618,18 @@ authorization from the authors.
<xsl:template match="list" mode="param"> <xsl:template match="list" mode="param">
<!-- If no length expression is provided, use a CARD32 localfield. --> <!-- If no length expression is provided, use a CARD32 localfield. -->
<xsl:if test="not(node())"> <xsl:if test="not(node())">
<field type="CARD32" name="{@name}_len" /> <field type="uint32_t" name="{@name}_len" />
</xsl:if> </xsl:if>
<field> <field>
<xsl:variable name="ctype">
<xsl:call-template name="canonical-type-name" />
</xsl:variable>
<xsl:attribute name="type"> <xsl:attribute name="type">
<xsl:text>const </xsl:text> <xsl:text>const </xsl:text>
<xsl:call-template name="canonical-type-name" /> <xsl:call-template name="canonical-type-name" />
<xsl:if test="not($ctype='char') and not($ctype='void')">
<xsl:text>_t</xsl:text>
</xsl:if>
<xsl:text> *</xsl:text> <xsl:text> *</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="name"> <xsl:attribute name="name">
@ -517,6 +644,7 @@ authorization from the authors.
<xsl:call-template name="canonical-type-name"> <xsl:call-template name="canonical-type-name">
<xsl:with-param name="type" select="@value-mask-type" /> <xsl:with-param name="type" select="@value-mask-type" />
</xsl:call-template> </xsl:call-template>
<xsl:text>_t</xsl:text>
</xsl:attribute> </xsl:attribute>
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name"> <xsl:call-template name="canonical-var-name">
@ -524,7 +652,7 @@ authorization from the authors.
</xsl:call-template> </xsl:call-template>
</xsl:attribute> </xsl:attribute>
</field> </field>
<field type="const CARD32 *"> <field type="const uint32_t *">
<xsl:attribute name="name"> <xsl:attribute name="name">
<xsl:call-template name="canonical-var-name"> <xsl:call-template name="canonical-var-name">
<xsl:with-param name="name" select="@value-list-name" /> <xsl:with-param name="name" select="@value-list-name" />
@ -585,14 +713,14 @@ authorization from the authors.
<xsl:variable name="num-parts" select="(1+count($struct/list))*2" /> <xsl:variable name="num-parts" select="(1+count($struct/list))*2" />
<l>static const XCBProtocolRequest xcb_req = {</l> <l>static const xcb_protocol_request_t xcb_req = {</l>
<indent> <indent>
<l>/* count */ <xsl:value-of select="$num-parts" />,</l> <l>/* count */ <xsl:value-of select="$num-parts" />,</l>
<l>/* ext */ <xsl:choose> <l>/* ext */ <xsl:choose>
<xsl:when test="$ext"> <xsl:when test="$ext">
<xsl:text>&amp;XCB</xsl:text> <xsl:text>&amp;</xsl:text>
<xsl:value-of select="$ext" /> <xsl:value-of select="xcb:xcb-prefix()" />
<xsl:text>Id</xsl:text> <xsl:text>_id</xsl:text>
</xsl:when> </xsl:when>
<xsl:otherwise>0</xsl:otherwise> <xsl:otherwise>0</xsl:otherwise>
</xsl:choose>,</l> </xsl:choose>,</l>
@ -621,17 +749,24 @@ authorization from the authors.
<l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_base = (char *) <!-- <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_base = (char *) <!--
--><xsl:value-of select="@name" />;</l> --><xsl:value-of select="@name" />;</l>
<l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len = <!-- <l>xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len = <!--
--><xsl:apply-templates mode="output-expression" /><!-- --><xsl:apply-templates mode="output-expression" />
--><xsl:if test="not(@type = 'void')"> <xsl:if test="not(@type = 'void_t')">
<xsl:text> * sizeof(</xsl:text> <xsl:text> * sizeof(</xsl:text>
<xsl:choose>
<xsl:when test="@type='char_t'">
<xsl:text>char</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@type" /> <xsl:value-of select="@type" />
</xsl:otherwise>
</xsl:choose>
<xsl:text>)</xsl:text> <xsl:text>)</xsl:text>
</xsl:if>;</l> </xsl:if>;</l>
<l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_base = 0;</l> <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_base = 0;</l>
<l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_len = -xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len &amp; 3;</l> <l>xcb_parts[<xsl:value-of select="3 + position() * 2"/>].iov_len = -xcb_parts[<xsl:value-of select="2 + position() * 2"/>].iov_len &amp; 3;</l>
</xsl:for-each> </xsl:for-each>
<l>xcb_ret.sequence = XCBSendRequest(c, <!-- <l>xcb_ret.sequence = xcb_send_request(c, <!--
--><xsl:choose> --><xsl:choose>
<xsl:when test="@checked='true'">XCB_REQUEST_CHECKED</xsl:when> <xsl:when test="@checked='true'">XCB_REQUEST_CHECKED</xsl:when>
<xsl:otherwise>0</xsl:otherwise> <xsl:otherwise>0</xsl:otherwise>
@ -660,50 +795,30 @@ authorization from the authors.
</xsl:template> </xsl:template>
<xsl:template match="iterator" mode="pass2"> <xsl:template match="iterator" mode="pass2">
<struct name="{@ref}Iter"> <struct name="{@ref}_iterator_t">
<field type="{@ref} *" name="data" /> <field type="{@ref}_t *" name="data" />
<field type="int" name="rem" /> <field type="int" name="rem" />
<field type="int" name="index" /> <field type="int" name="index" />
</struct> </struct>
</xsl:template> </xsl:template>
<!-- Change a_name_like_this to ANameLikeThis. If the parameter name is not
given, it defaults to the name attribute of the context node. -->
<xsl:template name="capitalize">
<xsl:param name="name" select="string(@name)" />
<xsl:if test="$name">
<xsl:value-of select="translate(substring($name,1,1), $lcase, $ucase)" />
<xsl:choose>
<xsl:when test="contains($name, '_')">
<xsl:value-of select="substring(substring-before($name, '_'), 2)" />
<xsl:call-template name="capitalize">
<xsl:with-param name="name" select="substring-after($name, '_')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($name, 2)" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="iterator-functions" mode="pass2"> <xsl:template match="iterator-functions" mode="pass2">
<xsl:variable name="ref" select="@ref" /> <xsl:variable name="ref" select="@ref" />
<xsl:variable name="kind" select="@kind" /> <xsl:variable name="kind" select="@kind" />
<xsl:variable name="struct" <xsl:variable name="struct"
select="$pass1/xcb/struct[@name=concat($ref,$kind)]" /> select="$pass1/xcb/struct[@name=concat($ref, $kind, '_t')]" />
<xsl:variable name="nextfields-rtf"> <xsl:variable name="nextfields-rtf">
<nextfield>R + 1</nextfield> <nextfield>R + 1</nextfield>
<xsl:for-each select="$struct/list[not(@fixed)]"> <xsl:for-each select="$struct/list[not(@fixed)]">
<xsl:choose> <xsl:choose>
<xsl:when test="substring(@type, 1, 3) = 'XCB'"> <xsl:when test="substring(@type, 1, 3) = 'xcb'">
<nextfield><xsl:value-of select="@type" />End(<!-- <nextfield><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_end(<!--
--><xsl:value-of select="$ref" /><!-- --><xsl:value-of select="$ref" />_<!--
--><xsl:call-template name="capitalize" />Iter(R))</nextfield> --><xsl:value-of select="string(@name)" />_iterator(R))</nextfield>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<nextfield><xsl:value-of select="$ref" /><!-- <nextfield><xsl:value-of select="$ref" />_<!--
--><xsl:call-template name="capitalize" />End(R)</nextfield> --><xsl:value-of select="string(@name)" />_end(R)</nextfield>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:for-each> </xsl:for-each>
@ -715,52 +830,51 @@ authorization from the authors.
<xsl:variable name="nextfield" select="$nextfields/nextfield[$number]" /> <xsl:variable name="nextfield" select="$nextfields/nextfield[$number]" />
<xsl:variable name="is-first" <xsl:variable name="is-first"
select="not(preceding-sibling::list[not(@fixed)])" /> select="not(preceding-sibling::list[not(@fixed)])" />
<xsl:variable name="field-name"><!-- <xsl:variable name="field-name" select="@name" />
--><xsl:call-template name="capitalize" /><!--
--></xsl:variable>
<xsl:variable name="is-variable" <xsl:variable name="is-variable"
select="$pass1/xcb/struct[@name=current()/@type]/list select="$pass1/xcb/struct[@name=current()/@type]/list
or document($search-path)/xcb or document($search-path)/xcb
/struct[concat('XCB', /struct[concat(xcb:xcb-prefix(@name), '_t')
ancestor::xcb/@extension-name, = current()/@type]
@name) = current()/@type] /*[self::valueparam
/*[self::valueparam or self::list]" /> or self::list[.//*[not(self::value
or self::op)]]]" />
<xsl:if test="not($is-variable)"> <xsl:if test="not($is-variable)">
<function type="{@type} *" name="{$ref}{$field-name}"> <function type="{xcb:get-char-void(@type)} *" name="{$ref}_{xcb:lowercase($field-name)}">
<field type="const {$ref}{$kind} *" name="R" /> <field type="const {$ref}{$kind}_t *" name="R" />
<xsl:choose> <xsl:choose>
<xsl:when test="$is-first"> <xsl:when test="$is-first">
<l>return (<xsl:value-of select="@type" /> *) <!-- <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
-->(<xsl:value-of select="$nextfield" />);</l> -->(<xsl:value-of select="$nextfield" />);</l>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<l>XCBGenericIter prev = <!-- <l>xcb_generic_iterator_t prev = <!--
--><xsl:value-of select="$nextfield" />;</l> --><xsl:value-of select="$nextfield" />;</l>
<l>return (<xsl:value-of select="@type" /> *) <!-- <l>return (<xsl:value-of select="xcb:get-char-void(@type)" /> *) <!--
-->((char *) prev.data + XCB_TYPE_PAD(<!-- -->((char *) prev.data + XCB_TYPE_PAD(<!--
--><xsl:value-of select="@type" />, prev.index));</l> --><xsl:value-of select="xcb:get-char-void(@type)" />, prev.index));</l>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</function> </function>
</xsl:if> </xsl:if>
<function type="int" name="{$ref}{$field-name}Length"> <function type="int" name="{$ref}_{xcb:lowercase($field-name)}_length">
<field type="const {$ref}{$kind} *" name="R" /> <field type="const {$ref}{$kind}_t *" name="R" />
<l>return <xsl:apply-templates mode="output-expression"> <l>return <xsl:apply-templates mode="output-expression">
<xsl:with-param name="field-prefix" select="'R->'" /> <xsl:with-param name="field-prefix" select="'R->'" />
</xsl:apply-templates>;</l> </xsl:apply-templates>;</l>
</function> </function>
<xsl:choose> <xsl:choose>
<xsl:when test="substring(@type, 1, 3) = 'XCB'"> <xsl:when test="substring(@type, 1, 3) = 'xcb'">
<function type="{@type}Iter" name="{$ref}{$field-name}Iter"> <function type="{substring(@type, 1, string-length(@type)-2)}_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_iterator">
<field type="const {$ref}{$kind} *" name="R" /> <field type="const {$ref}{$kind}_t *" name="R" />
<l><xsl:value-of select="@type" />Iter i;</l> <l><xsl:value-of select="substring(@type, 1, string-length(@type)-2)" />_iterator_t i;</l>
<xsl:choose> <xsl:choose>
<xsl:when test="$is-first"> <xsl:when test="$is-first">
<l>i.data = (<xsl:value-of select="@type" /> *) <!-- <l>i.data = (<xsl:value-of select="@type" /> *) <!--
-->(<xsl:value-of select="$nextfield" />);</l> -->(<xsl:value-of select="$nextfield" />);</l>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<l>XCBGenericIter prev = <!-- <l>xcb_generic_iterator_t prev = <!--
--><xsl:value-of select="$nextfield" />;</l> --><xsl:value-of select="$nextfield" />;</l>
<l>i.data = (<xsl:value-of select="@type" /> *) <!-- <l>i.data = (<xsl:value-of select="@type" /> *) <!--
-->((char *) prev.data + XCB_TYPE_PAD(<!-- -->((char *) prev.data + XCB_TYPE_PAD(<!--
@ -781,21 +895,21 @@ authorization from the authors.
<xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise> <xsl:otherwise><xsl:value-of select="@type" /></xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
<function type="XCBGenericIter" name="{$ref}{$field-name}End"> <function type="xcb_generic_iterator_t" name="{$ref}_{xcb:lowercase($field-name)}_end">
<field type="const {$ref}{$kind} *" name="R" /> <field type="const {$ref}{$kind}_t *" name="R" />
<l>XCBGenericIter i;</l> <l>xcb_generic_iterator_t i;</l>
<xsl:choose> <xsl:choose>
<xsl:when test="$is-first"> <xsl:when test="$is-first">
<l>i.data = ((<xsl:value-of select="$cast" /> *) <!-- <l>i.data = ((<xsl:value-of select="xcb:remove-void($cast)" /> *) <!--
-->(<xsl:value-of select="$nextfield" />)) + (<!-- -->(<xsl:value-of select="$nextfield" />)) + (<!--
--><xsl:apply-templates mode="output-expression"> --><xsl:apply-templates mode="output-expression">
<xsl:with-param name="field-prefix" select="'R->'" /> <xsl:with-param name="field-prefix" select="'R->'" />
</xsl:apply-templates>);</l> </xsl:apply-templates>);</l>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<l>XCBGenericIter child = <!-- <l>xcb_generic_iterator_t child = <!--
--><xsl:value-of select="$nextfield" />;</l> --><xsl:value-of select="$nextfield" />;</l>
<l>i.data = ((<xsl:value-of select="$cast" /> *) <!-- <l>i.data = ((<xsl:value-of select="xcb:get-char-void($cast)" /> *) <!--
-->child.data) + (<!-- -->child.data) + (<!--
--><xsl:apply-templates mode="output-expression"> --><xsl:apply-templates mode="output-expression">
<xsl:with-param name="field-prefix" select="'R->'" /> <xsl:with-param name="field-prefix" select="'R->'" />
@ -810,32 +924,32 @@ authorization from the authors.
</xsl:choose> </xsl:choose>
</xsl:for-each> </xsl:for-each>
<xsl:if test="not($kind)"> <xsl:if test="not($kind)">
<function type="void" name="{$ref}Next"> <function type="void" name="{$ref}_next">
<field type="{$ref}Iter *" name="i" /> <field type="{$ref}_iterator_t *" name="i" />
<xsl:choose> <xsl:choose>
<xsl:when test="$struct/list[not(@fixed)]"> <xsl:when test="$struct/list[not(@fixed)]">
<l><xsl:value-of select="$ref" /> *R = i->data;</l> <l><xsl:value-of select="$ref" />_t *R = i->data;</l>
<l>XCBGenericIter child = <!-- <l>xcb_generic_iterator_t child = <!--
--><xsl:value-of select="$nextfields/nextfield[last()]" />;</l> --><xsl:value-of select="$nextfields/nextfield[last()]" />;</l>
<l>--i->rem;</l> <l>--i->rem;</l>
<l>i->data = (<xsl:value-of select="$ref" /> *) child.data;</l> <l>i->data = (<xsl:value-of select="$ref" />_t *) child.data;</l>
<l>i->index = child.index;</l> <l>i->index = child.index;</l>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<l>--i->rem;</l> <l>--i->rem;</l>
<l>++i->data;</l> <l>++i->data;</l>
<l>i->index += sizeof(<xsl:value-of select="$ref" />);</l> <l>i->index += sizeof(<xsl:value-of select="$ref" />_t);</l>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</function> </function>
<function type="XCBGenericIter" name="{$ref}End"> <function type="xcb_generic_iterator_t" name="{$ref}_end">
<field type="{$ref}Iter" name="i" /> <field type="{$ref}_iterator_t" name="i" />
<l>XCBGenericIter ret;</l> <l>xcb_generic_iterator_t ret;</l>
<xsl:choose> <xsl:choose>
<xsl:when test="$struct/list[not(@fixed)]"> <xsl:when test="$struct/list[not(@fixed)]">
<l>while(i.rem > 0)</l> <l>while(i.rem > 0)</l>
<indent> <indent>
<l><xsl:value-of select="$ref" />Next(&amp;i);</l> <l><xsl:value-of select="$ref" />_next(&amp;i);</l>
</indent> </indent>
<l>ret.data = i.data;</l> <l>ret.data = i.data;</l>
<l>ret.rem = i.rem;</l> <l>ret.rem = i.rem;</l>
@ -915,7 +1029,7 @@ authorization from the authors.
<xsl:when test="@type = 'number'"> <xsl:when test="@type = 'number'">
<xsl:if test="$h"> <xsl:if test="$h">
<xsl:text>#define </xsl:text> <xsl:text>#define </xsl:text>
<xsl:value-of select="@name" /> <xsl:value-of select="translate(@name, $lcase, $ucase)" />
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:value-of select="@value" /> <xsl:value-of select="@value" />
<xsl:text> <xsl:text>
@ -958,7 +1072,7 @@ authorization from the authors.
<xsl:template match="typedef" mode="output"> <xsl:template match="typedef" mode="output">
<xsl:if test="$h"> <xsl:if test="$h">
<xsl:text>typedef </xsl:text> <xsl:text>typedef </xsl:text>
<xsl:value-of select="@oldname" /> <xsl:value-of select="xcb:get-char-void(@oldname)" />
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:value-of select="@newname" /> <xsl:value-of select="@newname" />
<xsl:text>; <xsl:text>;
@ -1159,7 +1273,7 @@ authorization from the authors.
<xsl:variable name="padnum"><xsl:number /></xsl:variable> <xsl:variable name="padnum"><xsl:number /></xsl:variable>
<xsl:call-template name="type-and-name"> <xsl:call-template name="type-and-name">
<xsl:with-param name="type" select="'CARD8'" /> <xsl:with-param name="type" select="'uint8_t'" />
<xsl:with-param name="name"> <xsl:with-param name="name">
<xsl:text>pad</xsl:text> <xsl:text>pad</xsl:text>
<xsl:value-of select="$padnum - 1" /> <xsl:value-of select="$padnum - 1" />

146
src/xcb.h
View File

@ -37,14 +37,14 @@
/* FIXME: these names conflict with those defined in Xmd.h. */ /* FIXME: these names conflict with those defined in Xmd.h. */
#ifndef XMD_H #ifndef XMD_H
typedef uint8_t BYTE; typedef uint8_t uint8_t;
typedef uint8_t BOOL; typedef uint8_t uint8_t;
typedef uint8_t CARD8; typedef uint8_t uint8_t;
typedef uint16_t CARD16; typedef uint16_t uint16_t;
typedef uint32_t CARD32; typedef uint32_t uint32_t;
typedef int8_t INT8; typedef int8_t int8_t;
typedef int16_t INT16; typedef int16_t int16_t;
typedef int32_t INT32; typedef int32_t int32_t;
#endif /* XMD_H */ #endif /* XMD_H */
#include <sys/uio.h> #include <sys/uio.h>
@ -60,7 +60,7 @@ extern "C" {
*/ */
/** /**
* @defgroup XCB_Core_Api XCB Core API * @defgroup xcb__core_api_t XCB Core API
* @brief Core API of the XCB library. * @brief Core API of the XCB library.
* *
* @{ * @{
@ -86,7 +86,7 @@ extern "C" {
* *
* A structure that contain all data that XCB needs to communicate with an X server. * A structure that contain all data that XCB needs to communicate with an X server.
*/ */
typedef struct XCBConnection XCBConnection; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */ typedef struct xcb_connection_t xcb_connection_t; /**< Opaque structure containing all data that XCB needs to communicate with an X server. */
/* Other types */ /* Other types */
@ -100,7 +100,7 @@ typedef struct {
void *data; /**< Data of the current iterator */ void *data; /**< Data of the current iterator */
int rem; /**< remaining elements */ int rem; /**< remaining elements */
int index; /**< index of the current iterator */ int index; /**< index of the current iterator */
} XCBGenericIter; } xcb_generic_iterator_t;
/** /**
* @brief Generic reply. * @brief Generic reply.
@ -108,11 +108,11 @@ typedef struct {
* A generic reply structure. * A generic reply structure.
*/ */
typedef struct { typedef struct {
BYTE response_type; /**< Type of the response */ uint8_t response_type; /**< Type of the response */
CARD8 pad0; /**< Padding */ uint8_t pad0; /**< Padding */
CARD16 sequence; /**< Sequence number */ uint16_t sequence; /**< Sequence number */
CARD32 length; /**< Length of the response */ uint32_t length; /**< Length of the response */
} XCBGenericRep; } xcb_generic_reply_t;
/** /**
* @brief Generic event. * @brief Generic event.
@ -120,12 +120,12 @@ typedef struct {
* A generic event structure. * A generic event structure.
*/ */
typedef struct { typedef struct {
BYTE response_type; /**< Type of the response */ uint8_t response_type; /**< Type of the response */
CARD8 pad0; /**< Padding */ uint8_t pad0; /**< Padding */
CARD16 sequence; /**< Sequence number */ uint16_t sequence; /**< Sequence number */
CARD32 pad[7]; /**< Padding */ uint32_t pad[7]; /**< Padding */
CARD32 full_sequence; uint32_t full_sequence;
} XCBGenericEvent; } xcb_generic_event_t;
/** /**
* @brief Generic error. * @brief Generic error.
@ -133,12 +133,12 @@ typedef struct {
* A generic error structure. * A generic error structure.
*/ */
typedef struct { typedef struct {
BYTE response_type; /**< Type of the response */ uint8_t response_type; /**< Type of the response */
BYTE error_code; /**< Error code */ uint8_t error_code; /**< Error code */
CARD16 sequence; /**< Sequence number */ uint16_t sequence; /**< Sequence number */
CARD32 pad[7]; /**< Padding */ uint32_t pad[7]; /**< Padding */
CARD32 full_sequence; uint32_t full_sequence;
} XCBGenericError; } xcb_generic_error_t;
/** /**
* @brief Generic cookie. * @brief Generic cookie.
@ -147,24 +147,24 @@ typedef struct {
*/ */
typedef struct { typedef struct {
unsigned int sequence; /**< Sequence number */ unsigned int sequence; /**< Sequence number */
} XCBVoidCookie; } xcb_void_cookie_t;
/* Include the generated xproto header. */ /* Include the generated xproto header. */
#include "xproto.h" #include "xproto.h"
/** XCBNone is the universal null resource or null atom parameter value for many core X requests */ /** XCB_NONE is the universal null resource or null atom parameter value for many core X requests */
#define XCBNone 0L #define XCB_NONE 0L
/** XCBCopyFromParent can be used for many CreateWindow parameters */ /** XCB_COPY_FROM_PARENT can be used for many CreateWindow parameters */
#define XCBCopyFromParent 0L #define XCB_COPY_FROM_PARENT 0L
/** XCBCurrentTime can be used in most requests that take an XCBTIMESTAMP */ /** XCB_CURRENT_TIME can be used in most requests that take an xcb_timestamp_t */
#define XCBCurrentTime 0L #define XCB_CURRENT_TIME 0L
/** XCBNoSymbol fills in unused entries in XCBKEYSYM tables */ /** XCB_NO_SYMBOL fills in unused entries in xcb_keysym_t tables */
#define XCBNoSymbol 0L #define XCB_NO_SYMBOL 0L
/* xcb_auth.c */ /* xcb_auth.c */
@ -174,12 +174,12 @@ typedef struct {
* *
* A container for authorization information to be sent to the X server. * A container for authorization information to be sent to the X server.
*/ */
typedef struct XCBAuthInfo { typedef struct xcb_auth_info_t {
int namelen; /**< Length of the string name (as returned by strlen). */ int namelen; /**< Length of the string name (as returned by strlen). */
char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */ char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
int datalen; /**< Length of the data member. */ int datalen; /**< Length of the data member. */
char *data; /**< Data interpreted in a protocol-specific manner. */ char *data; /**< Data interpreted in a protocol-specific manner. */
} XCBAuthInfo; } xcb_auth_info_t;
/* xcb_out.c */ /* xcb_out.c */
@ -192,7 +192,7 @@ typedef struct XCBAuthInfo {
* Forces any buffered output to be written to the server. Blocks * Forces any buffered output to be written to the server. Blocks
* until the write is complete. * until the write is complete.
*/ */
int XCBFlush(XCBConnection *c); int xcb_flush(xcb_connection_t *c);
/** /**
* @brief Returns the maximum request length field from the connection * @brief Returns the maximum request length field from the connection
@ -210,7 +210,7 @@ int XCBFlush(XCBConnection *c);
* theoretical maximum lengths roughly 256kB without BIG-REQUESTS and * theoretical maximum lengths roughly 256kB without BIG-REQUESTS and
* 16GB with. * 16GB with.
*/ */
CARD32 XCBGetMaximumRequestLength(XCBConnection *c); uint32_t xcb_get_maximum_request_length(xcb_connection_t *c);
/* xcb_in.c */ /* xcb_in.c */
@ -224,7 +224,7 @@ CARD32 XCBGetMaximumRequestLength(XCBConnection *c);
* the event of an I/O error. Blocks until either an event or error * the event of an I/O error. Blocks until either an event or error
* arrive, or an I/O error occurs. * arrive, or an I/O error occurs.
*/ */
XCBGenericEvent *XCBWaitForEvent(XCBConnection *c); xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
/** /**
* @brief Returns the next event or error from the server. * @brief Returns the next event or error from the server.
@ -241,7 +241,7 @@ XCBGenericEvent *XCBWaitForEvent(XCBConnection *c);
* operation. If @p error is @c NULL, terminates the application when an * operation. If @p error is @c NULL, terminates the application when an
* I/O error occurs. * I/O error occurs.
*/ */
XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error); xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error);
/** /**
* @brief Return the error for a request, or NULL if none can ever arrive. * @brief Return the error for a request, or NULL if none can ever arrive.
@ -249,7 +249,7 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
* @param cookie: The request cookie. * @param cookie: The request cookie.
* @return The error for the request, or NULL if none can ever arrive. * @return The error for the request, or NULL if none can ever arrive.
* *
* The XCBVoidCookie cookie supplied to this function must have resulted from * The xcb_void_cookie_t cookie supplied to this function must have resulted from
* a call to XCB[RequestName]Checked(). This function will block until one of * a call to XCB[RequestName]Checked(). This function will block until one of
* two conditions happens. If an error is received, it will be returned. If * two conditions happens. If an error is received, it will be returned. If
* a reply to a subsequent request has already arrived, no error can arrive * a reply to a subsequent request has already arrived, no error can arrive
@ -259,33 +259,33 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
* sequence number will advance beyond that provided in cookie; this is a * sequence number will advance beyond that provided in cookie; this is a
* convenience to avoid races in determining whether the sync is needed. * convenience to avoid races in determining whether the sync is needed.
*/ */
XCBGenericError *XCBRequestCheck(XCBConnection *c, XCBVoidCookie cookie); xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie);
/* xcb_ext.c */ /* xcb_ext.c */
/** /**
* @typedef typedef struct XCBExtension XCBExtension * @typedef typedef struct xcb_extension_t xcb_extension_t
*/ */
typedef struct XCBExtension XCBExtension; /**< Opaque structure used as key for XCBGetExtensionData. */ typedef struct xcb_extension_t xcb_extension_t; /**< Opaque structure used as key for xcb_get_extension_data_t. */
/** /**
* @brief Caches reply information from QueryExtension requests. * @brief Caches reply information from QueryExtension requests.
* @param c: The connection. * @param c: The connection.
* @param ext: The extension data. * @param ext: The extension data.
* @return A pointer to the XCBQueryExtensionRep for the extension. * @return A pointer to the xcb_query_extension_reply_t for the extension.
* *
* This function is the primary interface to the "extension cache", * This function is the primary interface to the "extension cache",
* which caches reply information from QueryExtension * which caches reply information from QueryExtension
* requests. Invoking this function may cause a call to * requests. Invoking this function may cause a call to
* XCBQueryExtension to retrieve extension information from the * xcb_query_extension_t to retrieve extension information from the
* server, and may block until extension data is received from the * server, and may block until extension data is received from the
* server. * server.
* *
* The result must not be freed. This storage is managed by the cache * The result must not be freed. This storage is managed by the cache
* itself. * itself.
*/ */
const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext); const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
/** /**
* @brief Prefetch of extension data into the extension cache * @brief Prefetch of extension data into the extension cache
@ -294,11 +294,11 @@ const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *
* *
* This function allows a "prefetch" of extension data into the * This function allows a "prefetch" of extension data into the
* extension cache. Invoking the function may cause a call to * extension cache. Invoking the function may cause a call to
* XCBQueryExtension, but will not block waiting for the * xcb_query_extension_t, but will not block waiting for the
* reply. XCBGetExtensionData will return the prefetched data after * reply. xcb_get_extension_data_t will return the prefetched data after
* possibly blocking while it is retrieved. * possibly blocking while it is retrieved.
*/ */
void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext); void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext);
/* xcb_conn.c */ /* xcb_conn.c */
@ -306,9 +306,9 @@ void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
/** /**
* @brief Access the data returned by the server. * @brief Access the data returned by the server.
* @param c: The connection. * @param c: The connection.
* @return A pointer to an XCBSetup structure. * @return A pointer to an xcb_setup_t structure.
* *
* Accessor for the data returned by the server when the XCBConnection * Accessor for the data returned by the server when the xcb_connection_t
* was initialized. This data includes * was initialized. This data includes
* - the server's required format for images, * - the server's required format for images,
* - a list of available visuals, * - a list of available visuals,
@ -321,7 +321,7 @@ void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext);
* *
* The result must not be freed. * The result must not be freed.
*/ */
const XCBSetup *XCBGetSetup(XCBConnection *c); const xcb_setup_t *xcb_get_setup(xcb_connection_t *c);
/** /**
* @brief Access the file descriptor of the connection. * @brief Access the file descriptor of the connection.
@ -329,39 +329,39 @@ const XCBSetup *XCBGetSetup(XCBConnection *c);
* @return The file descriptor. * @return The file descriptor.
* *
* Accessor for the file descriptor that was passed to the * Accessor for the file descriptor that was passed to the
* XCBConnectToFD call that returned @p c. * xcb_connect_to_fd_t call that returned @p c.
*/ */
int XCBGetFileDescriptor(XCBConnection *c); int xcb_get_file_descriptor(xcb_connection_t *c);
/** /**
* @brief Test whether the connection has shut down due to a fatal error. * @brief Test whether the connection has shut down due to a fatal error.
* @param c: The connection. * @param c: The connection.
* @return 1 if the connection is in an error state; 0 otherwise. * @return 1 if the connection is in an error state; 0 otherwise.
* *
* Some errors that occur in the context of an XCBConnection * Some errors that occur in the context of an xcb_connection_t
* are unrecoverable. When such an error occurs, the * are unrecoverable. When such an error occurs, the
* connection is shut down and further operations on the * connection is shut down and further operations on the
* XCBConnection have no effect. * xcb_connection_t have no effect.
* *
* @todo Other functions should document the conditions in * @todo Other functions should document the conditions in
* which they shut down the connection. * which they shut down the connection.
*/ */
int XCBConnectionHasError(XCBConnection *c); int xcb_connection_has_error(xcb_connection_t *c);
/** /**
* @brief Connects to the X server. * @brief Connects to the X server.
* @param fd: The file descriptor. * @param fd: The file descriptor.
* @param auth_info: Authentication data. * @param auth_info: Authentication data.
* @return A newly allocated XCBConnection structure. * @return A newly allocated xcb_connection_t structure.
* *
* Connects to an X server, given the open socket @p fd and the * Connects to an X server, given the open socket @p fd and the
* XCBAuthInfo @p auth_info. The file descriptor @p fd is * xcb_auth_info_t @p auth_info. The file descriptor @p fd is
* bidirectionally connected to an X server. XCBGetTCPFD and * bidirectionally connected to an X server. xcb_get_tcpfd_t and
* XCBGetUnixFD return appropriate file descriptors. If the connection * xcb_get_unix_fd_t return appropriate file descriptors. If the connection
* should be unauthenticated, @p auth_info must be @c * should be unauthenticated, @p auth_info must be @c
* NULL. XCBGetAuthInfo returns appropriate authentication data. * NULL. xcb_get_auth_info_t returns appropriate authentication data.
*/ */
XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info); xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info);
/** /**
* @brief Closes the connection. * @brief Closes the connection.
@ -370,7 +370,7 @@ XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info);
* Closes the file descriptor and frees all memory associated with the * Closes the file descriptor and frees all memory associated with the
* connection @c c. * connection @c c.
*/ */
void XCBDisconnect(XCBConnection *c); void xcb_disconnect(xcb_connection_t *c);
/* xcb_util.c */ /* xcb_util.c */
@ -392,13 +392,13 @@ void XCBDisconnect(XCBConnection *c);
* can be @c NULL. If @p displayname does not contain a screen number, * can be @c NULL. If @p displayname does not contain a screen number,
* it is set to @c 0. * it is set to @c 0.
*/ */
int XCBParseDisplay(const char *name, char **host, int *display, int *screen); int xcb_parse_display(const char *name, char **host, int *display, int *screen);
/** /**
* @brief Connects to the X server. * @brief Connects to the X server.
* @param displayname: The name of the display. * @param displayname: The name of the display.
* @param screenp: A pointer to a preferred screen number. * @param screenp: A pointer to a preferred screen number.
* @return A newly allocated XCBConnection structure. * @return A newly allocated xcb_connection_t structure.
* *
* Connects to the X server specified by @p displayname. If @p * Connects to the X server specified by @p displayname. If @p
* displayname is @c NULL, uses the value of the DISPLAY environment * displayname is @c NULL, uses the value of the DISPLAY environment
@ -406,21 +406,21 @@ int XCBParseDisplay(const char *name, char **host, int *display, int *screen);
* int pointed to by @p screenp (if not @c NULL) will be set to that * int pointed to by @p screenp (if not @c NULL) will be set to that
* screen; otherwise the screen will be set to 0. * screen; otherwise the screen will be set to 0.
*/ */
XCBConnection *XCBConnect(const char *displayname, int *screenp); xcb_connection_t *xcb_connect(const char *displayname, int *screenp);
/** /**
* @brief Connects to the X server, using an authorization information. * @brief Connects to the X server, using an authorization information.
* @param displayname: The name of the display. * @param displayname: The name of the display.
* @param auth: The authorization information. * @param auth: The authorization information.
* @param screenp: A pointer to a preferred screen number. * @param screenp: A pointer to a preferred screen number.
* @return A newly allocated XCBConnection structure. * @return A newly allocated xcb_connection_t structure.
* *
* Connects to the X server specified by @p displayname, using the * Connects to the X server specified by @p displayname, using the
* authorization @p auth. If a particular screen on that server is * authorization @p auth. If a particular screen on that server is
* preferred, the int pointed to by @p screenp (if not @c NULL) will * preferred, the int pointed to by @p screenp (if not @c NULL) will
* be set to that screen; otherwise @p screenp will be set to 0. * be set to that screen; otherwise @p screenp will be set to 0.
*/ */
XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *display, XCBAuthInfo *auth, int *screen); xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *display, xcb_auth_info_t *auth, int *screen);
/** /**

View File

@ -105,7 +105,7 @@ static Xauth *get_authptr(struct sockaddr *sockname, unsigned int socknamelen)
addr = (char *) &si->sin_addr; addr = (char *) &si->sin_addr;
addrlen = 4; addrlen = 4;
if (ntohl(si->sin_addr.s_addr) != 0x7f000001) if (ntohl(si->sin_addr.s_addr) != 0x7f000001)
family = XCBFamilyInternet; family = XCB_FAMILY_INTERNET;
snprintf(dispbuf, sizeof(dispbuf), "%d", ntohs(si->sin_port) - X_TCP_PORT); snprintf(dispbuf, sizeof(dispbuf), "%d", ntohs(si->sin_port) - X_TCP_PORT);
display = dispbuf; display = dispbuf;
} }
@ -158,7 +158,7 @@ static void do_append(char *buf, int *idxp, void *val, size_t valsize) {
} }
#endif #endif
static int compute_auth(XCBAuthInfo *info, Xauth *authptr, struct sockaddr *sockname) static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr *sockname)
{ {
if (authname_match(AUTH_MC1, authptr->name, authptr->name_length)) { if (authname_match(AUTH_MC1, authptr->name, authptr->name_length)) {
info->datalen = memdup(&info->data, authptr->data, authptr->data_length); info->datalen = memdup(&info->data, authptr->data, authptr->data_length);
@ -216,7 +216,7 @@ static int compute_auth(XCBAuthInfo *info, Xauth *authptr, struct sockaddr *sock
return 0; /* Unknown authorization type */ return 0; /* Unknown authorization type */
} }
int _xcb_get_auth_info(int fd, XCBAuthInfo *info) int _xcb_get_auth_info(int fd, xcb_auth_info_t *info)
{ {
/* code adapted from Xlib/ConnDis.c, xtrans/Xtranssocket.c, /* code adapted from Xlib/ConnDis.c, xtrans/Xtranssocket.c,
xtrans/Xtransutils.c */ xtrans/Xtransutils.c */

View File

@ -39,10 +39,10 @@
#include "xcbint.h" #include "xcbint.h"
typedef struct { typedef struct {
CARD8 status; uint8_t status;
CARD8 pad0[5]; uint8_t pad0[5];
CARD16 length; uint16_t length;
} XCBSetupGeneric; } xcb_setup_generic_t;
static const int error_connection = 1; static const int error_connection = 1;
@ -59,10 +59,10 @@ static int set_fd_flags(const int fd)
return 1; return 1;
} }
static int write_setup(XCBConnection *c, XCBAuthInfo *auth_info) static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
{ {
static const char pad[3]; static const char pad[3];
XCBSetupRequest out; xcb_setup_request_t out;
struct iovec parts[6]; struct iovec parts[6];
int count = 0; int count = 0;
int endian = 0x01020304; int endian = 0x01020304;
@ -79,9 +79,9 @@ static int write_setup(XCBConnection *c, XCBAuthInfo *auth_info)
out.protocol_minor_version = X_PROTOCOL_REVISION; out.protocol_minor_version = X_PROTOCOL_REVISION;
out.authorization_protocol_name_len = 0; out.authorization_protocol_name_len = 0;
out.authorization_protocol_data_len = 0; out.authorization_protocol_data_len = 0;
parts[count].iov_len = sizeof(XCBSetupRequest); parts[count].iov_len = sizeof(xcb_setup_request_t);
parts[count++].iov_base = &out; parts[count++].iov_base = &out;
parts[count].iov_len = XCB_PAD(sizeof(XCBSetupRequest)); parts[count].iov_len = XCB_PAD(sizeof(xcb_setup_request_t));
parts[count++].iov_base = (char *) pad; parts[count++].iov_base = (char *) pad;
if(auth_info) if(auth_info)
@ -106,24 +106,24 @@ static int write_setup(XCBConnection *c, XCBAuthInfo *auth_info)
return ret; return ret;
} }
static int read_setup(XCBConnection *c) static int read_setup(xcb_connection_t *c)
{ {
/* Read the server response */ /* Read the server response */
c->setup = malloc(sizeof(XCBSetupGeneric)); c->setup = malloc(sizeof(xcb_setup_generic_t));
if(!c->setup) if(!c->setup)
return 0; return 0;
if(_xcb_in_read_block(c, c->setup, sizeof(XCBSetupGeneric)) != sizeof(XCBSetupGeneric)) if(_xcb_in_read_block(c, c->setup, sizeof(xcb_setup_generic_t)) != sizeof(xcb_setup_generic_t))
return 0; return 0;
{ {
void *tmp = realloc(c->setup, c->setup->length * 4 + sizeof(XCBSetupGeneric)); void *tmp = realloc(c->setup, c->setup->length * 4 + sizeof(xcb_setup_generic_t));
if(!tmp) if(!tmp)
return 0; return 0;
c->setup = tmp; c->setup = tmp;
} }
if(_xcb_in_read_block(c, (char *) c->setup + sizeof(XCBSetupGeneric), c->setup->length * 4) <= 0) if(_xcb_in_read_block(c, (char *) c->setup + sizeof(xcb_setup_generic_t), c->setup->length * 4) <= 0)
return 0; return 0;
/* 0 = failed, 2 = authenticate, 1 = success */ /* 0 = failed, 2 = authenticate, 1 = success */
@ -131,15 +131,15 @@ static int read_setup(XCBConnection *c)
{ {
case 0: /* failed */ case 0: /* failed */
{ {
XCBSetupFailed *setup = (XCBSetupFailed *) c->setup; xcb_setup_failed_t *setup = (xcb_setup_failed_t *) c->setup;
write(STDERR_FILENO, XCBSetupFailedReason(setup), XCBSetupFailedReasonLength(setup)); write(STDERR_FILENO, xcb_setup_failed_reason(setup), xcb_setup_failed_reason_length(setup));
return 0; return 0;
} }
case 2: /* authenticate */ case 2: /* authenticate */
{ {
XCBSetupAuthenticate *setup = (XCBSetupAuthenticate *) c->setup; xcb_setup_authenticate_t *setup = (xcb_setup_authenticate_t *) c->setup;
write(STDERR_FILENO, XCBSetupAuthenticateReason(setup), XCBSetupAuthenticateReasonLength(setup)); write(STDERR_FILENO, xcb_setup_authenticate_reason(setup), xcb_setup_authenticate_reason_length(setup));
return 0; return 0;
} }
} }
@ -148,7 +148,7 @@ static int read_setup(XCBConnection *c)
} }
/* precondition: there must be something for us to write. */ /* precondition: there must be something for us to write. */
static int write_vec(XCBConnection *c, struct iovec **vector, int *count) static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
{ {
int n; int n;
assert(!c->out.queue_len); assert(!c->out.queue_len);
@ -180,7 +180,7 @@ static int write_vec(XCBConnection *c, struct iovec **vector, int *count)
/* Public interface */ /* Public interface */
const XCBSetup *XCBGetSetup(XCBConnection *c) const xcb_setup_t *xcb_get_setup(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return 0; return 0;
@ -188,7 +188,7 @@ const XCBSetup *XCBGetSetup(XCBConnection *c)
return c->setup; return c->setup;
} }
int XCBGetFileDescriptor(XCBConnection *c) int xcb_get_file_descriptor(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return -1; return -1;
@ -196,19 +196,19 @@ int XCBGetFileDescriptor(XCBConnection *c)
return c->fd; return c->fd;
} }
int XCBConnectionHasError(XCBConnection *c) int xcb_connection_has_error(xcb_connection_t *c)
{ {
/* doesn't need locking because it's read and written atomically. */ /* doesn't need locking because it's read and written atomically. */
return c->has_error; return c->has_error;
} }
XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info) xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
{ {
XCBConnection* c; xcb_connection_t* c;
c = calloc(1, sizeof(XCBConnection)); c = calloc(1, sizeof(xcb_connection_t));
if(!c) if(!c)
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
c->fd = fd; c->fd = fd;
@ -223,14 +223,14 @@ XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info)
_xcb_xid_init(c) _xcb_xid_init(c)
)) ))
{ {
XCBDisconnect(c); xcb_disconnect(c);
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
} }
return c; return c;
} }
void XCBDisconnect(XCBConnection *c) void xcb_disconnect(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return; return;
@ -250,12 +250,12 @@ void XCBDisconnect(XCBConnection *c)
/* Private interface */ /* Private interface */
void _xcb_conn_shutdown(XCBConnection *c) void _xcb_conn_shutdown(xcb_connection_t *c)
{ {
c->has_error = 1; c->has_error = 1;
} }
int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector, int *count) int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
{ {
int ret; int ret;
fd_set rfds, wfds; fd_set rfds, wfds;

View File

@ -35,12 +35,12 @@
typedef struct lazyreply { typedef struct lazyreply {
enum { LAZY_NONE = 0, LAZY_COOKIE, LAZY_FORCED } tag; enum { LAZY_NONE = 0, LAZY_COOKIE, LAZY_FORCED } tag;
union { union {
XCBQueryExtensionCookie cookie; xcb_query_extension_cookie_t cookie;
XCBQueryExtensionRep *reply; xcb_query_extension_reply_t *reply;
} value; } value;
} lazyreply; } lazyreply;
static lazyreply *get_index(XCBConnection *c, int index) static lazyreply *get_index(xcb_connection_t *c, int index)
{ {
if(index > c->ext.extensions_size) if(index > c->ext.extensions_size)
{ {
@ -55,7 +55,7 @@ static lazyreply *get_index(XCBConnection *c, int index)
return c->ext.extensions + index - 1; return c->ext.extensions + index - 1;
} }
static lazyreply *get_lazyreply(XCBConnection *c, XCBExtension *ext) static lazyreply *get_lazyreply(xcb_connection_t *c, xcb_extension_t *ext)
{ {
static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
static int next_global_id; static int next_global_id;
@ -72,16 +72,16 @@ static lazyreply *get_lazyreply(XCBConnection *c, XCBExtension *ext)
{ {
/* cache miss: query the server */ /* cache miss: query the server */
data->tag = LAZY_COOKIE; data->tag = LAZY_COOKIE;
data->value.cookie = XCBQueryExtension(c, strlen(ext->name), ext->name); data->value.cookie = xcb_query_extension(c, strlen(ext->name), ext->name);
} }
return data; return data;
} }
/* Public interface */ /* Public interface */
/* Do not free the returned XCBQueryExtensionRep - on return, it's aliased /* Do not free the returned xcb_query_extension_reply_t - on return, it's aliased
* from the cache. */ * from the cache. */
const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext) const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
{ {
lazyreply *data; lazyreply *data;
if(c->has_error) if(c->has_error)
@ -92,14 +92,14 @@ const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *
if(data && data->tag == LAZY_COOKIE) if(data && data->tag == LAZY_COOKIE)
{ {
data->tag = LAZY_FORCED; data->tag = LAZY_FORCED;
data->value.reply = XCBQueryExtensionReply(c, data->value.cookie, 0); data->value.reply = xcb_query_extension_reply(c, data->value.cookie, 0);
} }
pthread_mutex_unlock(&c->ext.lock); pthread_mutex_unlock(&c->ext.lock);
return data ? data->value.reply : 0; return data ? data->value.reply : 0;
} }
void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext) void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
{ {
if(c->has_error) if(c->has_error)
return; return;
@ -110,14 +110,14 @@ void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext)
/* Private interface */ /* Private interface */
int _xcb_ext_init(XCBConnection *c) int _xcb_ext_init(xcb_connection_t *c)
{ {
if(pthread_mutex_init(&c->ext.lock, 0)) if(pthread_mutex_init(&c->ext.lock, 0))
return 0; return 0;
return 1; return 1;
} }
void _xcb_ext_destroy(XCBConnection *c) void _xcb_ext_destroy(xcb_connection_t *c)
{ {
pthread_mutex_destroy(&c->ext.lock); pthread_mutex_destroy(&c->ext.lock);
while(c->ext.extensions_size-- > 0) while(c->ext.extensions_size-- > 0)

View File

@ -37,11 +37,11 @@
#include "xcbext.h" #include "xcbext.h"
#include "xcbint.h" #include "xcbint.h"
#define XCBError 0 #define XCB_ERROR 0
#define XCBReply 1 #define XCB_REPLY 1
struct event_list { struct event_list {
XCBGenericEvent *event; xcb_generic_event_t *event;
struct event_list *next; struct event_list *next;
}; };
@ -63,7 +63,7 @@ typedef struct reader_list {
struct reader_list *next; struct reader_list *next;
} reader_list; } reader_list;
static void wake_up_next_reader(XCBConnection *c) static void wake_up_next_reader(xcb_connection_t *c)
{ {
int pthreadret; int pthreadret;
if(c->in.readers) if(c->in.readers)
@ -73,9 +73,9 @@ static void wake_up_next_reader(XCBConnection *c)
assert(pthreadret == 0); assert(pthreadret == 0);
} }
static int read_packet(XCBConnection *c) static int read_packet(xcb_connection_t *c)
{ {
XCBGenericRep genrep; xcb_generic_reply_t genrep;
int length = 32; int length = 32;
void *buf; void *buf;
pending_reply *pend = 0; pending_reply *pend = 0;
@ -89,7 +89,7 @@ static int read_packet(XCBConnection *c)
memcpy(&genrep, c->in.queue, sizeof(genrep)); memcpy(&genrep, c->in.queue, sizeof(genrep));
/* Compute 32-bit sequence number of this packet. */ /* Compute 32-bit sequence number of this packet. */
if((genrep.response_type & 0x7f) != XCBKeymapNotify) if((genrep.response_type & 0x7f) != XCB_KEYMAP_NOTIFY)
{ {
unsigned int lastread = c->in.request_read; unsigned int lastread = c->in.request_read;
c->in.request_read = (lastread & 0xffff0000) | genrep.sequence; c->in.request_read = (lastread & 0xffff0000) | genrep.sequence;
@ -108,7 +108,7 @@ static int read_packet(XCBConnection *c)
} }
c->in.request_completed = c->in.request_read - 1; c->in.request_completed = c->in.request_read - 1;
} }
if(genrep.response_type == XCBError) if(genrep.response_type == XCB_ERROR)
c->in.request_completed = c->in.request_read; c->in.request_completed = c->in.request_read;
while(c->in.pending_replies && while(c->in.pending_replies &&
@ -122,7 +122,7 @@ static int read_packet(XCBConnection *c)
} }
} }
if(genrep.response_type == XCBError || genrep.response_type == XCBReply) if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
{ {
pend = c->in.pending_replies; pend = c->in.pending_replies;
if(pend && pend->request != c->in.request_read) if(pend && pend->request != c->in.request_read)
@ -130,17 +130,17 @@ static int read_packet(XCBConnection *c)
} }
/* For reply packets, check that the entire packet is available. */ /* For reply packets, check that the entire packet is available. */
if(genrep.response_type == XCBReply) if(genrep.response_type == XCB_REPLY)
{ {
if(pend && pend->workaround == WORKAROUND_GLX_GET_FB_CONFIGS_BUG) if(pend && pend->workaround == WORKAROUND_GLX_GET_FB_CONFIGS_BUG)
{ {
CARD32 *p = (CARD32 *) c->in.queue; uint32_t *p = (uint32_t *) c->in.queue;
genrep.length = p[2] * p[3] * 2; genrep.length = p[2] * p[3] * 2;
} }
length += genrep.length * 4; length += genrep.length * 4;
} }
buf = malloc(length + (genrep.response_type == XCBReply ? 0 : sizeof(CARD32))); buf = malloc(length + (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)));
if(!buf) if(!buf)
{ {
_xcb_conn_shutdown(c); _xcb_conn_shutdown(c);
@ -157,12 +157,12 @@ static int read_packet(XCBConnection *c)
return 1; return 1;
} }
if(genrep.response_type != XCBReply) if(genrep.response_type != XCB_REPLY)
((XCBGenericEvent *) buf)->full_sequence = c->in.request_read; ((xcb_generic_event_t *) buf)->full_sequence = c->in.request_read;
/* reply, or checked error */ /* reply, or checked error */
if( genrep.response_type == XCBReply || if( genrep.response_type == XCB_REPLY ||
(genrep.response_type == XCBError && pend && (pend->flags & XCB_REQUEST_CHECKED))) (genrep.response_type == XCB_ERROR && pend && (pend->flags & XCB_REQUEST_CHECKED)))
{ {
reader_list *reader; reader_list *reader;
struct reply_list *cur = malloc(sizeof(struct reply_list)); struct reply_list *cur = malloc(sizeof(struct reply_list));
@ -205,10 +205,10 @@ static int read_packet(XCBConnection *c)
return 1; /* I have something for you... */ return 1; /* I have something for you... */
} }
static XCBGenericEvent *get_event(XCBConnection *c) static xcb_generic_event_t *get_event(xcb_connection_t *c)
{ {
struct event_list *cur = c->in.events; struct event_list *cur = c->in.events;
XCBGenericEvent *ret; xcb_generic_event_t *ret;
if(!c->in.events) if(!c->in.events)
return 0; return 0;
ret = cur->event; ret = cur->event;
@ -253,7 +253,7 @@ static int read_block(const int fd, void *buf, const size_t len)
return len; return len;
} }
static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error) static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
{ {
struct reply_list *head; struct reply_list *head;
@ -292,7 +292,7 @@ static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply,
if(head) if(head)
{ {
if(((XCBGenericRep *) head->reply)->response_type == XCBError) if(((xcb_generic_reply_t *) head->reply)->response_type == XCB_ERROR)
{ {
if(error) if(error)
*error = head->reply; *error = head->reply;
@ -310,7 +310,7 @@ static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply,
/* Public interface */ /* Public interface */
void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e) void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e)
{ {
void *ret = 0; void *ret = 0;
if(e) if(e)
@ -362,7 +362,7 @@ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **
return ret; return ret;
} }
int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error) int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
{ {
int ret; int ret;
if(c->has_error) if(c->has_error)
@ -379,9 +379,9 @@ int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGen
return ret; return ret;
} }
XCBGenericEvent *XCBWaitForEvent(XCBConnection *c) xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
{ {
XCBGenericEvent *ret; xcb_generic_event_t *ret;
if(c->has_error) if(c->has_error)
return 0; return 0;
pthread_mutex_lock(&c->iolock); pthread_mutex_lock(&c->iolock);
@ -395,11 +395,11 @@ XCBGenericEvent *XCBWaitForEvent(XCBConnection *c)
return ret; return ret;
} }
XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error) xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error)
{ {
if(!c->has_error) if(!c->has_error)
{ {
XCBGenericEvent *ret = 0; xcb_generic_event_t *ret = 0;
int success; int success;
pthread_mutex_lock(&c->iolock); pthread_mutex_lock(&c->iolock);
/* FIXME: follow X meets Z architecture changes. */ /* FIXME: follow X meets Z architecture changes. */
@ -418,28 +418,28 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error)
*error = -1; *error = -1;
else else
{ {
fprintf(stderr, "XCBPollForEvent: I/O error occured, but no handler provided.\n"); fprintf(stderr, "xcb_poll_for_event_t: I/O error occured, but no handler provided.\n");
abort(); abort();
} }
return 0; return 0;
} }
XCBGenericError *XCBRequestCheck(XCBConnection *c, XCBVoidCookie cookie) xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
{ {
/* FIXME: this could hold the lock to avoid syncing unnecessarily, but /* FIXME: this could hold the lock to avoid syncing unnecessarily, but
* that would require factoring the locking out of XCBGetInputFocus, * that would require factoring the locking out of xcb_get_input_focus_t,
* XCBGetInputFocusReply, and XCBWaitForReply. */ * xcb_get_input_focus_reply_t, and xcb_wait_for_reply_t. */
XCBGenericError *ret; xcb_generic_error_t *ret;
void *reply; void *reply;
if(c->has_error) if(c->has_error)
return 0; return 0;
if(XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_expected) if(XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_expected)
&& XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_completed)) && XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_completed))
{ {
free(XCBGetInputFocusReply(c, XCBGetInputFocus(c), &ret)); free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), &ret));
assert(!ret); assert(!ret);
} }
reply = XCBWaitForReply(c, cookie.sequence, &ret); reply = xcb_wait_for_reply(c, cookie.sequence, &ret);
assert(!reply); assert(!reply);
return ret; return ret;
} }
@ -488,7 +488,7 @@ void _xcb_in_destroy(_xcb_in *in)
} }
} }
int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workarounds workaround, int flags) int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags)
{ {
pending_reply *pend = malloc(sizeof(pending_reply)); pending_reply *pend = malloc(sizeof(pending_reply));
assert(workaround != WORKAROUND_NONE || flags != 0); assert(workaround != WORKAROUND_NONE || flags != 0);
@ -506,7 +506,7 @@ int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workaround
return 1; return 1;
} }
int _xcb_in_read(XCBConnection *c) int _xcb_in_read(xcb_connection_t *c)
{ {
int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len); int n = read(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len);
if(n > 0) if(n > 0)
@ -519,7 +519,7 @@ int _xcb_in_read(XCBConnection *c)
return 0; return 0;
} }
int _xcb_in_read_block(XCBConnection *c, void *buf, int len) int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len)
{ {
int done = c->in.queue_len; int done = c->in.queue_len;
if(len < done) if(len < done)

View File

@ -54,7 +54,7 @@ _xcb_map *_xcb_map_new()
return list; return list;
} }
void _xcb_map_delete(_xcb_map *list, XCBListFreeFunc do_free) void _xcb_map_delete(_xcb_map *list, xcb_list_free_func_t do_free)
{ {
if(!list) if(!list)
return; return;

View File

@ -35,7 +35,7 @@
#include "xcbint.h" #include "xcbint.h"
#include "extensions/bigreq.h" #include "extensions/bigreq.h"
static int write_block(XCBConnection *c, struct iovec *vector, int count) static int write_block(xcb_connection_t *c, struct iovec *vector, int count)
{ {
while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue)) while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue))
{ {
@ -57,19 +57,19 @@ static int write_block(XCBConnection *c, struct iovec *vector, int count)
/* Public interface */ /* Public interface */
CARD32 XCBGetMaximumRequestLength(XCBConnection *c) uint32_t xcb_get_maximum_request_length(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return 0; return 0;
pthread_mutex_lock(&c->out.reqlenlock); pthread_mutex_lock(&c->out.reqlenlock);
if(!c->out.maximum_request_length) if(!c->out.maximum_request_length)
{ {
const XCBQueryExtensionRep *ext; const xcb_query_extension_reply_t *ext;
c->out.maximum_request_length = c->setup->maximum_request_length; c->out.maximum_request_length = c->setup->maximum_request_length;
ext = XCBGetExtensionData(c, &XCBBigRequestsId); ext = xcb_get_extension_data(c, &xcb_big_requests_id);
if(ext && ext->present) if(ext && ext->present)
{ {
XCBBigRequestsEnableRep *r = XCBBigRequestsEnableReply(c, XCBBigRequestsEnable(c), 0); xcb_big_requests_enable_reply_t *r = xcb_big_requests_enable_reply(c, xcb_big_requests_enable(c), 0);
c->out.maximum_request_length = r->maximum_request_length; c->out.maximum_request_length = r->maximum_request_length;
free(r); free(r);
} }
@ -78,18 +78,18 @@ CARD32 XCBGetMaximumRequestLength(XCBConnection *c)
return c->out.maximum_request_length; return c->out.maximum_request_length;
} }
unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, const XCBProtocolRequest *req) unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *req)
{ {
static const union { static const union {
struct { struct {
CARD8 major; uint8_t major;
CARD8 pad; uint8_t pad;
CARD16 len; uint16_t len;
} fields; } fields;
CARD32 packet; uint32_t packet;
} sync = { { /* GetInputFocus */ 43, 0, 1 } }; } sync = { { /* GetInputFocus */ 43, 0, 1 } };
unsigned int request; unsigned int request;
CARD32 prefix[3] = { 0 }; uint32_t prefix[3] = { 0 };
int veclen = req->count; int veclen = req->count;
enum workarounds workaround = WORKAROUND_NONE; enum workarounds workaround = WORKAROUND_NONE;
@ -104,23 +104,23 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
{ {
static const char pad[3]; static const char pad[3];
int i; int i;
CARD16 shortlen = 0; uint16_t shortlen = 0;
size_t longlen = 0; size_t longlen = 0;
assert(vector[0].iov_len >= 4); assert(vector[0].iov_len >= 4);
/* set the major opcode, and the minor opcode for extensions */ /* set the major opcode, and the minor opcode for extensions */
if(req->ext) if(req->ext)
{ {
const XCBQueryExtensionRep *extension = XCBGetExtensionData(c, req->ext); const xcb_query_extension_reply_t *extension = xcb_get_extension_data(c, req->ext);
if(!(extension && extension->present)) if(!(extension && extension->present))
{ {
_xcb_conn_shutdown(c); _xcb_conn_shutdown(c);
return 0; return 0;
} }
((CARD8 *) vector[0].iov_base)[0] = extension->major_opcode; ((uint8_t *) vector[0].iov_base)[0] = extension->major_opcode;
((CARD8 *) vector[0].iov_base)[1] = req->opcode; ((uint8_t *) vector[0].iov_base)[1] = req->opcode;
} }
else else
((CARD8 *) vector[0].iov_base)[0] = req->opcode; ((uint8_t *) vector[0].iov_base)[0] = req->opcode;
/* put together the length field, possibly using BIGREQUESTS */ /* put together the length field, possibly using BIGREQUESTS */
for(i = 0; i < req->count; ++i) for(i = 0; i < req->count; ++i)
@ -141,14 +141,14 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
shortlen = longlen; shortlen = longlen;
longlen = 0; longlen = 0;
} }
else if(longlen > XCBGetMaximumRequestLength(c)) else if(longlen > xcb_get_maximum_request_length(c))
{ {
_xcb_conn_shutdown(c); _xcb_conn_shutdown(c);
return 0; /* server can't take this; maybe need BIGREQUESTS? */ return 0; /* server can't take this; maybe need BIGREQUESTS? */
} }
/* set the length field. */ /* set the length field. */
((CARD16 *) vector[0].iov_base)[1] = shortlen; ((uint16_t *) vector[0].iov_base)[1] = shortlen;
if(!shortlen) if(!shortlen)
prefix[2] = ++longlen; prefix[2] = ++longlen;
} }
@ -158,7 +158,7 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
/* XXX: GetFBConfigs won't use BIG-REQUESTS in any sane /* XXX: GetFBConfigs won't use BIG-REQUESTS in any sane
* configuration, but that should be handled here anyway. */ * configuration, but that should be handled here anyway. */
if(req->ext && !req->isvoid && !strcmp(req->ext->name, "GLX") && if(req->ext && !req->isvoid && !strcmp(req->ext->name, "GLX") &&
((req->opcode == 17 && ((CARD32 *) vector[0].iov_base)[1] == 0x10004) || ((req->opcode == 17 && ((uint32_t *) vector[0].iov_base)[1] == 0x10004) ||
req->opcode == 21)) req->opcode == 21))
workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG; workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG;
@ -194,11 +194,11 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
--vector, ++veclen; --vector, ++veclen;
if(prefix[2]) if(prefix[2])
{ {
prefix[1] = ((CARD32 *) vector[1].iov_base)[0]; prefix[1] = ((uint32_t *) vector[1].iov_base)[0];
vector[1].iov_base = (CARD32 *) vector[1].iov_base + 1; vector[1].iov_base = (uint32_t *) vector[1].iov_base + 1;
vector[1].iov_len -= sizeof(CARD32); vector[1].iov_len -= sizeof(uint32_t);
} }
vector[0].iov_len = sizeof(CARD32) * (prefix[0] ? 1 : 0 | prefix[2] ? 2 : 0); vector[0].iov_len = sizeof(uint32_t) * (prefix[0] ? 1 : 0 | prefix[2] ? 2 : 0);
vector[0].iov_base = prefix + !prefix[0]; vector[0].iov_base = prefix + !prefix[0];
} }
@ -211,7 +211,7 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
return request; return request;
} }
int XCBFlush(XCBConnection *c) int xcb_flush(xcb_connection_t *c)
{ {
int ret; int ret;
if(c->has_error) if(c->has_error)
@ -248,7 +248,7 @@ void _xcb_out_destroy(_xcb_out *out)
pthread_mutex_destroy(&out->reqlenlock); pthread_mutex_destroy(&out->reqlenlock);
} }
int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count) int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count)
{ {
int ret = 1; int ret = 1;
while(ret && *count) while(ret && *count)
@ -258,7 +258,7 @@ int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count)
return ret; return ret;
} }
int _xcb_out_flush_to(XCBConnection *c, unsigned int request) int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request)
{ {
assert(XCB_SEQUENCE_COMPARE(request, <=, c->out.request)); assert(XCB_SEQUENCE_COMPARE(request, <=, c->out.request));
if(XCB_SEQUENCE_COMPARE(c->out.request_written, >=, request)) if(XCB_SEQUENCE_COMPARE(c->out.request_written, >=, request))

View File

@ -47,7 +47,7 @@
static const int error_connection = 1; static const int error_connection = 1;
int XCBPopcount(CARD32 mask) int xcb_popcount(uint32_t mask)
{ {
unsigned long y; unsigned long y;
y = (mask >> 1) & 033333333333; y = (mask >> 1) & 033333333333;
@ -55,7 +55,7 @@ int XCBPopcount(CARD32 mask)
return ((y + (y >> 3)) & 030707070707) % 077; return ((y + (y >> 3)) & 030707070707) % 077;
} }
int XCBParseDisplay(const char *name, char **host, int *displayp, int *screenp) int xcb_parse_display(const char *name, char **host, int *displayp, int *screenp)
{ {
int len, display, screen; int len, display, screen;
char *colon, *dot, *end; char *colon, *dot, *end;
@ -206,38 +206,38 @@ static int _xcb_open_unix(const char *file)
return fd; return fd;
} }
XCBConnection *XCBConnect(const char *displayname, int *screenp) xcb_connection_t *xcb_connect(const char *displayname, int *screenp)
{ {
int fd, display = 0; int fd, display = 0;
char *host; char *host;
XCBConnection *c; xcb_connection_t *c;
XCBAuthInfo auth; xcb_auth_info_t auth;
if(!XCBParseDisplay(displayname, &host, &display, screenp)) if(!xcb_parse_display(displayname, &host, &display, screenp))
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
fd = _xcb_open(host, display); fd = _xcb_open(host, display);
free(host); free(host);
if(fd == -1) if(fd == -1)
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
_xcb_get_auth_info(fd, &auth); _xcb_get_auth_info(fd, &auth);
c = XCBConnectToFD(fd, &auth); c = xcb_connect_to_fd(fd, &auth);
free(auth.name); free(auth.name);
free(auth.data); free(auth.data);
return c; return c;
} }
XCBConnection *XCBConnectToDisplayWithAuthInfo(const char *displayname, XCBAuthInfo *auth, int *screenp) xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname, xcb_auth_info_t *auth, int *screenp)
{ {
int fd, display = 0; int fd, display = 0;
char *host; char *host;
if(!XCBParseDisplay(displayname, &host, &display, screenp)) if(!xcb_parse_display(displayname, &host, &display, screenp))
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
fd = _xcb_open(host, display); fd = _xcb_open(host, display);
free(host); free(host);
if(fd == -1) if(fd == -1)
return (XCBConnection *) &error_connection; return (xcb_connection_t *) &error_connection;
return XCBConnectToFD(fd, auth); return xcb_connect_to_fd(fd, auth);
} }

View File

@ -33,16 +33,16 @@
/* Public interface */ /* Public interface */
CARD32 XCBGenerateID(XCBConnection *c) uint32_t xcb_generate_id(xcb_connection_t *c)
{ {
CARD32 ret; uint32_t ret;
if(c->has_error) if(c->has_error)
return -1; return -1;
pthread_mutex_lock(&c->xid.lock); pthread_mutex_lock(&c->xid.lock);
if(c->xid.last == c->xid.max) if(c->xid.last == c->xid.max)
{ {
XCBXCMiscGetXIDRangeRep *range; xcb_xc_misc_get_xid_range_reply_t *range;
range = XCBXCMiscGetXIDRangeReply(c, XCBXCMiscGetXIDRange(c), 0); range = xcb_xc_misc_get_xid_range_reply(c, xcb_xc_misc_get_xid_range(c), 0);
if(!range) if(!range)
{ {
pthread_mutex_unlock(&c->xid.lock); pthread_mutex_unlock(&c->xid.lock);
@ -60,7 +60,7 @@ CARD32 XCBGenerateID(XCBConnection *c)
/* Private interface */ /* Private interface */
int _xcb_xid_init(XCBConnection *c) int _xcb_xid_init(xcb_connection_t *c)
{ {
if(pthread_mutex_init(&c->xid.lock, 0)) if(pthread_mutex_init(&c->xid.lock, 0))
return 0; return 0;
@ -71,7 +71,7 @@ int _xcb_xid_init(XCBConnection *c)
return 1; return 1;
} }
void _xcb_xid_destroy(XCBConnection *c) void _xcb_xid_destroy(xcb_connection_t *c)
{ {
pthread_mutex_destroy(&c->xid.lock); pthread_mutex_destroy(&c->xid.lock);
} }

View File

@ -26,14 +26,14 @@
#include "xcbxlib.h" #include "xcbxlib.h"
#include "xcbint.h" #include "xcbint.h"
unsigned int XCBGetRequestSent(XCBConnection *c) unsigned int xcb_get_request_sent(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return 0; return 0;
return c->out.request; return c->out.request;
} }
pthread_mutex_t *XCBGetIOLock(XCBConnection *c) pthread_mutex_t *xcb_get_io_lock(xcb_connection_t *c)
{ {
if(c->has_error) if(c->has_error)
return 0; return 0;

View File

@ -36,7 +36,7 @@ extern "C" {
/* xcb_ext.c */ /* xcb_ext.c */
struct XCBExtension { struct xcb_extension_t {
const char *name; const char *name;
int global_id; int global_id;
}; };
@ -46,34 +46,34 @@ struct XCBExtension {
typedef struct { typedef struct {
size_t count; size_t count;
XCBExtension *ext; xcb_extension_t *ext;
CARD8 opcode; uint8_t opcode;
BOOL isvoid; uint8_t isvoid;
} XCBProtocolRequest; } xcb_protocol_request_t;
enum XCBSendRequestFlags { enum xcb_send_request_flags_t {
XCB_REQUEST_CHECKED = 1 << 0, XCB_REQUEST_CHECKED = 1 << 0,
XCB_REQUEST_RAW = 1 << 1, XCB_REQUEST_RAW = 1 << 1,
XCB_REQUEST_DISCARD_REPLY = 1 << 2 XCB_REQUEST_DISCARD_REPLY = 1 << 2
}; };
unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, const XCBProtocolRequest *request); unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vector, const xcb_protocol_request_t *request);
/* xcb_in.c */ /* xcb_in.c */
void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e); void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e);
int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error); int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error);
/* xcb_xid.c */ /* xcb_xid.c */
CARD32 XCBGenerateID(XCBConnection *c); uint32_t xcb_generate_id(xcb_connection_t *c);
/* xcb_util.c */ /* xcb_util.c */
int XCBPopcount(CARD32 mask); int xcb_popcount(uint32_t mask);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -47,12 +47,12 @@ enum workarounds {
/* xcb_list.c */ /* xcb_list.c */
typedef void (*XCBListFreeFunc)(void *); typedef void (*xcb_list_free_func_t)(void *);
typedef struct _xcb_map _xcb_map; typedef struct _xcb_map _xcb_map;
_xcb_map *_xcb_map_new(void); _xcb_map *_xcb_map_new(void);
void _xcb_map_delete(_xcb_map *q, XCBListFreeFunc do_free); void _xcb_map_delete(_xcb_map *q, xcb_list_free_func_t do_free);
int _xcb_map_put(_xcb_map *q, unsigned int key, void *data); int _xcb_map_put(_xcb_map *q, unsigned int key, void *data);
void *_xcb_map_remove(_xcb_map *q, unsigned int key); void *_xcb_map_remove(_xcb_map *q, unsigned int key);
@ -70,14 +70,14 @@ typedef struct _xcb_out {
unsigned int request_written; unsigned int request_written;
pthread_mutex_t reqlenlock; pthread_mutex_t reqlenlock;
CARD32 maximum_request_length; uint32_t maximum_request_length;
} _xcb_out; } _xcb_out;
int _xcb_out_init(_xcb_out *out); int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_xcb_out *out); void _xcb_out_destroy(_xcb_out *out);
int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count); int _xcb_out_send(xcb_connection_t *c, struct iovec **vector, int *count);
int _xcb_out_flush_to(XCBConnection *c, unsigned int request); int _xcb_out_flush_to(xcb_connection_t *c, unsigned int request);
/* xcb_in.c */ /* xcb_in.c */
@ -107,24 +107,24 @@ typedef struct _xcb_in {
int _xcb_in_init(_xcb_in *in); int _xcb_in_init(_xcb_in *in);
void _xcb_in_destroy(_xcb_in *in); void _xcb_in_destroy(_xcb_in *in);
int _xcb_in_expect_reply(XCBConnection *c, unsigned int request, enum workarounds workaround, int flags); int _xcb_in_expect_reply(xcb_connection_t *c, unsigned int request, enum workarounds workaround, int flags);
int _xcb_in_read(XCBConnection *c); int _xcb_in_read(xcb_connection_t *c);
int _xcb_in_read_block(XCBConnection *c, void *buf, int nread); int _xcb_in_read_block(xcb_connection_t *c, void *buf, int nread);
/* xcb_xid.c */ /* xcb_xid.c */
typedef struct _xcb_xid { typedef struct _xcb_xid {
pthread_mutex_t lock; pthread_mutex_t lock;
CARD32 last; uint32_t last;
CARD32 base; uint32_t base;
CARD32 max; uint32_t max;
CARD32 inc; uint32_t inc;
} _xcb_xid; } _xcb_xid;
int _xcb_xid_init(XCBConnection *c); int _xcb_xid_init(xcb_connection_t *c);
void _xcb_xid_destroy(XCBConnection *c); void _xcb_xid_destroy(xcb_connection_t *c);
/* xcb_ext.c */ /* xcb_ext.c */
@ -135,17 +135,17 @@ typedef struct _xcb_ext {
int extensions_size; int extensions_size;
} _xcb_ext; } _xcb_ext;
int _xcb_ext_init(XCBConnection *c); int _xcb_ext_init(xcb_connection_t *c);
void _xcb_ext_destroy(XCBConnection *c); void _xcb_ext_destroy(xcb_connection_t *c);
/* xcb_conn.c */ /* xcb_conn.c */
struct XCBConnection { struct xcb_connection_t {
int has_error; int has_error;
/* constant data */ /* constant data */
XCBSetup *setup; xcb_setup_t *setup;
int fd; int fd;
/* I/O data */ /* I/O data */
@ -158,13 +158,13 @@ struct XCBConnection {
_xcb_xid xid; _xcb_xid xid;
}; };
void _xcb_conn_shutdown(XCBConnection *c); void _xcb_conn_shutdown(xcb_connection_t *c);
int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector, int *count); int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
/* xcb_auth.c */ /* xcb_auth.c */
int _xcb_get_auth_info(int fd, XCBAuthInfo *info); int _xcb_get_auth_info(int fd, xcb_auth_info_t *info);
#ifdef GCC_HAS_VISIBILITY #ifdef GCC_HAS_VISIBILITY
#pragma GCC visibility pop #pragma GCC visibility pop

View File

@ -32,8 +32,8 @@
#include "xcb.h" #include "xcb.h"
/* This function must be called with the IOLock held. */ /* This function must be called with the IOLock held. */
unsigned int XCBGetRequestSent(XCBConnection *c); unsigned int xcb_get_request_sent(xcb_connection_t *c);
pthread_mutex_t *XCBGetIOLock(XCBConnection *c); pthread_mutex_t *xcb_get_io_lock(xcb_connection_t *c);
#endif #endif