emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/xelb 16e774c 02/42: First commit


From: Chris Feng
Subject: [elpa] externals/xelb 16e774c 02/42: First commit
Date: Thu, 17 Sep 2015 23:16:37 +0000

branch: externals/xelb
commit 16e774cfc8941d710693cae259d18b1686075a59
Author: Chris Feng <address@hidden>
Commit: Chris Feng <address@hidden>

    First commit
---
 COPYING        |  674 +++++++++++++++++++++++++++++++++++++
 README         |   12 +
 xcb-cursor.el  |  433 ++++++++++++++++++++++++
 xcb-ewmh.el    |  757 +++++++++++++++++++++++++++++++++++++++++
 xcb-icccm.el   |  540 +++++++++++++++++++++++++++++
 xcb-keysyms.el |  314 +++++++++++++++++
 xcb-xim.el     | 1025 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 xcb-xlib.el    |  113 +++++++
 8 files changed, 3868 insertions(+), 0 deletions(-)

diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/README b/README
new file mode 100644
index 0000000..2b7b8a3
--- /dev/null
+++ b/README
@@ -0,0 +1,12 @@
+Utility libraries for XELB
+==========================
+
+This project provides utitlity libraries for working with XELB. Most of them
+are the Elisp ports of the utility libraries of XCB. They are:
+  + xcb-curosr: port of xcb/util-cursor
+  + xcb-icccm and xcb-ewmh: port of xcb/util-wm
+  + xcb-keysyms: port of xcb/util-keysyms
+
+This project also includes other utility libraries:
+  + xcb-xim: an implementation of XIM protocl
+  + xcb-xlib: constants defined in "Xlib.h" but not found in XCB
diff --git a/xcb-cursor.el b/xcb-cursor.el
new file mode 100644
index 0000000..beb6964
--- /dev/null
+++ b/xcb-cursor.el
@@ -0,0 +1,433 @@
+;;; xcb-cursor.el --- Port of Xcursor  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library is a port of Xcursor in Xlib, and roughly corresponds to the
+;; xcb/util-cursor project.
+
+;; Usage tips:
+;; + Do not forget to call `xcb:cursor:init' for _every_ connection using this
+;;   library.
+;; + The only useful method in this library is `xcb:cursor:load-cursor', which
+;;   loads a cursor by its name (e.g. "left_ptr"), in the following order:
+;;   1. themed cursor
+;;   2. inherited themed cursor
+;;   3. standard X cursor
+
+;; Todo:
+;; + Add legacy support for RENDER.
+;; + Cursor should be set per screen (only the first is used right now).
+;; + Move codes corresponding to xcb/util-renderutil or xcb/util-image
+;;   elsewhere.
+
+;; References:
+;; + Xcursor(3).
+;; + xcb/util-cursor (git://anongit.freedesktop.org/xcb/util-cursor)
+;; + xcb/util-renderutil (git://anongit.freedesktop.org/xcb/util-renderutil)
+;; + xcb/util-image (git://anongit.freedesktop.org/xcb/util-image)
+
+;;; Code:
+
+(require 'xcb-xproto)
+(require 'xcb-render)
+
+;; FIXME: check if resource manager really works
+(cl-defmethod xcb:cursor:init ((obj xcb:connection))
+  "Initialize Xcursor for connection OBJ."
+  ;; Initialize resource manager
+  (let* ((root (slot-value (car (slot-value (xcb:get-setup obj) 'roots))
+                           'root))
+         (rm (xcb:+request-unchecked+reply obj
+                 (make-instance 'xcb:GetProperty
+                                :delete 0 :window root
+                                :property xcb:Atom:RESOURCE_MANAGER
+                                :type xcb:Atom:STRING
+                                :long-offset 0
+                                :long-length 16384))) ;FIXME: xcb/util-cursor
+         (rm (split-string
+              (decode-coding-string
+               (apply 'unibyte-string (append (slot-value rm 'value) nil))
+               'iso-latin-1)
+              "\n"))
+         theme size dpi)
+    (dolist (i rm)
+      (pcase (replace-regexp-in-string "^\\(\\S-+\\)" "\\1" i)
+        ("Xcursor.theme"
+         (setq theme
+               (replace-regexp-in-string "^[^:]+:\\s-*\\(.+$\\)" "\\1" i)))
+        ("Xcursor.size"
+         (setq size
+               (string-to-int (replace-regexp-in-string "^[^:]+:\\s-*\\(.+$\\)"
+                                                        "\\1" i))))
+        ("Xft.dpi"
+         (setq dpi
+               (string-to-int (replace-regexp-in-string "^[^:]+:\\s-*\\(.+$\\)"
+                                                        "\\1" i))))))
+    ;; Get cursor size from XCURSOR_SIZE environment variable
+    (let ((default-size (getenv "XCURSOR_SIZE")))
+      (when default-size
+        (setq default-size (string-to-int default-size)))
+      (setq size (or default-size size)))
+    ;; Alternatives
+    (when (and (not size) dpi)
+      (setq size (/ (* dpi 16) 72)))    ;FIXME: xcb/util-cursor
+    (unless size
+      (setq size
+            ;; FIXME: xcb/util-cursor
+            (/ (min (x-display-pixel-width) (x-display-pixel-height)) 48)))
+    ;; Save default values
+    (let ((plist (plist-get (slot-value obj 'extra-plist) 'cursor)))
+      (setq plist (plist-put plist 'theme theme)
+            plist (plist-put plist 'size size))
+      (setf (slot-value obj 'extra-plist)
+            (plist-put (slot-value obj 'extra-plist) 'cursor plist))))
+  ;; Initialize render extension
+  (if (= 0 (slot-value (xcb:get-extension-data exwm--connection 'xcb:render)
+                       'present))
+      (error "[XELB:CURSOR] Render extension is not supported by this server")
+    (with-slots (minor-version)
+        (xcb:+request-unchecked+reply obj
+            (make-instance 'xcb:render:QueryVersion
+                           :client-major-version 0 :client-minor-version 8))
+      (if (> 8 minor-version)
+          (error "[XELB:CURSOR] Render version 0.8 is not supported")
+        (let* ((formats
+                (slot-value (xcb:+request-unchecked+reply obj
+                                (make-instance 'xcb:render:QueryPictFormats))
+                            'formats))
+               (format (catch 'break
+                         (dolist (i formats)
+                           (with-slots (type depth direct) i
+                             (with-slots (red-shift red-mask
+                                                    green-shift green-mask
+                                                    blue-shift blue-mask
+                                                    alpha-shift alpha-mask)
+                                 direct
+                               ;; FIXME: xcb/util-renderutil
+                               (when (and (= type xcb:render:PictType:Direct)
+                                          (= depth 32)
+                                          (= red-shift 16) (= red-mask #xFF)
+                                          (= green-shift 8) (= green-mask #xFF)
+                                          (= blue-shift 0) (= blue-mask #xFF)
+                                          (= alpha-shift 24)
+                                          (= alpha-mask #xFF))
+                                 (throw 'break i)))))))
+               (plist (plist-get (slot-value obj 'extra-plist) 'cursor)))
+          (setf (slot-value obj 'extra-plist)
+                (plist-put (slot-value obj 'extra-plist) 'cursor
+                           (plist-put plist 'pict-format format))))))))
+
+(defsubst xcb:cursor:-get-path ()
+  "Return a list of cursor paths."
+  (let ((path (getenv "XCURSOR_PATH")))
+    (if path
+        (split-string path ":" t)
+      '("~/.icons"
+        "/usr/share/icons"
+        "/usr/share/pixmaps"
+        "/usr/X11R6/lib/X11/icons"))))
+
+(defun xcb:cursor:-get-theme-inherits (file)
+  "Return the inherited themes in a index.theme file FILE."
+  (let ((lines (with-temp-buffer
+                 (insert-file-contents file)
+                 (split-string (buffer-string) "\n" t))))
+    (catch 'break
+      (dolist (line lines)
+        (when (string-match "^Inherits\\s-*=\\s-*" line)
+          (throw 'break
+                 (split-string (replace-regexp-in-string "^[^=]+=\\(.*\\)$"
+                                                         "\\1" line)
+                               "[;, \t\n]+" t)))))))
+
+(defun xcb:cursor:-find-file (theme name &optional skip)
+  "Return the file for cursor named NAME in theme THEME, or nil if not found."
+  (catch 'return
+    ;; Skip searched themes
+    (when (memq theme skip)
+      (throw 'return nil))
+    ;; Give up when supplied "core" theme and a valid cursor name
+    (when (and (string= "core" theme) (xcb:cursor:-shape->id name))
+      (throw 'return nil))
+    (let ((path (xcb:cursor:-get-path))
+          file)
+      ;; 1. try THEME/cursors/NAME in each cursor path
+      (dolist (i path)
+        (setq file (concat i "/" theme "/cursors/" name))
+        (when (file-readable-p file)
+          (throw 'return file)))
+      ;; 2. try "Inherits=" key in "index.theme"
+      (dolist (i path)
+        (setq file (concat i "/" theme "/index.theme"))
+        (when (file-readable-p file)
+          (cl-pushnew theme skip)
+          ;; try all inherited themes
+          (dolist (j (xcb:cursor:-get-theme-inherits file))
+            (setq file (xcb:cursor:-find-file j name skip))
+            (when file
+              (throw 'return file))
+            (cl-pushnew j skip)))))
+    nil))
+
+(defconst xcb:cursor:-file-magic-lsb "Xcur"
+  "The magic number for little-endian Xcursor file.")
+(defconst xcb:cursor:-file-magic-msb "rucX"
+  "The magic number for big-endian Xcursor file.")
+
+(defclass xcb:cursor:-file-header (xcb:-struct)
+  ((magic :type xcb:CARD32)
+   (header :type xcb:CARD32)
+   (version :type xcb:CARD32)
+   (ntoc :type xcb:CARD32)) ;redundant, required for calculating TOC bytes
+  :documentation "Xcursor file header.")
+
+(defclass xcb:cursor:-file-header-toc (xcb:-struct)
+  ((ntoc :type xcb:CARD32)              ;redundant slot
+   (toc :type xcb:-ignore)
+   (toc~ :initform '(name toc type xcb:cursor:-file-toc
+                          size (xcb:-fieldref 'ntoc))
+         :type xcb:-list))
+  :documentation "The TOC field in Xcursor file header.")
+
+(defclass xcb:cursor:-file-toc (xcb:-struct)
+  ((type :type xcb:CARD32)
+   (subtype :type xcb:CARD32)
+   (position :type xcb:CARD32))
+  :documentation "Xcursor file TOC entry.")
+
+(defclass xcb:cursor:-file-chunk-header (xcb:-struct)
+  ((header :type xcb:CARD32)
+   (type :type xcb:CARD32)
+   (subtype :type xcb:CARD32)
+   (version :type xcb:CARD32)
+   (width :type xcb:CARD32) ;redundant, required for calculating image bytes
+   (height :type xcb:CARD32)) ;redundant, required for calculating image bytes
+  :documentation "Xcursor file chunk header.")
+
+(defconst xcb:cursor:-file-chunk-image-header 36
+  "Header value of image-type chunk in Xcursor file.")
+(defconst xcb:cursor:-file-chunk-image-type #xFFFD0002
+  "Type of image-type chunk in Xcursor file.")
+(defconst xcb:cursor:-file-chunk-image-version 1
+  "Version of image-type chunk in Xcursor file.")
+
+(defclass xcb:cursor:-file-chunk-image (xcb:-struct)
+  ((width :type xcb:CARD32)             ;<= #x7FFF, redundant
+   (height :type xcb:CARD32)            ;<= #x7FFF, redundant
+   (xhot :type xcb:CARD32)              ;<= width
+   (yhot :type xcb:CARD32)              ;<= height
+   (delay :type xcb:CARD32)             ;in ms
+   (pixels :type xcb:-ignore)
+   (pixels~ :initform '(name pixels type xcb:CARD32
+                             size (* (xcb:-fieldref 'width)
+                                     (xcb:-fieldref 'height)))
+            :type xcb:-list))
+  :documentation "Image-type chunk in Xcursor file.")
+
+(cl-defmethod xcb:cursor:-parse-file ((obj xcb:connection) path)
+  "Parse an Xcursor file named PATH."
+  (catch 'return
+    (let ((data (let ((coding-system-for-read 'binary))
+                  (with-temp-buffer
+                    (set-buffer-multibyte nil)
+                    (insert-file-contents path) (buffer-string))))
+          (best-size 0)
+          xcb:lsb                       ;override global byte order
+          chunks
+          magic file-header file-header-toc chunk-header chunk)
+      ;; Determine byte order
+      (setq magic (substring data 0 4))
+      (if (string= xcb:cursor:-file-magic-lsb magic)
+          (setq xcb:lsb t)              ;LSB first
+        (if (string= xcb:cursor:-file-magic-msb magic)
+            (setq xcb:lsb nil)          ;MSB first
+          (throw 'return nil)))
+      (setq file-header (make-instance 'xcb:cursor:-file-header))
+      ;;
+      (xcb:unmarshal file-header (substring data 0 16))
+      ;; FIXME: checks
+      (setq file-header-toc (make-instance 'xcb:cursor:-file-header-toc))
+      (xcb:unmarshal file-header-toc
+                     (substring data 12 (+ 16 (* 12 (slot-value file-header
+                                                                'ntoc)))))
+      (with-slots (toc) file-header-toc
+        (let ((target (plist-get
+                       (plist-get (slot-value obj 'extra-plist) 'cursor)
+                       'size)))
+          (catch 'break
+            (dolist (i toc)
+              (with-slots (type subtype) i
+                (when (= type xcb:cursor:-file-chunk-image-type)
+                  (when (= target subtype)
+                    (setq best-size target)
+                    (throw 'break nil))
+                  (when (> (abs (- target best-size))
+                           (abs (- target subtype)))
+                    (setq best-size subtype)))))))
+        ;; Collect chunks fitting this size
+        (setq chunk-header (make-instance 'xcb:cursor:-file-chunk-header))
+        (dolist (i toc)
+          (with-slots (type subtype position) i
+            (when (and (= type xcb:cursor:-file-chunk-image-type)
+                       (= subtype best-size))
+              (xcb:unmarshal chunk-header (substring data position
+                                                     (+ position 24)))
+              ;; Validate the header of this chunk
+              (with-slots (header type subtype version) chunk-header
+                (when (or (/= header xcb:cursor:-file-chunk-image-header)
+                          (/= type xcb:cursor:-file-chunk-image-type)
+                          (/= subtype best-size)
+                          (/= version xcb:cursor:-file-chunk-image-version))
+                  (throw 'return nil)))
+              ;; Parse this chunk
+              (setq chunk (make-instance 'xcb:cursor:-file-chunk-image))
+              (xcb:unmarshal chunk (substring data (+ position 16)
+                                              (+ position 36
+                                                 (* 4
+                                                    (slot-value chunk-header
+                                                                'width)
+                                                    (slot-value chunk-header
+                                                                'height)))))
+              (setq chunks (nconc chunks (list chunk))))))
+        (list xcb:lsb chunks)))))
+
+(cl-defmethod xcb:cursor:-load-cursor ((obj xcb:connection) file)
+  "Load a cursor file FILE."
+  (let* ((images (xcb:cursor:-parse-file obj file))
+         (lsb (car images))
+         (images (cadr images))
+         (root (slot-value (car (slot-value (xcb:get-setup obj) 'roots))
+                           'root))
+         (picture (xcb:generate-id obj))
+         (pict-format (slot-value
+                       (plist-get
+                        (plist-get (slot-value obj 'extra-plist) 'cursor)
+                        'pict-format)
+                       'id))
+         pixmap gc cursors cursor last-width last-height)
+    (dolist (image images)
+      (with-slots (width height xhot yhot delay pixels) image
+        (when (or (not pixmap) (/= last-width width) (/= last-height height))
+          (if pixmap
+              (progn (xcb:+request obj (make-instance 'xcb:FreePixmap
+                                                      :pixmap pixmap))
+                     (xcb:+request obj (make-instance 'xcb:FreeGC :gc gc)))
+            (setq pixmap (xcb:generate-id obj)
+                  gc (xcb:generate-id obj)))
+          (xcb:+request obj (make-instance 'xcb:CreatePixmap
+                                           :depth 32 :pid pixmap :drawable root
+                                           :width width :height height))
+          (xcb:+request obj (make-instance 'xcb:CreateGC
+                                           :cid gc :drawable pixmap
+                                           :value-mask 0))
+          (setq last-width width
+                last-height height))
+        (xcb:+request obj (make-instance 'xcb:PutImage
+                                         :format xcb:ImageFormat:ZPixmap
+                                         :drawable pixmap
+                                         :gc gc
+                                         :width width
+                                         :height height
+                                         :dst-x 0
+                                         :dst-y 0
+                                         :left-pad 0
+                                         :depth 32
+                                         :data (with-temp-buffer
+                                                 (set-buffer-multibyte nil)
+                                                 (mapconcat
+                                                  (if lsb 'xcb:-pack-u4-lsb
+                                                    'xcb:-pack-u4)
+                                                  pixels []))))
+        (xcb:+request obj (make-instance 'xcb:render:CreatePicture
+                                         :pid picture
+                                         :drawable pixmap
+                                         :format pict-format
+                                         :value-mask 0))
+        (setq cursor (xcb:generate-id obj)
+              cursors (nconc cursors
+                             (list (make-instance 'xcb:render:ANIMCURSORELT
+                                                  :cursor cursor
+                                                  :delay delay))))
+        (xcb:+request obj (make-instance 'xcb:render:CreateCursor
+                                         :cid cursor
+                                         :source picture
+                                         :x xhot :y yhot))
+        (xcb:+request obj (make-instance 'xcb:render:FreePicture
+                                         :picture picture))))
+    (xcb:+request obj (make-instance 'xcb:FreePixmap :pixmap pixmap))
+    (xcb:+request obj (make-instance 'xcb:FreeGC :gc gc))
+    (xcb:flush obj)
+    (if (= 1 (length cursors))
+        ;; Non-animated cursor
+        (slot-value (car cursors) 'cursor)
+      ;; Animated cursor
+      (setq cursor (xcb:generate-id obj))
+      (xcb:+request obj (make-instance 'xcb:render:CreateAnimCursor
+                                       :cid cursor
+                                       :cursors (vconcat cursors)))
+      (dolist (i cursors)
+        (xcb:+request obj (make-instance 'xcb:FreeCursor
+                                         :cursor (slot-value i 'cursor))))
+      (xcb:flush obj)
+      cursor)))
+
+(defsubst xcb:cursor:-shape->id (name)
+  "Return the standard Xcursor font for cursor named NAME."
+  ;; Standard X cursor fonts are defined in Emacs
+  (intern-soft (concat "x-pointer-" (replace-regexp-in-string "_" "-" name))))
+
+(cl-defmethod xcb:cursor:load-cursor ((obj xcb:connection) name)
+  "Return a cursor whose name is NAME."
+  (let* ((theme (or (plist-get
+                     (plist-get (slot-value obj 'extra-plist) 'cursor) 'theme)
+                    "default"))
+         (file (xcb:cursor:-find-file theme name)))
+    (if file
+        (xcb:cursor:-load-cursor obj file)
+      ;; Fallback to standard X cursors
+      (let ((pointer (xcb:cursor:-shape->id name))
+            (cursor xcb:Cursor:None)
+            font)
+        (when (boundp pointer)
+          (setq pointer (symbol-value pointer)
+                font (xcb:generate-id obj)
+                cursor (xcb:generate-id obj))
+          (xcb:+request obj
+              (make-instance 'xcb:OpenFont
+                             :fid font :name-len (length "cursor")
+                             :name "cursor"))
+          (xcb:+request obj
+              (make-instance 'xcb:CreateGlyphCursor
+                             :cid cursor :source-font font :mask-font font
+                             :source-char pointer :mask-char (1+ pointer)
+                             :fore-red 0 :fore-green 0 :fore-blue 0
+                             :back-red #xFFFF :back-green #xFFFF
+                             :back-blue #xFFFF))
+          (xcb:flush obj))
+        cursor))))
+
+
+
+(provide 'xcb-cursor)
+
+;;; xcb-cursor.el ends here
diff --git a/xcb-ewmh.el b/xcb-ewmh.el
new file mode 100644
index 0000000..f5f00ff
--- /dev/null
+++ b/xcb-ewmh.el
@@ -0,0 +1,757 @@
+;;; xcb-ewmh.el --- Extended Window Manager Hints  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library implement EWMH the same way as xcb/util-wm.
+
+;; Usage tips:
+;; + Do not forget to call `xcb:ewmh:init' for _every_ connection using
+;;   this library.
+;; + Use `xcb:ewmh:SendEvent' instead of `xcb:SendEvent' to send client
+;;   messages defined in this library.
+;; + Initialize this library auto loads and initializes 'xcb-icccm'.
+
+;; Todo:
+;; + Interned atoms are actually connection-dependent. Currently they are
+;;   simply saved as global variables.
+;; + Is UTF-8 string NULL-terminated?
+;; + _NET_WM_CM_Sn (should implement "manager selection" in ICCCM first)
+
+;; References:
+;; + EWMH (http://standards.freedesktop.org/wm-spec/wm-spec-latest.html)
+;; + xcb/util-wm (git://anongit.freedesktop.org/xcb/util-wm)
+
+;;; Code:
+
+(require 'xcb-xproto)
+(require 'xcb-icccm)
+
+;;;; EWMH Atoms
+
+(defconst xcb:ewmh:-atoms               ;_NET_WM_CM_Sn are left out
+  '(;; Root Window Properties (and Related Messages)
+    _NET_SUPPORTED
+    _NET_CLIENT_LIST
+    _NET_CLIENT_LIST_STACKING
+    _NET_NUMBER_OF_DESKTOPS
+    _NET_DESKTOP_GEOMETRY
+    _NET_DESKTOP_VIEWPORT
+    _NET_CURRENT_DESKTOP
+    _NET_DESKTOP_NAMES
+    _NET_ACTIVE_WINDOW
+    _NET_WORKAREA
+    _NET_SUPPORTING_WM_CHECK
+    _NET_VIRTUAL_ROOTS
+    _NET_DESKTOP_LAYOUT
+    _NET_SHOWING_DESKTOP
+    ;; Other Root Window Messages
+    _NET_CLOSE_WINDOW
+    _NET_MOVERESIZE_WINDOW
+    _NET_WM_MOVERESIZE
+    _NET_RESTACK_WINDOW
+    _NET_REQUEST_FRAME_EXTENTS
+    ;; Application Window Properties
+    _NET_WM_NAME
+    _NET_WM_VISIBLE_NAME
+    _NET_WM_ICON_NAME
+    _NET_WM_VISIBLE_ICON_NAME
+    _NET_WM_DESKTOP
+    _NET_WM_WINDOW_TYPE
+    _NET_WM_STATE
+    _NET_WM_ALLOWED_ACTIONS
+    _NET_WM_STRUT
+    _NET_WM_STRUT_PARTIAL
+    _NET_WM_ICON_GEOMETRY
+    _NET_WM_ICON
+    _NET_WM_PID
+    _NET_WM_HANDLED_ICONS
+    _NET_WM_USER_TIME
+    _NET_WM_USER_TIME_WINDOW
+    _NET_FRAME_EXTENTS
+    _NET_WM_OPAQUE_REGION
+    _NET_WM_BYPASS_COMPOSITOR
+    ;; Window Manager Protocols
+    _NET_WM_PING
+    _NET_WM_SYNC_REQUEST
+    _NET_WM_SYNC_REQUEST_COUNTER
+    _NET_WM_FULLSCREEN_MONITORS
+    ;; Other Properties
+    _NET_WM_FULL_PLACEMENT
+    ;; _NET_WM_WINDOW_TYPE hint
+    _NET_WM_WINDOW_TYPE_DESKTOP
+    _NET_WM_WINDOW_TYPE_DOCK
+    _NET_WM_WINDOW_TYPE_TOOLBAR
+    _NET_WM_WINDOW_TYPE_MENU
+    _NET_WM_WINDOW_TYPE_UTILITY
+    _NET_WM_WINDOW_TYPE_SPLASH
+    _NET_WM_WINDOW_TYPE_DIALOG
+    _NET_WM_WINDOW_TYPE_DROPDOWN_MENU
+    _NET_WM_WINDOW_TYPE_POPUP_MENU
+    _NET_WM_WINDOW_TYPE_TOOLTIP
+    _NET_WM_WINDOW_TYPE_NOTIFICATION
+    _NET_WM_WINDOW_TYPE_COMBO
+    _NET_WM_WINDOW_TYPE_DND
+    _NET_WM_WINDOW_TYPE_NORMAL
+    ;; _NET_WM_STATE hint
+    _NET_WM_STATE_MODAL
+    _NET_WM_STATE_STICKY
+    _NET_WM_STATE_MAXIMIZED_VERT
+    _NET_WM_STATE_MAXIMIZED_HORZ
+    _NET_WM_STATE_SHADED
+    _NET_WM_STATE_SKIP_TASKBAR
+    _NET_WM_STATE_SKIP_PAGER
+    _NET_WM_STATE_HIDDEN
+    _NET_WM_STATE_FULLSCREEN
+    _NET_WM_STATE_ABOVE
+    _NET_WM_STATE_BELOW
+    _NET_WM_STATE_DEMANDS_ATTENTION
+    _NET_WM_STATE_FOCUSED
+    ;; _NET_WM_ACTION hint
+    _NET_WM_ACTION_MOVE
+    _NET_WM_ACTION_RESIZE
+    _NET_WM_ACTION_MINIMIZE
+    _NET_WM_ACTION_SHADE
+    _NET_WM_ACTION_STICK
+    _NET_WM_ACTION_MAXIMIZE_HORZ
+    _NET_WM_ACTION_MAXIMIZE_VERT
+    _NET_WM_ACTION_FULLSCREEN
+    _NET_WM_ACTION_CHANGE_DESKTOP
+    _NET_WM_ACTION_CLOSE
+    _NET_WM_ACTION_ABOVE
+    _NET_WM_ACTION_BELOW)
+  "EWMH atoms.")
+
+(cl-defmethod xcb:ewmh:init ((obj xcb:connection))
+  "Initialize EWMH module.
+
+This method must be called before using any other method in this module.
+
+This method also initializes ICCCM module automatically."
+  (xcb:icccm:init obj)                  ;required
+  (let ((atoms xcb:ewmh:-atoms))
+    (dotimes (i (x-display-screens))
+      (push (intern (format "_NET_WM_CM_S%d" i)) atoms))
+    (xcb:icccm:intern-atoms obj atoms)))
+
+;;;; Client message
+
+(defclass xcb:ewmh:SendEvent (xcb:SendEvent)
+  ((propagate :initform 0)
+   (event-mask :initform (logior xcb:EventMask:SubstructureNotify
+                                 xcb:EventMask:SubstructureRedirect)))
+  :documentation "A fork of `xcb:SendEvent' to send EWMH client message.
+
+Note that this only applies to \"sending a message to the root window\" in
+EWMH")
+
+(defclass xcb:ewmh:--ClientMessage ()
+  ((data :type xcb:-ignore))            ;shadowed slot
+  :documentation "To shadow the data slot in `xcb:SendEvent'.")
+;;
+(defclass xcb:ewmh:-ClientMessage (xcb:ewmh:--ClientMessage xcb:ClientMessage)
+  ((format :initform 32)))
+
+;;;; Abstract classes for getting/changing (UTF-8) string properties
+
+(defclass xcb:ewmh:-GetProperty-utf8 (xcb:icccm:-GetProperty-text)
+  ((type :initform xcb:Atom:UTF8_STRING))
+  :documentation "Get an EWMH UTF-8 text property (request part).")
+(defclass xcb:ewmh:-GetProperty-utf8~reply (xcb:icccm:-GetProperty-text~reply)
+  nil
+  :documentation "Get an EWMH UTF-8 text property (reply part).")
+(defclass xcb:ewmh:-ChangeProperty-utf8 (xcb:icccm:-ChangeProperty-text)
+  ((type :initform xcb:Atom:UTF8_STRING))
+  :documentation "Change an EWMH UTF-8 text property.")
+
+;;;; Root Window Properties (and Related Messages)
+
+;; _NET_SUPPORTED
+(defclass xcb:ewmh:get-_NET_SUPPORTED (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_SUPPORTED)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:get-_NET_SUPPORTED~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_SUPPORTED (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_SUPPORTED)
+   (type :initform xcb:Atom:ATOM)))
+
+;; _NET_CLIENT_LIST
+(defclass xcb:ewmh:get-_NET_CLIENT_LIST (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_CLIENT_LIST)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:get-_NET_CLIENT_LIST~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_CLIENT_LIST (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_CLIENT_LIST)
+   (type :initform xcb:Atom:WINDOW)))
+
+;; _NET_CLIENT_LIST_STACKING
+(defclass xcb:ewmh:get-_NET_CLIENT_LIST_STACKING (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_CLIENT_LIST_STACKING)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:get-_NET_CLIENT_LIST_STACKING~reply
+  (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_CLIENT_LIST_STACKING (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_CLIENT_LIST_STACKING)
+   (type :initform xcb:Atom:WINDOW)))
+
+;; _NET_NUMBER_OF_DESKTOPS
+(defclass xcb:ewmh:get-_NET_NUMBER_OF_DESKTOPS (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_NUMBER_OF_DESKTOPS)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_NUMBER_OF_DESKTOPS~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_NUMBER_OF_DESKTOPS
+  (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_NUMBER_OF_DESKTOPS)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_DESKTOP_GEOMETRY
+(defclass xcb:ewmh:-_NET_DESKTOP_GEOMETRY ()
+  ((width :initarg :width :type xcb:-ignore)
+   (height :initarg :height :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_DESKTOP_GEOMETRY (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_DESKTOP_GEOMETRY)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 2)))
+(defclass xcb:ewmh:get-_NET_DESKTOP_GEOMETRY~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_DESKTOP_GEOMETRY)
+  nil)
+(defclass xcb:ewmh:set-_NET_DESKTOP_GEOMETRY
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_DESKTOP_GEOMETRY)
+  ((property :initform xcb:Atom:_NET_DESKTOP_GEOMETRY)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_DESKTOP_GEOMETRY
+  (xcb:ewmh:-ClientMessage xcb:ewmh:-_NET_DESKTOP_GEOMETRY)
+  ((type :initform xcb:Atom:_NET_DESKTOP_GEOMETRY)))
+
+;; _NET_DESKTOP_VIEWPORT
+(defclass xcb:ewmh:get-_NET_DESKTOP_VIEWPORT (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_DESKTOP_VIEWPORT)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_DESKTOP_VIEWPORT~reply
+  (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_DESKTOP_VIEWPORT (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_DESKTOP_VIEWPORT)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_DESKTOP_VIEWPORT (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_DESKTOP_VIEWPORT)
+   (new-vx :initarg :new-vx :type xcb:CARD32)
+   (new-vy :initarg :new-vy :type xcb:CARD32)))
+
+;; _NET_CURRENT_DESKTOP
+(defclass xcb:ewmh:get-_NET_CURRENT_DESKTOP (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_CURRENT_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_CURRENT_DESKTOP~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_CURRENT_DESKTOP (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_CURRENT_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_CURRENT_DESKTOP (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_CURRENT_DESKTOP)
+   (new-index :initarg :new-index :type xcb:CARD32)
+   (timestamp :initarg :timestamp :type xcb:CARD32)))
+
+;; _NET_DESKTOP_NAMES
+(defclass xcb:ewmh:get-_NET_DESKTOP_NAMES (xcb:ewmh:-GetProperty-utf8)
+  ((property :initform xcb:Atom:_NET_DESKTOP_NAMES)))
+(defclass xcb:ewmh:get-_NET_DESKTOP_NAMES~reply
+  (xcb:ewmh:-GetProperty-utf8~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_DESKTOP_NAMES (xcb:ewmh:-ChangeProperty-utf8)
+  ((property :initform xcb:Atom:_NET_DESKTOP_NAMES)))
+
+;; _NET_ACTIVE_WINDOW
+(defclass xcb:ewmh:get-_NET_ACTIVE_WINDOW (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_ACTIVE_WINDOW)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:get-_NET_ACTIVE_WINDOW~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_ACTIVE_WINDOW (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_ACTIVE_WINDOW)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:_NET_ACTIVE_WINDOW (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_ACTIVE_WINDOW)
+   (source-indication :initarg :source-indication :type xcb:CARD32)
+   (timestamp :initarg :timestamp :type xcb:CARD32)
+   (current-active-window :initarg :current-active-window :type xcb:WINDOW)))
+
+;; _NET_WORKAREA
+(defclass xcb:ewmh:get-_NET_WORKAREA (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WORKAREA)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WORKAREA~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WORKAREA (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WORKAREA)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_SUPPORTING_WM_CHECK
+(defclass xcb:ewmh:get-_NET_SUPPORTING_WM_CHECK (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_SUPPORTING_WM_CHECK)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:get-_NET_SUPPORTING_WM_CHECK~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_SUPPORTING_WM_CHECK
+  (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_SUPPORTING_WM_CHECK)
+   (type :initform xcb:Atom:WINDOW)))
+
+;; _NET_VIRTUAL_ROOTS
+(defclass xcb:ewmh:get-_NET_VIRTUAL_ROOTS (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_VIRTUAL_ROOTS)
+   (type :initform xcb:Atom:WINDOW)))
+(defclass xcb:ewmh:get-_NET_VIRTUAL_ROOTS~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_VIRTUAL_ROOTS (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_VIRTUAL_ROOTS)
+   (type :initform xcb:Atom:WINDOW)))
+
+;; _NET_DESKTOP_LAYOUT
+;; Orientations
+(defconst xcb:ewmh:_NET_WM_ORIENTATION_HORZ 0)
+(defconst xcb:ewmh:_NET_WM_ORIENTATION_VERT 1)
+;; Starting corners
+(defconst xcb:ewmh:_NET_WM_TOPLEFT 0)
+(defconst xcb:ewmh:_NET_WM_TOPRIGHT 1)
+(defconst xcb:ewmh:_NET_WM_BOTTOMRIGHT 2)
+(defconst xcb:ewmh:_NET_WM_BOTTOMLEFT 3)
+;;
+(defclass xcb:ewmh:-_NET_DESKTOP_LAYOUT ()
+  ((orientation :initarg :orientation :type xcb:-ignore)
+   (columns :initarg :columns :type xcb:-ignore)
+   (rows :initarg :rows :type xcb:-ignore)
+   (starting-corner :initarg :starting-corner :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_DESKTOP_LAYOUT (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_DESKTOP_LAYOUT)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 4)))
+(defclass xcb:ewmh:get-_NET_DESKTOP_LAYOUT~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_DESKTOP_LAYOUT)
+  nil)
+(defclass xcb:ewmh:set-_NET_DESKTOP_LAYOUT
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_DESKTOP_LAYOUT)
+  ((property :initform xcb:Atom:_NET_DESKTOP_LAYOUT)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_SHOWING_DESKTOP
+(defclass xcb:ewmh:get-_NET_SHOWING_DESKTOP (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_SHOWING_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_SHOWING_DESKTOP~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_SHOWING_DESKTOP (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_SHOWING_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_SHOWING_DESKTOP (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_SHOWING_DESKTOP)
+   (show :initarg :show :type xcb:CARD32)))
+
+;;;; Other Root Window Messages
+
+;; _NET_CLOSE_WINDOW
+(defclass xcb:ewmh:_NET_CLOSE_WINDOW (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_CLOSE_WINDOW)
+   (timestamp :initarg :timestamp :type xcb:CARD32)
+   (source-indication :initarg :source-indication :type xcb:CARD32)))
+
+;; _NET_MOVERESIZE_WINDOW
+(defclass xcb:ewmh:_NET_MOVERESIZE_WINDOW (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_MOVERESIZE_WINDOW)
+   (gravity-and-flags :initarg :gravity-and-flags :type xcb:CARD32)
+   (x :initarg :x :type xcb:CARD32)
+   (y :initarg :y :type xcb:CARD32)
+   (width :initarg :width :type xcb:CARD32)
+   (height :initarg :height :type xcb:CARD32)))
+
+;; _NET_WM_MOVERESIZE
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPLEFT 0)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOP 1)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_RIGHT 3)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOM 5)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_LEFT 7)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_MOVE 8)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_SIZE_KEYBOARD 9)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_MOVE_KEYBOARD 10)
+(defconst xcb:ewmh:_NET_WM_MOVERESIZE_CANCEL 11)
+;;
+(defclass xcb:ewmh:_NET_WM_MOVERESIZE (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_WM_MOVERESIZE)
+   (x-root :initarg :x-root :type xcb:CARD32)
+   (y-root :initarg :y-root :type xcb:CARD32)
+   (direction :initarg :direction :type xcb:CARD32)
+   (button :initarg :button :type xcb:CARD32)
+   (source-indication :initarg :source-indication :type xcb:CARD32)))
+
+;; _NET_RESTACK_WINDOW
+(defclass xcb:ewmh:_NET_RESTACK_WINDOW (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_RESTACK_WINDOW)
+   (source-indication :initarg :source-indication :type xcb:CARD32)
+   (sibling :initarg :sibling :type xcb:WINDOW)
+   (detail :initarg :detail :type xcb:CARD32)))
+
+;; _NET_REQUEST_FRAME_EXTENTS
+(defclass xcb:ewmh:_NET_REQUEST_FRAME_EXTENTS (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_REQUEST_FRAME_EXTENTS)))
+
+;;;; Application Window Properties
+
+;; _NET_WM_NAME
+(defclass xcb:ewmh:get-_NET_WM_NAME (xcb:ewmh:-GetProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_NAME)))
+(defclass xcb:ewmh:get-_NET_WM_NAME~reply (xcb:ewmh:-GetProperty-utf8~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_NAME (xcb:ewmh:-ChangeProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_NAME)))
+
+;; _NET_WM_VISIBLE_NAME
+(defclass xcb:ewmh:get-_NET_WM_VISIBLE_NAME (xcb:ewmh:-GetProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_VISIBLE_NAME)))
+(defclass xcb:ewmh:get-_NET_WM_VISIBLE_NAME~reply
+  (xcb:ewmh:-GetProperty-utf8~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_VISIBLE_NAME (xcb:ewmh:-ChangeProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_VISIBLE_NAME)))
+
+;; _NET_WM_ICON_NAME
+(defclass xcb:ewmh:get-_NET_WM_ICON_NAME (xcb:ewmh:-GetProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_ICON_NAME)))
+(defclass xcb:ewmh:get-_NET_WM_ICON_NAME~reply
+  (xcb:ewmh:-GetProperty-utf8~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_ICON_NAME (xcb:ewmh:-ChangeProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_ICON_NAME)))
+
+;; _NET_WM_VISIBLE_ICON_NAME
+(defclass xcb:ewmh:get-_NET_WM_VISIBLE_ICON_NAME (xcb:ewmh:-GetProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_VISIBLE_ICON_NAME)))
+(defclass xcb:ewmh:get-_NET_WM_VISIBLE_ICON_NAME~reply
+  (xcb:ewmh:-GetProperty-utf8~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_VISIBLE_ICON_NAME
+  (xcb:ewmh:-ChangeProperty-utf8)
+  ((property :initform xcb:Atom:_NET_WM_VISIBLE_ICON_NAME)))
+
+;; _NET_WM_DESKTOP
+(defclass xcb:ewmh:get-_NET_WM_DESKTOP (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_DESKTOP~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_DESKTOP (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_DESKTOP)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_WM_DESKTOP (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_WM_DESKTOP)
+   (new-desktop :initarg :new-desktop :type xcb:CARD32)
+   (source-indication :initarg :source-indication :type xcb:CARD32)))
+
+;; _NET_WM_WINDOW_TYPE
+(defclass xcb:ewmh:get-_NET_WM_WINDOW_TYPE (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WM_WINDOW_TYPE)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:get-_NET_WM_WINDOW_TYPE~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_WINDOW_TYPE (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WM_WINDOW_TYPE)
+   (type :initform xcb:Atom:ATOM)))
+
+;; _NET_WM_STATE
+(defconst xcb:ewmh:_NET_WM_STATE_REMOVE 0)
+(defconst xcb:ewmh:_NET_WM_STATE_ADD 1)
+(defconst xcb:ewmh:_NET_WM_STATE_TOGGLE 2)
+;;
+(defclass xcb:ewmh:get-_NET_WM_STATE (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WM_STATE)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:get-_NET_WM_STATE~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_STATE (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WM_STATE)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:_NET_WM_STATE (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:_NET_WM_STATE)
+   (action :initarg :action :type xcb:CARD32)
+   (first-property :initarg :first-property :type xcb:CARD32)
+   (second-property :initarg :second-property :type xcb:CARD32)
+   (source-indication :initarg :source-indication :type xcb:CARD32)))
+
+;; _NET_WM_ALLOWED_ACTIONS
+(defclass xcb:ewmh:get-_NET_WM_ALLOWED_ACTIONS (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WM_ALLOWED_ACTIONS)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:get-_NET_WM_ALLOWED_ACTIONS~reply
+  (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_ALLOWED_ACTIONS (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WM_ALLOWED_ACTIONS)
+   (type :initform xcb:Atom:ATOM)))
+
+;; _NET_WM_STRUT
+(defclass xcb:ewmh:-_NET_WM_STRUT ()
+  ((left :initarg :left :type xcb:-ignore)
+   (right :initarg :right :type xcb:-ignore)
+   (top :initarg :top :type xcb:-ignore)
+   (bottom :initarg :bottom :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_WM_STRUT (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_WM_STRUT)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 4)))
+(defclass xcb:ewmh:get-_NET_WM_STRUT~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_WM_STRUT)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_STRUT
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_WM_STRUT)
+  ((property :initform xcb:Atom:_NET_WM_STRUT)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_STRUT_PARTIAL
+(defclass xcb:ewmh:-_NET_WM_STRUT_PARTIAL ()
+  ((left :initarg :left :type xcb:-ignore)
+   (right :initarg :right :type xcb:-ignore)
+   (top :initarg :top :type xcb:-ignore)
+   (bottom :initarg bottom :type xcb:-ignore)
+   (left-start-y :initarg :left-start-y :type xcb:-ignore)
+   (left-end-y :initarg :left-end-y :type xcb:-ignore)
+   (right-start-y :initarg :right-start-y :type xcb:-ignore)
+   (right-end-y :initarg :right-end-y :type xcb:-ignore)
+   (top-start-x :initarg :top-start-x :type xcb:-ignore)
+   (top-end-x :initarg :top-end-x :type xcb:-ignore)
+   (bottom-start-x :initarg :bottom-start-x:type xcb:-ignore)
+   (bottom-end-x :initarg :bottom-end-x :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_WM_STRUT_PARTIAL (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_WM_STRUT_PARTIAL)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 12)))
+(defclass xcb:ewmh:get-_NET_WM_STRUT_PARTIAL~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_WM_STRUT_PARTIAL)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_STRUT_PARTIAL
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_WM_STRUT_PARTIAL)
+  ((property :initform xcb:Atom:_NET_WM_STRUT_PARTIAL)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_ICON_GEOMETRY
+(defclass xcb:ewmh:-_NET_WM_ICON_GEOMETRY ()
+  ((x :initarg :x :type xcb:-ignore)
+   (y :initarg :y :type xcb:-ignore)
+   (width :initarg :width :type xcb:-ignore)
+   (height :initarg :height :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_WM_ICON_GEOMETRY (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_WM_ICON_GEOMETRY)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 4)))
+(defclass xcb:ewmh:get-_NET_WM_ICON_GEOMETRY~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_WM_ICON_GEOMETRY)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_ICON_GEOMETRY
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_WM_ICON_GEOMETRY)
+  ((property :initform xcb:Atom:_NET_WM_ICON_GEOMETRY)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_ICON
+(defclass xcb:ewmh:-get-_NET_WM_ICON (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WM_ICON)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:-get-_NET_WM_ICON~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:-set-_NET_WM_ICON (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WM_ICON)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_PID
+(defclass xcb:ewmh:get-_NET_WM_PID (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_PID)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_PID~reply (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_PID (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_PID)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_HANDLED_ICONS
+(defclass xcb:ewmh:get-_NET_WM_HANDLED_ICONS (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_HANDLED_ICONS)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_HANDLED_ICONS~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_HANDLED_ICONS (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_HANDLED_ICONS)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_USER_TIME
+(defclass xcb:ewmh:get-_NET_WM_USER_TIME (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_USER_TIME)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_USER_TIME~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_USER_TIME (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_USER_TIME)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_USER_TIME_WINDOW
+(defclass xcb:ewmh:get-_NET_WM_USER_TIME_WINDOW (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_USER_TIME_WINDOW)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_USER_TIME_WINDOW~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_USER_TIME_WINDOW
+  (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_USER_TIME_WINDOW)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_FRAME_EXTENTS
+(defclass xcb:ewmh:-_NET_FRAME_EXTENTS ()
+  ((left :initarg :left :type xcb:-ignore)
+   (right :initarg :right :type xcb:-ignore)
+   (top :initarg :top :type xcb:-ignore)
+   (bottom :initarg :bottom :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_FRAME_EXTENTS (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_FRAME_EXTENTS)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 4)))
+(defclass xcb:ewmh:get-_NET_FRAME_EXTENTS~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_FRAME_EXTENTS)
+  nil)
+(defclass xcb:ewmh:set-_NET_FRAME_EXTENTS
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_FRAME_EXTENTS)
+  ((property :initform xcb:Atom:_NET_FRAME_EXTENTS)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_OPAQUE_REGION
+(defclass xcb:ewmh:get-_NET_WM_OPAQUE_REGION (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:_NET_WM_OPAQUE_REGION)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:ewmh:get-_NET_WM_OPAQUE_REGION~reply
+  (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_OPAQUE_REGION (xcb:icccm:-ChangeProperty)
+  ((property :initform xcb:Atom:_NET_WM_OPAQUE_REGION)
+   (type :initform xcb:Atom:ATOM)))
+
+;; _NET_WM_BYPASS_COMPOSITOR
+(defclass xcb:ewmh:get-_NET_WM_BYPASS_COMPOSITOR
+  (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_BYPASS_COMPOSITOR)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:get-_NET_WM_BYPASS_COMPOSITOR~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_BYPASS_COMPOSITOR
+  (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:_NET_WM_BYPASS_COMPOSITOR)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;;;; Window Manager Protocols
+
+;; _NET_WM_PING
+(defclass xcb:ewmh:_NET_WM_PING (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:WM_PROTOCOLS)
+   (protocol :initform xcb:Atom:_NET_WM_PING :type xcb:CARD32)
+   (timestamp :initarg :timestamp :type xcb:CARD32)
+   (client-window :initarg :client-window :type xcb:WINDOW)))
+
+;; _NET_WM_SYNC_REQUEST
+(defclass xcb:ewmh:_NET_WM_SYNC_REQUEST (xcb:ewmh:-ClientMessage)
+  ((type :initform xcb:Atom:WM_PROTOCOLS)
+   (protocol :initform xcb:Atom:_NET_WM_SYNC_REQUEST :type xcb:CARD32)
+   (timestamp :initarg :timestamp :type xcb:CARD32)
+   (low :initarg :low :type xcb:CARD32)
+   (high :initarg :high :type xcb:CARD32)))
+
+;; _NET_WM_SYNC_REQUEST_COUNTER
+(defclass xcb:ewmh:-_NET_WM_SYNC_REQUEST_COUNTER ()
+  ((low :initarg :low :type xcb:-ignore)
+   (high :initarg :hight :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_WM_SYNC_REQUEST_COUNTER
+  (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_WM_SYNC_REQUEST_COUNTER)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 2)))
+(defclass xcb:ewmh:get-_NET_WM_SYNC_REQUEST_COUNTER~reply
+  (xcb:icccm:-GetProperty-explicit~reply
+   xcb:ewmh:-_NET_WM_SYNC_REQUEST_COUNTER)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_SYNC_REQUEST_COUNTER
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_WM_SYNC_REQUEST_COUNTER)
+  ((property :initform xcb:Atom:_NET_WM_SYNC_REQUEST_COUNTER)
+   (type :initform xcb:Atom:CARDINAL)))
+
+;; _NET_WM_FULLSCREEN_MONITORS
+(defclass xcb:ewmh:-_NET_WM_FULLSCREEN_MONITORS ()
+  ((top :initarg :top :type xcb:-ignore)
+   (bottom :initarg :bottom :type xcb:-ignore)
+   (left :initarg :left :type xcb:-ignore)
+   (right :initarg :right :type xcb:-ignore)))
+;;
+(defclass xcb:ewmh:get-_NET_WM_FULLSCREEN_MONITORS
+  (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:_NET_WM_FULLSCREEN_MONITORS)
+   (type :initform xcb:Atom:CARDINAL)
+   (long-length :initform 4)))
+(defclass xcb:ewmh:get-_NET_WM_FULLSCREEN_MONITORS~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:ewmh:-_NET_WM_FULLSCREEN_MONITORS)
+  nil)
+(defclass xcb:ewmh:set-_NET_WM_FULLSCREEN_MONITORS
+  (xcb:icccm:-ChangeProperty-explicit xcb:ewmh:-_NET_WM_FULLSCREEN_MONITORS)
+  ((property :initform xcb:Atom:_NET_WM_FULLSCREEN_MONITORS)
+   (type :initform xcb:Atom:CARDINAL)))
+(defclass xcb:ewmh:_NET_WM_FULLSCREEN_MONITORS
+  (xcb:ewmh:-ClientMessage xcb:ewmh:-_NET_WM_FULLSCREEN_MONITORS)
+  ((type :initform xcb:Atom:_NET_WM_FULLSCREEN_MONITORS)))
+
+;;;; Other Properties
+
+;;;; Misc.
+
+(defconst xcb:ewmh:source-indication:none 0)
+(defconst xcb:ewmh:source-indication:normal 1)
+(defconst xcb:ewmh:source-indication:other 2)
+
+
+
+(provide 'xcb-ewmh)
+
+;;; xcb-ewmh.el ends here
diff --git a/xcb-icccm.el b/xcb-icccm.el
new file mode 100644
index 0000000..0fabbc8
--- /dev/null
+++ b/xcb-icccm.el
@@ -0,0 +1,540 @@
+;;; xcb-icccm.el --- Inter-Client Communication  -*- lexical-binding: t -*-
+;;;                  Conventions Manual
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library implement ICCCM the same way as xcb/util-wm.
+
+;; Usage tips:
+;; + Do not forget to call `xcb:icccm:init' for _every_ connection using
+;;   this library.
+;; + Use `xcb:icccm:SendEvent' instead of `xcb:SendEvent' to send client
+;;   messages defined in this library.
+
+;; Todo:
+;; + Interned atoms are actually connection-dependent. Currently they are
+;;   simply saved as global variables.
+
+;; References:
+;; + ICCCM (http://www.x.org/releases/X11R7.7/doc/xorg-docs/icccm/icccm.txt)
+;; + xcb/util-wm (git://anongit.freedesktop.org/xcb/util-wm)
+
+;;; Code:
+
+(require 'xcb-xproto)
+
+;;;; ICCCM atoms
+
+(defconst xcb:icccm:-atoms
+  '(UTF8_STRING COMPOUND_TEXT TEXT C_STRING
+    WM_PROTOCOLS WM_TAKE_FOCUS WM_DELETE_WINDOW WM_STATE)
+  "Atoms involved in ICCCM.")
+
+(cl-defmethod xcb:icccm:init ((obj xcb:connection))
+  "Initialize ICCCM module.
+
+This method must be called before using any other method in this module."
+  (xcb:icccm:intern-atoms obj xcb:icccm:-atoms))
+
+(cl-defmethod xcb:icccm:intern-atoms ((obj xcb:connection) atoms)
+  "Intern the X atoms listed in the list AOTMS.
+
+The value of these atoms will be available in `xcb:Atom' namespace."
+  (dolist (atom atoms)
+    (let ((name (symbol-name atom))
+          reply)
+      (unless (boundp atom)
+        (setq reply (xcb:+request-unchecked+reply obj
+                        (make-instance 'xcb:InternAtom
+                                       :only-if-exists 0
+                                       :name-len (length name)
+                                       :name name)))
+        (eval `(defvar ,(intern (concat "xcb:Atom:" name)) ;add prefix
+                 (slot-value ,reply 'atom)))))))
+
+;;;; Client message
+
+(defclass xcb:icccm:SendEvent (xcb:SendEvent)
+  ((propagate :initform 0)
+   (event-mask :initform xcb:EventMask:NoEvent))
+  :documentation "A fork of `xcb:SendEvent' to send ICCCM client messages.")
+
+(defclass xcb:icccm:--ClientMessage ()
+  ((data :type xcb:-ignore))            ;shadowed slot
+  :documentation "To shadow the data slot in `xcb:SendEvent'.")
+;;
+(defclass xcb:icccm:-ClientMessage
+  (xcb:icccm:--ClientMessage xcb:ClientMessage)
+  ((format :initform 32)
+   (type :initform xcb:Atom:WM_PROTOCOLS)
+   (protocol :type xcb:ATOM)                  ;new slot
+   (time :initarg :time :type xcb:TIMESTAMP)  ;new slot
+   (pad~0 :initform 12 :type xcb:-pad))       ;new slot
+  :documentation "An ICCCM client message with data slot replaced by
+protocol and time.")
+
+(defclass xcb:icccm:WM_DELETE_WINDOW (xcb:icccm:-ClientMessage)
+  ((protocol :initform xcb:Atom:WM_DELETE_WINDOW)
+   (time :initform xcb:Time:CurrentTime))
+  :documentation "Delete a window using the WM_DELETE_WINDOW client message.")
+
+(defclass xcb:icccm:WM_TAKE_FOCUS (xcb:icccm:-ClientMessage)
+  ((protocol :initform xcb:Atom:WM_TAKE_FOCUS))
+  :documentation "Set a focus using the WM_TAKE_FOCUS client message.
+
+A valid timestamp (rather than `xcb:Time:CurrentTime') must be supplied.")
+
+;;;; Abstract classes for getting/changing (plain) list properties
+
+(defclass xcb:icccm:-GetProperty (xcb:GetProperty)
+  ((delete :initform 0)
+   (long-offset :initform 0)
+   (long-length :initform 1000000000))  ;as long as possible
+  :documentation "Get an ICCCM property (request part).")
+
+(defclass xcb:icccm:-GetProperty~reply (xcb:GetProperty~reply)
+  nil
+  :documentation "Get an ICCCM property (reply part).")
+;;
+(cl-defmethod xcb:unmarshal ((obj xcb:icccm:-GetProperty~reply) byte-array)
+  "Fill in the fields in the reply of ICCCM GetProperty request OBJ
+according to BYTE-ARRAY.
+
+This method automatically format the value as 8, 16 or 32 bits array."
+  (let ((retval (cl-call-next-method obj byte-array))
+        tmp)
+    (with-slots (~lsb format bytes-after value-len value) obj
+      (if (= 0 value-len)
+          (setf value nil)              ;no available value
+        (setq tmp (substring value
+                             0          ;long-offset
+                             (- (length value) bytes-after))
+              value nil)
+        (pcase format
+          (8
+           (cl-assert (= value-len (length tmp)))
+           (setf value tmp))
+          (16
+           (cl-assert (= (* 2 value-len) (length tmp)))
+           (if ~lsb
+               (dotimes (i value-len)
+                 (setf value (vconcat value (vector (xcb:-unpack-u2-lsb tmp))))
+                 (setq tmp (substring tmp 2)))
+             (dotimes (i value-len)
+               (setf value (vconcat value (vector (xcb:-unpack-u2 tmp))))
+               (setq tmp (substring tmp 2)))))
+          (32
+           (cl-assert (= (* 4 value-len) (length tmp)))
+           (if ~lsb
+               (dotimes (i value-len)
+                 (setf value (vconcat value (vector (xcb:-unpack-u4-lsb tmp))))
+                 (setq tmp (substring tmp 4)))
+             (dotimes (i value-len)
+               (setf value (vconcat value (vector (xcb:-unpack-u4 tmp))))
+               (setq tmp (substring tmp 4)))))
+          (_ (cl-assert nil)))))
+    retval))
+
+(defclass xcb:icccm:-ChangeProperty (xcb:ChangeProperty)
+  ((mode :initform xcb:PropMode:Replace)
+   (format :initform 32)
+   (data :initform nil))
+  :documentation "Change an ICCCM property.")
+;;
+(cl-defmethod xcb:marshal ((obj xcb:icccm:-ChangeProperty))
+  "Return the byte-array representation of an ICCCM ChangeProperty request.
+
+This method automatically sets the data length."
+  (with-slots (~lsb format data-len data) obj
+    (setf data-len (length data))
+    (setf data
+          (pcase format
+            (8 data)
+            (16 (mapconcat (lambda (i) (if ~lsb (xcb:-pack-u2-lsb i)
+                                         (xcb:-pack-u2 i)))
+                           data []))
+            (32 (mapconcat (lambda (i) (if ~lsb (xcb:-pack-u4-lsb i)
+                                         (xcb:-pack-u4 i)))
+                           data []))
+            (_ (cl-assert nil)))))
+  (cl-call-next-method obj))
+
+;;;; Abstract classes for getting/changing text properties
+
+(defclass xcb:icccm:-GetProperty-text (xcb:icccm:-GetProperty)
+  ((type :initform xcb:GetPropertyType:Any))
+  :documentation "Get an ICCCM text property (request part).")
+
+(defclass xcb:icccm:-GetProperty-text~reply (xcb:icccm:-GetProperty~reply)
+  nil
+  :documentation "Get an ICCCM text property (reply part).")
+;;
+(cl-defmethod xcb:unmarshal ((obj xcb:icccm:-GetProperty-text~reply)
+                             byte-array)
+  "Fill in the fields in the reply of ICCCM GetProperty (text) request OBJ
+according to BYTE-ARRAY.
+
+This method automatically decodes the value (as string)."
+  (let* ((retval (cl-call-next-method obj byte-array)))
+    (with-slots (format type value) obj
+      (when (symbolp type) (setq type (symbol-value type)))
+      (when (and value (= format 8))
+        (setf value
+              (decode-coding-string
+               (apply 'unibyte-string (append value nil))
+               (cond ((eq type xcb:Atom:UTF8_STRING) 'utf-8)
+                     ((eq type xcb:Atom:STRING) 'iso-latin-1)
+                     ((eq type xcb:Atom:COMPOUND_TEXT)
+                      'compound-text-with-extensions)
+                     ((or (eq type xcb:Atom:TEXT) (eq type xcb:Atom:C_STRING))
+                      'no-conversion)
+                     (t (error "[XELB:ICCCM] Unsupported encoding: %d"
+                               type)))))))
+    retval))
+
+(defclass xcb:icccm:-ChangeProperty-text (xcb:icccm:-ChangeProperty)
+  ((type :initform xcb:Atom:STRING)     ;may be changed
+   (format :initform 8))
+  :documentation "Change an ICCCM text property.")
+;;
+(cl-defmethod xcb:marshal ((obj xcb:icccm:-ChangeProperty-text))
+  "Return the byte-array representation of an ICCCM ChangeProperty (text)
+request OBJ.
+
+This method automatically encodes the data (which is a string)."
+  (with-slots (type data) obj
+    (when (symbolp type) (setq type (symbol-value type)))
+    (setf data
+          (vconcat
+           (encode-coding-string
+            data
+            (cond ((eq type xcb:Atom:UTF8_STRING) 'utf-8)
+                  ((eq type xcb:Atom:STRING) 'iso-latin-1)
+                  ((eq type xcb:Atom:COMPOUND_TEXT)
+                   'compound-text-with-extensions)
+                  ((or (eq type xcb:Atom:TEXT) (eq type xcb:Atom:C_STRING))
+                   'no-conversion)
+                  (t (error "[XELB:ICCCM] Unsupported encoding: %d" type)))))))
+  (cl-call-next-method obj))
+
+;;;; Abstract classes for getting/changing single field properties
+
+(defclass xcb:icccm:-GetProperty-single (xcb:icccm:-GetProperty)
+  nil
+  :documentation "Get an ICCCM single-valued property (request part).")
+
+(defclass xcb:icccm:-GetProperty-single~reply (xcb:icccm:-GetProperty~reply)
+  nil
+  :documentation "Get a single-valued ICCCM property (reply part).")
+;;
+(cl-defmethod xcb:unmarshal ((obj xcb:icccm:-GetProperty-single~reply)
+                             byte-array)
+  "Fill in the fields in the reply of an ICCCM GetProperty (single-valued)
+request OBJ according to BYTE-ARRAY."
+  (let ((retval (cl-call-next-method obj byte-array)))
+    (with-slots (value) obj
+      (when value
+        (cl-assert (= 1 (length value)))
+        (setf value (elt value 0))))
+    retval))
+
+(defclass xcb:icccm:-ChangeProperty-single (xcb:icccm:-ChangeProperty)
+  nil
+  :documentation "Change a single-valued ICCCM property.")
+;;
+(cl-defmethod xcb:marshal ((obj xcb:icccm:-ChangeProperty-single))
+  "Return the byte-array representation of a single-valued ICCCM ChangeProperty
+request OBJ."
+  (with-slots (data) obj
+    (setf data `[,data]))
+  (cl-call-next-method obj))
+
+;;;; Abstract classes for getting/changing property with explicit fields
+
+(defclass xcb:icccm:-GetProperty-explicit (xcb:icccm:-GetProperty)
+  nil
+  :documentation "Get an ICCCM property whose fields are explicitly listed out
+(request part).")
+
+(defclass xcb:icccm:-GetProperty-explicit~reply (xcb:icccm:-GetProperty~reply)
+  nil
+  :documentation "Get an ICCCM property whose fields are explicitly listed out
+(reply part).")
+;;
+(cl-defmethod xcb:unmarshal ((obj xcb:icccm:-GetProperty-explicit~reply)
+                             byte-array)
+  "Fill in the reply of an ICCCM GetProperty request whose fields are
+explicitly listed out."
+  (let* ((retval (cl-call-next-method obj byte-array))
+         (slots-orig (eieio-class-slots xcb:icccm:-GetProperty~reply))
+         (slots (eieio-class-slots (eieio-object-class obj)))
+         (slots (nthcdr (length slots-orig) slots))
+         (value (slot-value obj 'value)))
+    (unless value (setq value (make-vector (length slots) nil))) ;fallback
+    (cl-assert (= (length value) (length slots)))
+    ;; Set explicit fields from value field
+    (dotimes (i (length slots))
+      (setf (slot-value obj (cl--slot-descriptor-name (elt slots i)))
+            (elt value i)))
+    retval))
+
+(defclass xcb:icccm:-ChangeProperty-explicit (xcb:icccm:-ChangeProperty)
+  ((format :initform 32))
+  :documentation "Change an ICCCM property whose fields are explicitly listed
+out.")
+;;
+(cl-defmethod xcb:marshal ((obj xcb:icccm:-ChangeProperty-explicit))
+  "Return the byte-array representation of an ICCCM ChangeProperty request
+whose fields are explicitly listed out."
+  (let* ((slots-orig (eieio-class-slots xcb:icccm:-ChangeProperty))
+         (slots (eieio-class-slots (eieio-object-class obj)))
+         (slots (nthcdr (length slots-orig) slots)))
+    ;; Set data field from explicit fields
+    (setf (slot-value obj 'data)
+          (mapconcat (lambda (slot)
+                       (list (slot-value obj (cl--slot-descriptor-name slot))))
+                     slots []))
+    (cl-call-next-method obj)))
+
+;;;; Client Properties
+
+;; WM_NAME
+(defclass xcb:icccm:get-WM_NAME (xcb:icccm:-GetProperty-text)
+  ((property :initform xcb:Atom:WM_NAME)))
+(defclass xcb:icccm:get-WM_NAME~reply (xcb:icccm:-GetProperty-text~reply)
+  nil)
+(defclass xcb:icccm:set-WM_NAME (xcb:icccm:-ChangeProperty-text)
+  ((property :initform xcb:Atom:WM_NAME)))
+
+;; WM_ICON_NAME
+(defclass xcb:icccm:get-WM_ICON_NAME (xcb:icccm:-GetProperty-text)
+  ((property :initform xcb:Atom:WM_ICON_NAME)))
+(defclass xcb:icccm:get-WM_ICON_NAME~reply (xcb:icccm:-GetProperty-text~reply)
+  nil)
+(defclass xcb:icccm:set-WM_ICON_NAME (xcb:icccm:-ChangeProperty-text)
+  ((property :initform xcb:Atom:WM_ICON_NAME)))
+
+;; WM_SIZE_HINTS
+(defconst xcb:icccm:WM_SIZE_HINTS:USPosition  1)
+(defconst xcb:icccm:WM_SIZE_HINTS:USSize 2)
+(defconst xcb:icccm:WM_SIZE_HINTS:PPosition 4)
+(defconst xcb:icccm:WM_SIZE_HINTS:PSize 8)
+(defconst xcb:icccm:WM_SIZE_HINTS:PMinSize 16)
+(defconst xcb:icccm:WM_SIZE_HINTS:PMaxSize 32)
+(defconst xcb:icccm:WM_SIZE_HINTS:PResizeInc 64)
+(defconst xcb:icccm:WM_SIZE_HINTS:PAspect 128)
+(defconst xcb:icccm:WM_SIZE_HINTS:PBaseSize 256)
+(defconst xcb:icccm:WM_SIZE_HINTS:PWinGravity 512)
+;;
+(defclass xcb:icccm:-WM_SIZE_HINTS ()
+  ((flags :initarg :flags :initform 0 :type xcb:-ignore)
+   (x :initarg :x :initform 0 :type xcb:-ignore)
+   (y :initarg :y :initform 0 :type xcb:-ignore)
+   (width :initarg :width :initform 0 :type xcb:-ignore)
+   (height :initarg :height :initform 0 :type xcb:-ignore)
+   (min-width :initarg :min-width :initform 0 :type xcb:-ignore)
+   (min-height :initarg :min-height :initform 0 :type xcb:-ignore)
+   (max-width :initarg :max-width :initform 0 :type xcb:-ignore)
+   (max-height :initarg :max-height :initform 0 :type xcb:-ignore)
+   (width-inc :initarg :width-inc :initform 0 :type xcb:-ignore)
+   (height-inc :initarg :height-inc :initform 0 :type xcb:-ignore)
+   (min-aspect-num :initarg :min-aspect-num :initform 0 :type xcb:-ignore)
+   (min-aspect-den :initarg :min-aspect-den :initform 0 :type xcb:-ignore)
+   (max-aspect-num :initarg :max-aspect-num :initform 0 :type xcb:-ignore)
+   (max-aspect-den :initarg :max-aspect-den :initform 0 :type xcb:-ignore)
+   (base-width :initarg :base-width :initform 0 :type xcb:-ignore)
+   (base-height :initarg :base-height :initform 0 :type xcb:-ignore)
+   (win-gravity :initarg :win-gravity :initform 0 :type xcb:-ignore)))
+;;
+(defclass xcb:icccm:get-WM_SIZE_HINTS (xcb:icccm:-GetProperty-explicit)
+  ((type :initform xcb:Atom:WM_SIZE_HINTS)
+   (long-length :initform 18)))         ;fixed
+(defclass xcb:icccm:get-WM_SIZE_HINTS~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:icccm:-WM_SIZE_HINTS)
+  nil)
+(defclass xcb:icccm:set-WM_SIZE_HINTS
+  (xcb:icccm:-ChangeProperty-explicit xcb:icccm:-WM_SIZE_HINTS)
+  ((type :initform xcb:Atom:WM_SIZE_HINTS)))
+
+;; WM_NORMAL_HINTS
+(defclass xcb:icccm:get-WM_NORMAL_HINTS (xcb:icccm:get-WM_SIZE_HINTS)
+  ((property :initform xcb:Atom:WM_NORMAL_HINTS)))
+(defclass xcb:icccm:get-WM_NORMAL_HINTS~reply
+  (xcb:icccm:get-WM_SIZE_HINTS~reply)
+  nil)
+(defclass xcb:icccm:set-WM_NORMAL_HINTS (xcb:icccm:set-WM_SIZE_HINTS)
+  ((property :initform xcb:Atom:WM_NORMAL_HINTS)))
+
+;; WM_HINTS
+(defconst xcb:icccm:WM_HINTS:InputHint 1)
+(defconst xcb:icccm:WM_HINTS:StateHint 2)
+(defconst xcb:icccm:WM_HINTS:IconPixmapHint 4)
+(defconst xcb:icccm:WM_HINTS:IconWindowHint 8)
+(defconst xcb:icccm:WM_HINTS:IconPositionHint 16)
+(defconst xcb:icccm:WM_HINTS:IconMaskHint 32)
+(defconst xcb:icccm:WM_HINTS:WindowGroupHint 64)
+(defconst xcb:icccm:WM_HINTS:MessageHint 128)
+(defconst xcb:icccm:WM_HINTS:UrgencyHint 256)
+;;
+(defclass xcb:icccm:-WM_HINTS ()
+  ((flags :initarg :flags :initform 0 :type xcb:-ignore)
+   (input :initarg :input :initform 0 :type xcb:-ignore)
+   (initial-state :initarg :initial-state :initform 0 :type xcb:-ignore)
+   (icon-pixmap :initarg :icon-pixmap :initform 0 :type xcb:-ignore)
+   (icon-window :initarg :icon-window :initform 0 :type xcb:-ignore)
+   (icon-x :initarg :icon-x :initform 0 :type xcb:-ignore)
+   (icon-y :initarg :icon-y :initform 0 :type xcb:-ignore)
+   (icon-mask :initarg :icon-mask :initform 0 :type xcb:-ignore)
+   (window-group :initarg :window-group :initform 0 :type xcb:-ignore)))
+;;
+(defclass xcb:icccm:get-WM_HINTS (xcb:icccm:-GetProperty-explicit)
+  ;; (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:WM_HINTS)
+   (type :initform xcb:Atom:WM_HINTS)
+   (long-length :initform 9)))          ;fixed
+(defclass xcb:icccm:get-WM_HINTS~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:icccm:-WM_HINTS)
+  nil)
+(defclass xcb:icccm:set-WM_HINTS
+  (xcb:icccm:-ChangeProperty-explicit xcb:icccm:-WM_HINTS)
+  ((property :initform xcb:Atom:WM_HINTS)
+   (type :initform xcb:Atom:WM_HINTS)))
+
+;; WM_CLASS
+(defclass xcb:icccm:get-WM_CLASS (xcb:icccm:-GetProperty-text)
+  ((property :initform xcb:Atom:WM_CLASS)
+   (type :initform xcb:Atom:STRING)))
+(defclass xcb:icccm:get-WM_CLASS~reply (xcb:icccm:-GetProperty-text~reply)
+  ((instance-name :type xcb:-ignore)
+   (class-name :type xcb:-ignore)))
+;;
+(cl-defmethod xcb:unmarshal ((obj xcb:icccm:get-WM_CLASS~reply) byte-array)
+  ;; Split value into instance & class names
+  (let* ((retval (cl-call-next-method obj byte-array))
+         (tmp (slot-value obj 'value))
+         (tmp (if tmp (split-string tmp "\0" t) '(nil nil))))
+    (with-slots (instance-name class-name) obj
+      (setf instance-name (car tmp)
+            class-name (cadr tmp)))
+    retval))
+;;
+(defclass xcb:icccm:set-WM_CLASS (xcb:icccm:-ChangeProperty-text)
+  ((property :initform xcb:Atom:WM_CLASS)
+   (type :initform xcb:Atom:STRING)
+   (instance-name :initarg :instance-name :type xcb:-ignore)
+   (class-name :initarg :class-name :type xcb:-ignore)))
+;;
+(cl-defmethod xcb:marshal ((obj xcb:icccm:set-WM_CLASS))
+  (with-slots (data instance-name class-name) obj
+    (setf data (concat instance-name "\0" class-name "\0")))
+  (cl-call-next-method obj))
+
+;; WM_TRANSIENT_FOR
+(defclass xcb:icccm:get-WM_TRANSIENT_FOR (xcb:icccm:-GetProperty-single)
+  ((property :initform xcb:Atom:WM_TRANSIENT_FOR)
+   (type :initform xcb:Atom:WINDOW)
+   (long-length :initform 1)))
+(defclass xcb:icccm:get-WM_TRANSIENT_FOR~reply
+  (xcb:icccm:-GetProperty-single~reply)
+  nil)
+(defclass xcb:icccm:set-WM_TRANSIENT_FOR (xcb:icccm:-ChangeProperty-single)
+  ((property :initform xcb:Atom:WM_TRANSIENT_FOR)))
+
+;; WM_PROTOCOLS
+(defclass xcb:icccm:get-WM_PROTOCOLS (xcb:icccm:-GetProperty)
+  ((property :initform xcb:Atom:WM_PROTOCOLS)
+   (type :initform xcb:Atom:ATOM)))
+(defclass xcb:icccm:get-WM_PROTOCOLS~reply (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:icccm:set-WM_PROTOCOLS (xcb:icccm:-ChangeProperty)
+  ((type :initform xcb:Atom:ATOM)
+   (format :initform 32)))
+
+;; WM_COLORMAP_WINDOWS
+(defclass xcb:icccm:get-WM_COLORMAP_WINDOWS (xcb:icccm:-GetProperty)
+  ((type :initform xcb:Atom:WINDOW)))
+(defclass xcb:icccm:get-WM_COLORMAP_WINDOWS~reply
+  (xcb:icccm:-GetProperty~reply)
+  nil)
+(defclass xcb:icccm:set-WM_COLORMAP_WINDOWS (xcb:icccm:-ChangeProperty)
+  ((type :initform xcb:Atom:WINDOW)
+   (format :initform 32)))
+
+;; WM_CLIENT_MACHINE
+(defclass xcb:icccm:get-WM_CLIENT_MACHINE (xcb:icccm:-GetProperty-text)
+  ((property :initform xcb:Atom:WM_CLIENT_MACHINE)))
+(defclass xcb:icccm:get-WM_CLIENT_MACHINE~reply
+  (xcb:icccm:-GetProperty-text~reply)
+  nil)
+(defclass xcb:icccm:set-WM_CLIENT_MACHINE (xcb:icccm:-ChangeProperty-text)
+  ((property :initform xcb:Atom:WM_CLIENT_MACHINE)))
+
+;;;; Window Manager Properties
+
+;; WM_STATE
+(defconst xcb:icccm:WM_STATE:WithdrawnState 0)
+(defconst xcb:icccm:WM_STATE:NormalState 1)
+(defconst xcb:icccm:WM_STATE:IconicState 3)
+;;
+(defclass xcb:icccm:-WM_STATE ()
+  ((state :initarg :state :type xcb:-ignore)
+   (icon :initarg :icon :type xcb:-ignore)))
+;;
+(defclass xcb:icccm:get-WM_STATE (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:WM_STATE)
+   (type :initform xcb:Atom:WM_STATE)
+   (long-length :initform 2)))
+(defclass xcb:icccm:get-WM_STATE~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:icccm:-WM_STATE)
+  nil)
+(defclass xcb:icccm:set-WM_STATE
+  (xcb:icccm:-ChangeProperty-explicit xcb:icccm:-WM_STATE)
+  ((property :initform xcb:Atom:WM_STATE)
+   (type :initform xcb:Atom:WM_STATE)))
+
+;; WM_ICON_SIZE
+(defclass xcb:icccm:-WM_ICON_SIZE ()
+  ((min-width :initarg :min-width :type xcb:-ignore)
+   (min-height :initarg :min-height :type xcb:-ignore)
+   (max-width :initarg :max-width :type xcb:-ignore)
+   (max-height :initarg :max-height :type xcb:-ignore)
+   (width-inc :initarg :width-inc :type xcb:-ignore)
+   (height-inc :initarg :height-inc :type xcb:-ignore)))
+;;
+(defclass xcb:icccm:get-WM_ICON_SIZE (xcb:icccm:-GetProperty-explicit)
+  ((property :initform xcb:Atom:WM_ICON_SIZE)
+   (type :initform xcb:Atom:WM_ICON_SIZE)
+   (long-length :initform 6)))
+(defclass xcb:icccm:get-WM_ICON_SIZE~reply
+  (xcb:icccm:-GetProperty-explicit~reply xcb:icccm:-WM_ICON_SIZE)
+  nil)
+(defclass xcb:icccm:set-WM_ICON_SIZE
+  (xcb:icccm:-ChangeProperty-explicit xcb:icccm:-WM_ICON_SIZE)
+  ((property :initform xcb:Atom:WM_ICON_SIZE)
+   (type :initform xcb:Atom:WM_ICON_SIZE)))
+
+
+
+(provide 'xcb-icccm)
+
+;;; xcb-icccm.el ends here
diff --git a/xcb-keysyms.el b/xcb-keysyms.el
new file mode 100644
index 0000000..5a118a4
--- /dev/null
+++ b/xcb-keysyms.el
@@ -0,0 +1,314 @@
+;;; xcb-keysyms.el --- Conversion between  -*- lexical-binding: t -*-
+;;;                    X keysyms, X keycodes and Emacs key event.
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library mainly deals with the conversion between X keycodes, X keysyms
+;; and Emacs key events, roughly corresponding to the xcb/util-keysyms project.
+
+;; Usage tips:
+;; + Do not forget to call `xcb:keysyms:init' for _every_ connection using
+;;   this library.
+;; + xcb:keysyms:*-mask correctly relate Emacs modifier keys to X ones,
+;;   thus shall be used in preference to 'xcb:ModMask:*' or
+;;   'xcb:KeyButMask:Mod*'.
+
+;; Todo:
+;; + Is xcb:ModMask:Control/xcb:ModMask:Shift always equivalent to
+;;   control/shift in Emacs?
+
+;; References:
+;; + X protocol (http://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.txt)
+;; + xcb/util-keysyms (git://anongit.freedesktop.org/xcb/util-keysyms)
+
+;;; Code:
+
+(require 'xcb)
+
+(defvar xcb:keysyms:meta-mask nil "META key mask.")
+(defvar xcb:keysyms:control-mask xcb:ModMask:Control "CONTROL key mask.")
+(defvar xcb:keysyms:shift-mask xcb:ModMask:Shift "SHIFT key mask.")
+(defvar xcb:keysyms:hyper-mask nil "HYPER key mask.")
+(defvar xcb:keysyms:super-mask nil "SUPER key mask.")
+(defvar xcb:keysyms:alt-mask nil "ALT key mask.")
+(defvar xcb:keysyms:lock-mask xcb:ModMask:Lock "LOCK key mask.")
+(defvar xcb:keysyms:num-lock-mask nil "NUM LOCK key mask.")
+(defvar xcb:keysyms:mode-switch-mask nil "MODE SWITCH key mask.")
+
+(cl-defmethod xcb:keysyms:init ((obj xcb:connection))
+  "Initialize keysyms module.
+
+This method must be called before using any other method in this module."
+  (with-slots (min-keycode max-keycode) (xcb:get-setup obj)
+    (xcb:keysyms:update-keyboard-mapping obj
+                                         min-keycode
+                                         (1+ (- max-keycode min-keycode)))
+    (unless xcb:keysyms:meta-mask     ;avoid duplicated initialization
+      (xcb:keysyms:update-modifier-mapping obj))))
+
+(cl-defmethod xcb:keysyms:update-keyboard-mapping ((obj xcb:connection)
+                                                   first-keycode count)
+  "Update keyboard mapping (from FIRST-KEYCODE to FIRST-KEYCODE + COUNT - 1)."
+  (let* ((reply (xcb:+request-unchecked+reply obj
+                    (make-instance 'xcb:GetKeyboardMapping
+                                   :first-keycode first-keycode :count count)))
+         (keysyms-per-keycode (slot-value reply 'keysyms-per-keycode))
+         (keysyms (slot-value reply 'keysyms))
+         result keycode index row-index keysym)
+    (dotimes (i count)
+      (setq keycode (+ i first-keycode)
+            index (* i keysyms-per-keycode)
+            row-index 0)
+      (setq keysym (nth (+ index row-index) keysyms))
+      (while (and (/= keysym 0) (< row-index keysyms-per-keycode))
+        (setq result (append result `((,keycode . ,keysym)))
+              row-index (1+ row-index)
+              keysym (nth (+ index row-index) keysyms))))
+    (setf (slot-value obj 'extra-plist)
+          (plist-put (slot-value obj 'extra-plist) 'keysyms result))))
+
+(cl-defmethod xcb:keysyms:update-modifier-mapping ((obj xcb:connection))
+  "Differentiate xcb:ModMask:1 ~ xcb:ModMask:5."
+  ;; Determine MODE SWITCH and NUM LOCK
+  (let* ((reply (xcb:+request-unchecked+reply obj
+                    (make-instance 'xcb:GetModifierMapping)))
+         (keycodes-per-modifier (slot-value reply 'keycodes-per-modifier))
+         (keycodes (slot-value reply 'keycodes))
+         (mode-masks (list xcb:ModMask:Shift xcb:ModMask:Lock
+                           xcb:ModMask:Control xcb:ModMask:1 xcb:ModMask:2
+                           xcb:ModMask:3 xcb:ModMask:4 xcb:ModMask:5))
+         events keycode keysym)
+    (cl-assert (= (length keycodes) (* 8 keycodes-per-modifier)))
+    (dotimes (i 8)
+      (setq events nil)
+      (dotimes (j keycodes-per-modifier)
+        (when (and (/= (setq keycode (pop keycodes)) 0)
+                   (setq keysym (xcb:keysyms:keycode->keysym obj keycode 0)))
+          (setq events
+                (nconc events
+                       (list (xcb:keysyms:keysym->event keysym nil t))))))
+      (cond ((memq 'mode-switch* events)
+             (setq xcb:keysyms:mode-switch-mask (elt mode-masks i)))
+            ((memq 'kp-numlock events)
+             (setq xcb:keysyms:num-lock-mask (elt mode-masks i))))))
+  ;; Determine remaining keys
+  (let* ((id (string-to-int (frame-parameter nil 'window-id)))
+         (root
+          (slot-value (car (slot-value (xcb:get-setup obj) 'roots)) 'root))
+         (keycode (xcb:keysyms:keysym->keycode obj ?a))
+         (fake-event (make-instance 'xcb:SendEvent
+                                    :propagate 0 :destination id
+                                    :event-mask xcb:EventMask:NoEvent
+                                    :event nil))
+         (key-press (make-instance 'xcb:KeyPress
+                                   :detail keycode :time xcb:Time:CurrentTime
+                                   :root root :event id :child 0
+                                   :root-x 0 :root-y 0 :event-x 0 :event-y 0
+                                   :state nil :same-screen 1))
+         event)
+    (dolist (i (list xcb:ModMask:1 xcb:ModMask:2 xcb:ModMask:3
+                     xcb:ModMask:4 xcb:ModMask:5))
+      (unless (or (= i xcb:keysyms:mode-switch-mask) ;already determined
+                  (= i xcb:keysyms:num-lock-mask))
+        (setf (slot-value key-press 'state) i
+              (slot-value fake-event 'event) (xcb:marshal key-press obj))
+        (run-with-idle-timer 0 nil (lambda ()
+                                     (xcb:+request obj fake-event)
+                                     (xcb:flush obj)))
+        (catch 'break
+          (with-timeout (1)             ;FIXME
+            (while t
+              (setq event (read-event))
+              (when (and (integerp event) (= ?a (event-basic-type event)))
+                (pcase event
+                  (?\M-a (setq xcb:keysyms:meta-mask i))
+                  (?\A-a (setq xcb:keysyms:alt-mask i))
+                  (?\s-a (setq xcb:keysyms:super-mask i))
+                  (?\H-a (setq xcb:keysyms:hyper-mask i)))
+                (throw 'break nil)))))))))
+
+(cl-defmethod xcb:keysyms:keycode->keysym ((obj xcb:connection)
+                                           keycode modifiers)
+  "Get the keysym from KeyPress event
+
+SHIFT LOCK is ignored."
+  (let* ((keysyms (plist-get (slot-value obj 'extra-plist) 'keysyms))
+         (group (delq nil (mapcar (lambda (i)
+                                    (when (= keycode (car i)) (cdr i)))
+                                  keysyms)))
+         (group (pcase (length group)
+                  (1 (append group '(0) group '(0)))
+                  (2 (append group group))
+                  (3 (append group '(0)))
+                  (_
+                   (list (elt group 0) (elt group 1)
+                         (elt group 2) (elt group 3)))))
+         (group (if (and xcb:keysyms:mode-switch-mask ;not initialized
+                         (/= 0
+                             (logand modifiers xcb:keysyms:mode-switch-mask)))
+                    (cddr group) (list (elt group 0) (elt group 1))))
+         (mask (logior (if (= 0 (logand modifiers xcb:keysyms:shift-mask)) 0 1)
+                       (if (= 0 (logand modifiers xcb:keysyms:lock-mask))
+                           0 2))))
+    (if (and xcb:keysyms:num-lock-mask  ;not initialized
+             (/= 0 (logand modifiers xcb:keysyms:num-lock-mask))
+             (<= #xff80 (elt group 1)) (>= #xffbe (elt group 1))) ;keypad
+        (if (= mask 1) (elt group 0) (elt group 1))
+      (pcase mask
+        (0 (elt group 0))               ;SHIFT off, CAPS LOCK off
+        (1 (elt group 1))               ;SHIFT on, CAPS LOCK off
+        (2 (upcase (elt group 0)))      ;SHIFT off, CAPS LOCK on
+        (3 (upcase (elt group 1)))))))  ;SHIFT on, CAPS LOCK on
+
+(cl-defmethod xcb:keysyms:keysym->keycode ((obj xcb:connection) keysym)
+  "Convert X keysym to (first match) keycode"
+  (car (rassoc keysym (plist-get (slot-value obj 'extra-plist) 'keysyms))))
+
+;; This list is largely base on 'lispy_function_keys' in 'keyboard.c'.
+;; Emacs has a built-in variable `x-keysym-table' providing Latin-1 and legacy
+;; keysyms, which seems not very useful here.
+;; FIXME: shall we also include 'iso_lispy_function_keys' there?
+(defconst xcb:keysyms:-function-keys
+  `(                                    ;#xff00 - #xff0f
+    ,@(make-list 8 nil) backspace tab linefeed clear nil return nil nil
+                                        ;#xff10 - #xff1f
+    nil nil nil pause nil nil nil nil nil nil nil escape nil nil nil nil
+                                        ;#xff20 - #xff2f
+    nil kanji muhenkan henkan romaji hiragana katakana hiragana-katakana
+    zenkaku hankaku zenkaku-hankaku touroku massyo kana-lock kana-shift
+    eisu-shift
+                                        ;#xff30 - #xff3f
+    eisu-toggle ,@(make-list 15 nil)
+                                        ;#xff40 - #xff4f
+    ,@(make-list 16 nil)
+                                        ;#xff50 - #xff5f
+    home left up right down prior next end begin ,@(make-list 7 nil)
+                                        ;#xff60 - #xff6f
+    select print execute insert nil undo redo menu find cancel help break
+    nil nil nil nil
+                                        ;#xff70 - #xff7f
+    ;; nil nil nil nil backtab ,@(make-list 10 nil) kp-numlock
+    nil nil nil nil backtab ,@(make-list 9 nil) mode-switch* kp-numlock
+                                        ;#xff80 - #xff8f
+    kp-space ,@(make-list 8 nil) kp-tab nil nil nil kp-enter nil nil
+                                        ;#xff90 - #xff9f
+    nil kp-f1 kp-f2 kp-f3 kp-f4 kp-home kp-left kp-up kp-right kp-down
+    kp-prior kp-next kp-end kp-begin kp-insert kp-delete
+                                        ;#xffa0 - #xffaf
+    ,@(make-list 10 nil)
+    kp-multiply kp-add kp-separator kp-subtract kp-decimal kp-divide
+                                        ;#xffb0 - #xffbf
+    kp-0 kp-1 kp-2 kp-3 kp-4 kp-5 kp-6 kp-7 kp-8 kp-9 nil nil nil kp-equal
+    f1 f2
+                                        ;#xffc0 - #xffcf
+    f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18
+                                        ;#xffd0 - #xffdf
+    f19 f20 f21 f22 f23 f24 f25 f26 f27 f28 f29 f30 f31 f32 f33 f34
+                                        ;#xffe0 - #xffef
+    ;; f35 ,@(make-list 15 nil)
+    f35 lshift* rshift* lcontrol* rcontrol* caps-lock* shift-lock*
+    lmeta* rmeta* lalt* ralt* lsuper* rsuper* lhyper* rhyper*
+                                        ;#xff00 - #xffff
+    ,@(make-list 15 nil) delete)
+  "Emacs event representations of X function keys (keysym #xff00 to #xffff)")
+
+(defun xcb:keysyms:event->keysym (event)
+  "Translate Emacs key event to X Keysym.
+
+This function returns nil when it fails to convert an event."
+  (let ((modifiers (event-modifiers event))
+        (event (event-basic-type event))
+        keysym)
+    (if (not (integerp event))
+        (setq keysym
+              (pcase event
+                (`mouse-1 xcb:ButtonIndex:1)
+                (`mouse-2 xcb:ButtonIndex:2)
+                (`mouse-3 xcb:ButtonIndex:3)
+                (`mouse-4 xcb:ButtonIndex:4)
+                (`mouse-5 xcb:ButtonIndex:5)
+                ;; Function keys
+                (_ (cl-position event xcb:keysyms:-function-keys))))
+      (if (and (<= #x20 event) (>= #xff event)) ;Latin-1
+          (setq keysym event)
+        (when (and (<= #x100 event) (>= #x10ffff event)) ;Unicode
+          (setq keysym (+ #x1000000 event)))))
+    (when keysym
+      (when (and (not (integerp event)) (< 5 keysym))
+        (setq keysym (logior keysym #xff00)))
+      `(,keysym
+        ;; state for KeyPress event
+        ,(apply 'logior
+                (mapcar (lambda (i)
+                          (pcase i
+                            (`meta xcb:keysyms:meta-mask)
+                            (`control xcb:keysyms:control-mask)
+                            (`shift xcb:keysyms:shift-mask)
+                            (`hyper xcb:keysyms:hyper-mask)
+                            (`super xcb:keysyms:super-mask)
+                            (`alt xcb:keysyms:alt-mask)
+                            (`down 0)
+                            ;; FIXME: more?
+                            (_ 0)))
+                        modifiers))))))
+
+(defun xcb:keysyms:keysym->event (keysym &optional mask allow-modifiers)
+  "Translate X Keysym into Emacs key event."
+  (let ((event (cond ((and (<= #x20 keysym) (>= #xff keysym))
+                      keysym)
+                     ((and (<= #xff00 keysym) (>= #xffff keysym))
+                      (elt xcb:keysyms:-function-keys (logand keysym #xff)))
+                     ((and (<= #x1000100 keysym) (>= #x110ffff keysym))
+                      (- keysym #x1000000))
+                     ((and (<= 1 keysym) (>= 5 keysym)) ;ButtonPress assuemd
+                      (intern-soft (format "down-mouse-%d" keysym))))))
+    (when (and (not allow-modifiers)
+               (memq event
+                     '(lshift* rshift* lcontrol* rcontrol*
+                               caps-lock* shift-lock* lmeta* rmeta* lalt* ralt*
+                               lsuper* rsuper* lhyper* rhyper*
+                               mode-switch* kp-numlock)))
+      (setq event nil))
+    (when event
+      (if (not mask)
+          event
+        (setq event (list event))
+        (when (/= 0 (logand mask xcb:keysyms:meta-mask))
+          (push 'meta event))
+        (when (/= 0 (logand mask xcb:keysyms:control-mask))
+          (push 'control event))
+        (when (/= 0 (logand mask xcb:keysyms:shift-mask))
+          (push 'shift event))
+        (when (and xcb:keysyms:hyper-mask
+                   (/= 0 (logand mask xcb:keysyms:hyper-mask)))
+          (push 'hyper event))
+        (when (/= 0 (logand mask xcb:keysyms:super-mask))
+          (push 'super event))
+        (when (and xcb:keysyms:alt-mask
+                   (/= 0 (logand mask xcb:keysyms:alt-mask)))
+          (push 'alt event))
+        (event-convert-list event)))))
+
+(provide 'xcb-keysyms)
+
+;;; xcb-keysyms.el ends here
diff --git a/xcb-xim.el b/xcb-xim.el
new file mode 100644
index 0000000..847db54
--- /dev/null
+++ b/xcb-xim.el
@@ -0,0 +1,1025 @@
+;;; xcb-xim.el --- XIM Protocol  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library implements the X Input Method Protocol.
+
+;; Please note that the byte order of an XIM packet can be different from that
+;; of X packets. Moreover, if you are writing an XIM server, the byte order is
+;; actually specified by the client. Therefore we provide a different global
+;; variable `xim:lsb' to indicate the byte order of classes in this library.
+;; You should let-bind it whenever creating new objects.
+
+;; Todo:
+;; + Add extension support.
+
+;; References:
+;; + XIM (http://www.x.org/releases/X11R7.7/doc/libX11/XIM/xim.txt)
+
+;;; Code:
+
+(require 'xcb-types)
+(require 'xcb-xlib)
+
+;;;; Protocol number
+
+(defconst xim:opcode:connect 1)
+(defconst xim:opcode:connect-reply 2)
+(defconst xim:opcode:disconnect 3)
+(defconst xim:opcode:disconnect-reply 4)
+
+(defconst xim:opcode:auth-required 10)
+(defconst xim:opcode:auth-reply 11)
+(defconst xim:opcode:auth-next 12)
+(defconst xim:opcode:auth-setup 13)
+(defconst xim:opcode:auth-ng 14)
+
+(defconst xim:opcode:error 20)
+
+(defconst xim:opcode:open 30)
+(defconst xim:opcode:open-reply 31)
+(defconst xim:opcode:close 32)
+(defconst xim:opcode:close-reply 33)
+(defconst xim:opcode:register-triggerkeys 34)
+(defconst xim:opcode:trigger-notify 35)
+(defconst xim:opcode:trigger-notify-reply 36)
+(defconst xim:opcode:set-event-mask 37)
+(defconst xim:opcode:encoding-negotiation 38)
+(defconst xim:opcode:encoding-negotiation-reply 39)
+(defconst xim:opcode:query-extension 40)
+(defconst xim:opcode:query-extension-reply 41)
+(defconst xim:opcode:set-im-values 42)
+(defconst xim:opcode:set-im-values-reply 43)
+(defconst xim:opcode:get-im-values 44)
+(defconst xim:opcode:get-im-values-reply 45)
+
+(defconst xim:opcode:create-ic 50)
+(defconst xim:opcode:create-ic-reply 51)
+(defconst xim:opcode:destroy-ic 52)
+(defconst xim:opcode:destroy-ic-reply 53)
+(defconst xim:opcode:set-ic-values 54)
+(defconst xim:opcode:set-ic-values-reply 55)
+(defconst xim:opcode:get-ic-values 56)
+(defconst xim:opcode:get-ic-values-reply 57)
+(defconst xim:opcode:set-ic-focus 58)
+(defconst xim:opcode:unset-ic-focus 59)
+(defconst xim:opcode:forward-event 60)
+(defconst xim:opcode:sync 61)
+(defconst xim:opcode:sync-reply 62)
+(defconst xim:opcode:commit 63)
+(defconst xim:opcode:reset-ic 64)
+(defconst xim:opcode:reset-ic-reply 65)
+
+(defconst xim:opcode:geometry 70)
+(defconst xim:opcode:str-conversion 71)
+(defconst xim:opcode:str-conversion-reply 72)
+(defconst xim:opcode:preedit-start 73)
+(defconst xim:opcode:preedit-start-reply 74)
+(defconst xim:opcode:preedit-draw 75)
+(defconst xim:opcode:preedit-caret 76)
+(defconst xim:opcode:preedit-caret-reply 77)
+(defconst xim:opcode:preedit-done 78)
+(defconst xim:opcode:status-start 79)
+(defconst xim:opcode:status-draw 80)
+(defconst xim:opcode:status-done 81)
+(defconst xim:opcode:preeditstate 82)
+
+;;;; Basic requests packet format
+
+(defvar xim:lsb xcb:lsb "t for LSB first, nil otherwise.
+
+Consider let-bind it rather than change its global value.")
+
+(defclass xim:-struct (xcb:-struct)
+  ((~lsb :initform (symbol-value 'xim:lsb)))
+  :documentation "Struct type for XIM.")
+
+(defclass xim:-request (xim:-struct)
+  ((~major-opcode :type xcb:CARD8)
+   (~minor-opcode :initform 0 :type xcb:CARD8)
+   (~length :initform 0 :type xcb:CARD16))
+  :documentation "XIM request type.")
+
+(cl-defmethod xcb:marshal ((obj xim:-request))
+  "Return the byte-array representation of XIM request OBJ."
+  (let ((result (cl-call-next-method obj)))
+    (vconcat (substring result 0 2)
+             (funcall (if (slot-value obj '~lsb)
+                          'xcb:-pack-u2-lsb
+                        'xcb:-pack-u2)
+                      (1- (/ (length result) 4)))
+             (substring result 4))))
+
+;;;; Data types
+
+(xcb:deftypealias 'xim:BITMASK16 'xcb:CARD16)
+
+(xcb:deftypealias 'xim:BITMASK32 'xcb:CARD32)
+
+(defsubst xim:PADDING (N)
+  (% (- 4 (% N 4)) 4))
+
+(xcb:deftypealias 'xim:LPCE 'xcb:char)
+
+(defclass xim:STRING (xim:-struct)
+  ((length :initarg :length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xim:LPCE
+                             size (xcb:-fieldref 'length))
+            :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+(defclass xim:STR (xim:-struct)
+  ((length :initarg :length :type xcb:-u1)
+   (name :initarg :name :type xcb:-ignore)
+   (name~ :initform '(name name type xcb:char size (xcb:-fieldref 'length))
+          :type xcb:-list)))
+
+(defclass xim:XIMATTR (xim:-struct)
+  ((id :initarg :id :type xcb:CARD16)
+   (type :initarg :type :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (attribute :initarg :attribute :type xcb:-ignore)
+   (attribute~ :initform '(name attribute type xcb:char
+                                size (xcb:-fieldref 'length))
+               :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+(defclass xim:XICATTR (xim:XIMATTR)
+  nil)
+
+(defconst xim:ATTRIBUTE-VALUE-TYPE:separator-of-nestedlist 0)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:byte-data 1)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:word-data 2)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:long-data 3)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:char-data 4)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:window 5)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-styles 10)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:x-rectangle 11)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:x-point 12)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:x-font-set 13)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-hot-key-triggers 15)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-string-conversion 17)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-preedit-state 18)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-reset-state 19)
+(defconst xim:ATTRIBUTE-VALUE-TYPE:xim-nested-list #x7FFF)
+
+(defclass xim:XIMStyles (xim:-struct)
+  ((number :initarg :number :type xcb:-u2)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (styles :initarg :styles :type xcb:-ignore)
+   (styles~ :initform '(name styles type xcb:CARD32
+                             size (/ (xcb:-fieldref 'number) 4))
+            :type xcb:-list)))
+
+;; Auto set the number slot
+(cl-defmethod xcb:marshal ((obj xim:XIMStyles))
+  (setf (slot-value obj 'number) (* 4 (length (slot-value obj 'styles))))
+  (cl-call-next-method obj))
+
+(defclass xim:XFontSet (xim:-struct)
+  ((length :initarg :length :type xcb:-u2)
+   (base-font-name :initarg :base-font-name :type xcb:-ignore)
+   (base-font-name~ :initform '(name base-font-name type xim:LPCE
+                                     size (xcb:-fieldref 'length))
+                    :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+(defclass xim:XIMHotKeyTriggers (xim:-struct)
+  ((number :type xcb:-u4)
+   (triggers :type xcb:-ignore)
+   (triggers~ :initform '(name triggers type xim:XIMTRIGGERKEY
+                               size (xcb:-fieldref 'number))
+              :type xcb:-list)
+   (states :type xcb:-ignore)
+   (states~ :initform '(name states type xim:XIMHOTKEYSTATE
+                             size (xcb:-fieldref 'number))
+            :type xcb:-list)))
+
+(defclass xim:XIMTRIGGERKEY (xim:-struct)
+  ((keysym :initarg :keysym :type xcb:CARD32)
+   (modifier :initarg :modifier :type xcb:CARD32)
+   (modifier-mask :initarg :modifier-mask :type xcb:CARD32)))
+
+(defclass xim:ENCODINGINFO (xim:-struct)
+  ((length :initarg :length :type xcb:-u2)
+   (encoding-info :initarg :encoding-info :type xcb:-ignore)
+   (encoding-info~ :initform '(name encoding-info type xcb:char
+                                    size (xcb:-fieldref 'length))
+                   :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+(defclass xim:EXT (xim:-struct)
+  ((major-opcode :initarg :major-opcode :type xcb:CARD8)
+   (minor-opcode :initarg :minor-opcode :type xcb:CARD8)
+   (length :initarg :length :type xcb:-u2)
+   (name :initarg :name :type xcb:-ignore)
+   (name~ :initform '(name name type xcb:char size (xcb:-fieldref 'length))
+          :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(defclass xim:XIMATTRIBUTE (xim:-struct)
+  ((id :initarg :id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (value :initarg :value :type xcb:-ignore)
+   (value~ :initform '(name value type xcb:void size (xcb:-fieldref 'length))
+           :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(cl-defmethod xcb:marshal ((obj xim:XIMATTRIBUTE))
+  (let ((value (slot-value obj 'value)))
+    (when (eieio-object-p value)
+      (setq value (xcb:marshal value))
+      (setf (slot-value obj 'length) (length value)
+            (slot-value obj 'value) value))
+    (cl-call-next-method obj)))
+
+(defclass xim:XICATTRIBUTE (xim:XIMATTRIBUTE)
+  nil)
+
+(defclass xim:XIMSTRCONVTEXT (xim:-struct)
+  ((feedback :initarg :feedback :type xcb:CARD16)
+   (string-length :initarg :string-length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xcb:char
+                             size (xcb:-fieldref 'string-length))
+            :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'string-length))
+          :type xcb:-pad)
+   (feedbacks-length :initarg :feedbacks-length :type xcb:-u2)
+   (pad~1 :initform 2 :type xcb:-pad)
+   (feedbacks :initarg :feedbacks :type xcb:-ignore)
+   (feedbacks~ :initform '(name feedbacks type xcb:void
+                                size (xcb:-fieldref 'feedbacks-length))
+               :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:XIMSTRCONVTEXT))
+  (let ((feedbacks (mapconcat 'xcb:marshal (slot-value obj 'feedbacks) [])))
+    (setf (slot-value obj 'feedbacks-length) (length feedbacks)
+          (slot-value obj 'feedbacks) feedbacks)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:XIMSTRCONVTEXT) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (data (slot-value obj 'feedbacks))
+        feedback feedbacks)
+    (while (< 0 (length data))
+      (setq feedback (make-instance 'xim:XIMSTRCONVFEEDBACK)
+            data (substring data (xcb:unmarshal feedback data))
+            feedbacks (nconc feedbacks (list feedback))))
+    (setf (slot-value obj 'feedbacks) feedbacks)
+    retval))
+
+(defconst xim:string-conversion:left-edge #x0000001)
+(defconst xim:string-conversion:right-edge #x0000002)
+(defconst xim:string-conversion:top-edge #x0000004)
+(defconst xim:string-conversion:bottom-edge #x0000008)
+(defconst xim:string-conversion:convealed #x0000010)
+(defconst xim:string-conversion:wrapped #x0000020)
+
+(xcb:deftypealias 'xim:XIMFEEDBACK 'xcb:CARD32)
+
+;; FIXME: different from Xlib:XIM*
+(defconst xim:reverse #x000001)
+(defconst xim:underline #x000002)
+(defconst xim:highlight #x000004)
+(defconst xim:primary #x000008)
+(defconst xim:secondary #x000010)
+(defconst xim:tertiary #x000020)
+(defconst xim:visible-to-forward #x000040)
+(defconst xim:visible-to-backward #x000080)
+(defconst xim:visible-center #x000100)
+
+(xcb:deftypealias 'xim:XIMHOTKEYSTATE 'xcb:CARD32)
+
+(defconst xim:hot-key-state:on #x0000001)
+(defconst xim:hot-key-state:off #x0000002)
+
+(xcb:deftypealias 'xim:XIMPREEDITSTATE 'xcb:CARD32)
+
+(defconst xim:preedit:enable #x0000001)
+(defconst xim:preedit:disable #x0000002)
+
+(xcb:deftypealias 'xim:XIMRESETSTATE 'xcb:CARD32)
+
+(defconst xim:initial-state #x0000001)
+(defconst xim:preserve-state #x0000002)
+
+;;;; Error notification
+
+(defclass xim:error (xim:-request)
+  ((~major-opcode :initform xim:opcode:error)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (flag :initarg :flag :type xim:BITMASK16)
+   (error-code :initarg :error-code :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (type :initarg :type :type xcb:CARD16)
+   (detail :initarg :detail :type xcb:-ignore)
+   (detail~ :initform '(name detail type xcb:char
+                             size (xcb:-fieldref 'length)) :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(defconst xim:error-flag:invalid-both 0)
+(defconst xim:error-flag:invalid-im-id 1)
+(defconst xim:error-flag:invalid-ic-id 2)
+
+(defconst xim:error-code:bad-alloc 1)
+(defconst xim:error-code:bad-style 2)
+(defconst xim:error-code:bad-client-window 3)
+(defconst xim:error-code:bad-focus-window 4)
+(defconst xim:error-code:bad-area 5)
+(defconst xim:error-code:bad-spot-location 6)
+(defconst xim:error-code:bad-colormap 7)
+(defconst xim:error-code:bad-atom 8)
+(defconst xim:error-code:bad-pixel 9)
+(defconst xim:error-code:bad-pixmap 10)
+(defconst xim:error-code:bad-name 11)
+(defconst xim:error-code:bad-cursor 12)
+(defconst xim:error-code:bad-protocol 13)
+(defconst xim:error-code:bad-foreground 14)
+(defconst xim:error-code:bad-background 15)
+(defconst xim:error-code:locale-not-supported 16)
+(defconst xim:error-code:bad-something 999)
+
+;;;; Connection establishment
+
+(defclass xim:connect (xim:-request)
+  ((~major-opcode :initform xim:opcode:connect)
+   (byte-order :initarg :byte-order :type xcb:-u1)
+   (pad~0 :initform 1 :type xcb:-pad)
+   (major-version :initarg :major-version :type xcb:CARD16)
+   (minor-version :initarg :minor-version :type xcb:CARD16)
+   (number :initarg :number :type xcb:CARD16)
+   (auth-names :initarg :auth-names :type xcb:-ignore)
+   (auth-names~ :initform '(name auth-names type xim:STRING
+                                 size (xcb:-fieldref 'number))
+                :type xcb:-list)))
+
+(defconst xim:connect-byte-order:msb-first #x42)
+(defconst xim:connect-byte-order:lsb-first #x6c)
+
+(defclass xim:auth-required (xim:-request)
+  ((~major-opcode :initform xim:opcode:auth-required)
+   (index :initarg :index :type xcb:CARD8)
+   (pad~0 :initform 3 :type xcb:-pad)
+   (length :initarg :length :type xcb:-u2)
+   (pad~1 :initform 2 :type xcb:-pad)
+   (data :initarg :data :type xcb:-ignore)
+   (data~ :initform '(name data type xcb:void size (xcb:-fieldref 'length))
+          :type xcb:-list)
+   (pad~1 :initform '(xim:PADDING (slot-value length)) :type xcb:-pad)))
+
+(defclass xim:auth-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:auth-reply)
+   (length :initarg :length :type xcb:-u2)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (data :initarg :data :type xcb:-ignore)
+   (data~ :initform '(name data type xcb:void size (xcb:-fieldref 'length))
+          :type xcb:-list)
+   (pad~1 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(defclass xim:auth-next (xim:-request)
+  ((~major-opcode :initform xim:opcode:auth-next)
+   (length :initarg :length :type xcb:-u2)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (data :initarg :data :type xcb:-ignore)
+   (data~ :initform '(name data type xcb:void size (xcb:-fieldref 'length))
+          :type xcb:-list)
+   (pad~1 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(defclass xim:auth-setup (xim:-request)
+  ((~major-opcode :initform xim:opcode:auth-setup)
+   (number :initarg :number :type xcb:CARD16)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (names :initarg :names :type xcb:-ignore)
+   (names~ :initform '(name names type xim:STRING
+                            size (xcb:-fieldref 'number))
+           :type xcb:-list)))
+
+(defclass xim:auth-ng (xim:-request)
+  ((~major-opcode :initform xim:opcode:auth-ng)))
+
+(defclass xim:connect-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:connect-reply)
+   ;; Default to version 1.0
+   (major-version :initarg :major-version :initform 1 :type xcb:CARD16)
+   (minor-version :initarg :minor-version :initform 0 :type xcb:CARD16)))
+
+(defclass xim:disconnect (xim:-request)
+  ((~major-opcode :initform xim:opcode:disconnect)))
+
+(defclass xim:disconnect-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:disconnect-reply)))
+
+(defclass xim:open (xim:-request)
+  ((~major-opcode :initform xim:opcode:open)
+   (locale-name :initarg :locale-name :type xim:STR)
+   (pad~0 :initform '(xim:PADDING (1+ (slot-value (xcb:-fieldref 'locale-name)
+                                                  'length)))
+          :type xcb:-pad)))
+
+(defclass xim:open-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:open-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (im-attrs-length :initarg :im-attrs-length :type xcb:-u2)
+   (im-attrs :initarg :im-attrs :type xcb:-ignore)
+   (im-attrs~ :initform '(name im-attrs type xcb:void
+                               size (xcb:-fieldref 'im-attrs-length))
+              :type xcb:-list)
+   (ic-attrs-length :initarg :ic-attrs-length :type xcb:-u2)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (ic-attrs :initarg :ic-attrs :type xcb:-ignore)
+   (ic-attrs~ :initform '(name ic-attrs type xcb:void
+                               size (xcb:-fieldref 'ic-attrs-length))
+              :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:open-reply))
+  (let ((im-attrs (mapconcat 'xcb:marshal (slot-value obj 'im-attrs) []))
+        (ic-attrs (mapconcat 'xcb:marshal (slot-value obj 'ic-attrs) [])))
+    (setf (slot-value obj 'im-attrs-length) (length im-attrs)
+          (slot-value obj 'im-attrs) im-attrs
+          (slot-value obj 'ic-attrs-length) (length ic-attrs)
+          (slot-value obj 'ic-attrs) ic-attrs)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:open-reply) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (im-data (slot-value obj 'im-attrs))
+        (ic-data (slot-value obj 'ic-attrs))
+        im-attr im-attrs ic-attr ic-attrs)
+    (while (< 0 (length im-data))
+      (setq im-attr (make-instance 'xim:XIMATTR)
+            im-data (substring im-data (xcb:unmarshal im-attr im-data))
+            im-attrs (nconc im-attrs (list im-attr))))
+    (while (< 0 (length ic-data))
+      (setq ic-attr (make-instance 'xim:XICATTR)
+            ic-data (substring ic-data (xcb:unmarshal ic-attr ic-data))
+            ic-attrs (nconc ic-attrs (list ic-attr))))
+    (setf (slot-value obj 'im-attrs) im-attrs
+          (slot-value obj 'ic-attrs) ic-attrs)
+    retval))
+
+(defclass xim:close (xim:-request)
+  ((~major-opcode :initform xim:opcode:close)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (pad~0 :initform 2 :type xcb:-pad)))
+
+(defclass xim:close-reply (xim:close)
+  ((~major-opcode :initform xim:opcode:close-reply)))
+
+;;;; Event flow control
+
+(defclass xim:set-event-mask (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-event-mask)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (forward-event-mask :initarg :forward-event-mask :type xcb:-u4)
+   (synchronous-event-mask :initarg :synchronous-event-mask :type xcb:-u4)))
+
+(defclass xim:register-triggerkeys (xim:-request)
+  ((~major-opcode :initform xim:opcode:register-triggerkeys)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (on-keys-length :initarg :on-keys-length :type xcb:-u4)
+   (on-keys :initarg :on-keys :type xcb:-ignore)
+   (on-keys~ :initform '(name on-keys type xim:XIMTRIGGERKEY
+                              size (/ (xcb:-fieldref 'on-keys-length) 12))
+             :type xcb:-list)
+   (off-keys-length :initarg :off-keys-length :type xcb:-u4)
+   (off-keys :initarg :off-keys :type xcb:-ignore)
+   (off-keys~ :initform '(name off-keys type xim:XIMTRIGGERKEY
+                               size (/ (xcb:-fieldref 'off-keys-length) 12))
+              :type xcb:-list)))
+
+(defclass xim:trigger-nofity (xim:-request)
+  ((~major-opcode :initform xim:opcode:trigger-notify)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (flag :initarg :flag :type xcb:CARD32)
+   (index :initarg :index :type xcb:CARD32)
+   (client-select-event-mask :initarg :client-select-event-mask
+                             :type xcb:-u4)))
+
+(defconst xim:trigger-nofity-flag:on-keys 0)
+(defconst xim:trigger-nofity-flag:off-keys 1)
+
+(defclass xim:trigger-nofity-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:trigger-notify-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Encoding negotiation
+
+(defclass xim:encoding-negotiation (xim:-request)
+  ((~major-opcode :initform xim:opcode:encoding-negotiation)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (names-length :initarg :names-length :type xcb:-u2)
+   (names :initarg :names :type xcb:-ignore)
+   (names~ :initform '(name names type xcb:void
+                            size (xcb:-fieldref 'names-length))
+           :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'names-length))
+          :type xcb:-pad)
+   (encodings-length :initarg :encoding-length :type xcb:-u2)
+   (pad~1 :initform 2 :type xcb:-pad)
+   (encodings :initarg :encodings :type xcb:-ignore)
+   (encodings~ :initform '(name encodings type xcb:void
+                                size (xcb:-fieldref 'encodings-length))
+               :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:encoding-negotiation))
+  (let ((names (mapconcat 'xcb:marshal (slot-value obj 'names) []))
+        (encodings (mapconcat 'xcb:marshal (slot-value obj 'encodings) [])))
+    (setf (slot-value obj 'names-length) (length names)
+          (slot-value obj 'names) names
+          (slot-value obj 'encodings-length) (length encodings)
+          (slot-value obj 'encodings) encodings)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:encoding-negotiation) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (names-data (slot-value obj 'names))
+        (encodings-data (slot-value obj 'encodings))
+        name names encoding encodings)
+    (while (< 0 (length names-data))
+      (setq name (make-instance 'xim:STR)
+            names-data (substring names-data (xcb:unmarshal name names-data))
+            names (nconc names (list name))))
+    (while (< 0 (length encodings-data))
+      (setq encoding (make-instance 'xim:ENCODINGINFO)
+            encodings-data
+            (substring encodings-data (xcb:unmarshal encoding encodings-data))
+            encodings (nconc encodings (list encoding))))
+    (setf (slot-value obj 'names) names
+          (slot-value obj 'encodings) encodings)
+    retval))
+
+(defclass xim:encoding-negotiation-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:encoding-negotiation-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (category :initarg :category :type xcb:CARD16)
+   (index :initarg :index :type xcb:INT16)
+   (pad~0 :initform 2 :type xcb:-pad)))
+
+(defconst xim:encoding-negotiation-reply-category:name 0)
+(defconst xim:encoding-negotiation-reply-category:data 1)
+
+;;;; Query the supported extension protocol list
+
+(defclass xim:query-extension (xim:-request)
+  ((~major-opcode :initform xim:opcode:query-extension)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (extensions :initarg :extensions :type xcb:-ignore)
+   (extensions~ :initform '(name extensions type xcb:void
+                                 size (xcb:-fieldref 'length))
+                :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(cl-defmethod xcb:marshal ((obj xim:query-extension))
+  (let ((extensions (mapconcat 'xcb:marshal (slot-value obj 'extensions) [])))
+    (setf (slot-value obj 'length) (length extensions)
+          (slot-value obj 'extensions) extensions)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:query-extension) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (data (slot-value obj 'extensions))
+        extension extensions)
+    (while (< 0 (length data))
+      (setq extension (make-instance 'xim:STR)
+            data (substring data (xcb:unmarshal extension data))
+            extensions (nconc extensions (list extension))))
+    (setf (slot-value obj 'extensions) extensions)
+    retval))
+
+(defclass xim:query-extension-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:query-extension-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (extensions :initarg :extensions :type xcb:-ignore)
+   (extensions~ :initform '(name extensions type xcb:void
+                                 size (xcb:-fieldref 'length))
+                :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:query-extension-reply))
+  (let ((extensions (mapconcat 'xcb:marshal (slot-value obj 'extensions) [])))
+    (setf (slot-value obj 'length) (length extensions)
+          (slot-value obj 'extensions) extensions)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:query-extension-reply) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (data (slot-value obj 'extensions))
+        extension extensions)
+    (while (< 0 (length data))
+      (setq extension (make-instance 'xim:EXT)
+            data (substring data (xcb:unmarshal extension data))
+            extensions (nconc extensions (list extension))))
+    (setf (slot-value obj 'extensions) extensions)
+    retval))
+
+;;;; Setting IM values
+
+(defclass xim:set-im-values (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-im-values)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (im-attributes :initarg :im-attributes :type xcb:-ignore)
+   (im-attributes~ :initform '(name im-attributes type xcb:void
+                                    size (xcb:-fieldref 'length))
+                   :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:set-im-values))
+  (let ((im-attributes (mapconcat 'xcb:marshal
+                                  (slot-value obj 'im-attributes) [])))
+    (setf (slot-value obj 'length) (length im-attributes)
+          (slot-value obj 'im-attributes) im-attributes)
+    (cl-call-next-method obj)))
+
+(defclass xim:set-im-values-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-im-values-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (pad~0 :initform 2 :type xcb:-pad)))
+
+;;;; Getting IM values
+
+(defclass xim:get-im-values (xim:-request)
+  ((~major-opcode :initform xim:opcode:get-im-values)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (im-attributes-id :initarg :im-attributes-id :type xcb:-ignore)
+   (im-attributes-id~ :initform '(name im-attributes-id type xcb:CARD16
+                                       size (/ (xcb:-fieldref 'length) 2))
+                      :type xcb:-list)))
+
+(defclass xim:get-im-values-reply (xim:set-im-values)
+  ((~major-opcode :initform xim:opcode:get-im-values-reply)))
+
+;;;; Creating an IC
+
+(defclass xim:create-ic (xim:-request)
+  ((~major-opcode :initform xim:opcode:create-ic)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (ic-attributes :initarg :ic-attributes :type xcb:-ignore)
+   (ic-attributes~ :initform '(name ic-attributes type xcb:void
+                                    size (xcb:-fieldref 'length))
+                   :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:create-ic))
+  (let ((ic-attributes (mapconcat 'xcb:marshal
+                                  (slot-value obj 'ic-attributes) [])))
+    (setf (slot-value obj 'length) (length ic-attributes)
+          (slot-value obj 'ic-attributes) ic-attributes)
+    (cl-call-next-method obj)))
+
+(cl-defmethod xcb:unmarshal ((obj xim:create-ic) byte-array)
+  (let ((retval (cl-call-next-method obj byte-array))
+        (data (slot-value obj 'ic-attributes))
+        ic-attribute ic-attributes)
+    (while (< 0 (length data))
+      (setq ic-attribute (make-instance 'xim:XICATTRIBUTE)
+            data (substring data (xcb:unmarshal ic-attribute data))
+            ic-attributes (nconc ic-attributes (list ic-attribute))))
+    (setf (slot-value obj 'ic-attributes) ic-attributes)
+    retval))
+
+(defclass xim:create-ic-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:create-ic-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Destroy the IC
+
+(defclass xim:destroy-ic (xim:-request)
+  ((~major-opcode :initform xim:opcode:destroy-ic)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+(defclass xim:destroy-ic-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:destroy-ic-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Setting IC values
+
+(defclass xim:set-ic-values (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-ic-values)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (ic-attributes :initarg :ic-attributes :type xcb:-ignore)
+   (ic-attributes~ :initform '(name ic-attributes type xcb:void
+                                    size (xcb:-fieldref 'length))
+                   :type xcb:-list)))
+
+(cl-defmethod xcb:marshal ((obj xim:set-ic-values))
+  (let ((ic-attributes (mapconcat 'xcb:marshal
+                                  (slot-value obj 'ic-attributes) [])))
+    (setf (slot-value obj 'length) (length ic-attributes)
+          (slot-value obj 'ic-attributes) ic-attributes)
+    (cl-call-next-method obj)))
+
+(defclass xim:set-ic-values-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-ic-values-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Getting IC values
+
+(defclass xim:get-ic-values (xim:-request)
+  ((~major-opcode :initform xim:opcode:get-ic-values)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (ic-attributes-id :initarg :ic-attributes-id :type xcb:-ignore)
+   (ic-attributes-id~ :initform '(name ic-attributes-id type xcb:CARD16
+                                       size (/ (xcb:-fieldref 'length) 2))
+                      :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+(defclass xim:get-ic-values-reply (xim:set-ic-values)
+  ((~major-opcode :initform xim:opcode:get-ic-values-reply)))
+
+;;;; Setting IC focus
+
+(defclass xim:set-ic-focus (xim:-request)
+  ((~major-opcode :initform xim:opcode:set-ic-focus)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Unsetting IC focus
+
+(defclass xim:unset-ic-focus (xim:-request)
+  ((~major-opcode :initform xim:opcode:unset-ic-focus)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Filtering events
+
+(defclass xim:forward-event (xim:-request)
+  ((~major-opcode :initform xim:opcode:forward-event)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (flag :initarg :flag :type xim:BITMASK16)
+   (serial-number :initarg :serial-number :type xcb:CARD16)
+   (event :initarg :event :type xcb:-ignore)
+   (event~ :initform '(name event type xcb:void size 32) :type xcb:-list)))
+
+(defconst xim:forward-event-flag:synchronous 1)
+(defconst xim:forward-event-flag:request-filtering 2)
+(defconst xim:forward-event-flag:request-lookupstring 4)
+
+;;;; Synchronizing with the IM server
+
+(defclass xim:sync (xim:-request)
+  ((~major-opcode :initform xim:opcode:sync)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+(defclass xim:sync-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:sync-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;;;; Sending a committed string
+
+(defclass xim:commit (xim:-request)
+  ((~major-opcode :initform xim:opcode:commit)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (flag :initarg :flag :type xim:BITMASK16)))
+
+(defconst xim:commit-flag:synchronous 1)
+;; FIXME: different from Xlib:XLookup*
+(defconst xim:commit-flag:x-lookup-chars 2)
+(defconst xim:commit-flag:x-lookup-key-sym 4)
+(defconst xim:commit-flag:x-lookup-both 6)
+
+(defclass xim:commit-x-lookup-key-sym (xim:commit)
+  ((flag :initform xim:commit-flag:x-lookup-key-sym)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (key-sym :initarg :key-sym :type xcb:KEYSYM)))
+
+(defclass xim:commit-x-lookup-chars (xim:commit)
+  ((flag :initform xim:commit-flag:x-lookup-chars)
+   (length :initarg :length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xcb:BYTE
+                             size (xcb:-fieldref 'length))
+            :type xcb:-list)
+   (pad~1 :initform '(xim:PADDING (xcb:-fieldref 'length)) :type xcb:-pad)))
+
+(defclass xim:commit-x-lookup-both (xim:commit-x-lookup-key-sym
+                                    xim:commit-x-lookup-chars)
+  ((flag :initform xim:commit-flag:x-lookup-both)
+   (pad~1 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+;;;; Reset IC
+
+(defclass xim:reset-ic (xim:-request)
+  ((~major-opcode :initform xim:opcode:reset-ic)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+(defclass xim:reset-ic-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:reset-ic-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (length :initarg :length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xcb:BYTE
+                             size (xcb:-fieldref 'length))
+            :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'length)))
+          :type xcb:-pad)))
+
+;;;; Callbacks
+
+;; Negotiating geometry
+(defclass xim:geometry (xim:-request)
+  ((~major-opcode :initform xim:opcode:geometry)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;; Converting a string
+(defclass xim:str-conversion (xim:-request)
+  ((~major-opcode :initform xim:opcode:str-conversion)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (position :initarg :position :type xcb:CARD16)
+   (pad~0 :initform 2 :type xcb:-pad)
+   (direction :initarg :direction :type xcb:CARD32)
+   (factor :initarg :factor :type xcb:CARD16)
+   (operation :initarg :operation :type xcb:CARD16)
+   (length :initarg :length :type xcb:INT16)))
+
+(defconst xim:caret-direction:forward-char 0)
+(defconst xim:caret-direction:backward-char 1)
+(defconst xim:caret-direction:forward-word 2)
+(defconst xim:caret-direction:backward-word 3)
+(defconst xim:caret-direction:caret-up 4)
+(defconst xim:caret-direction:caret-down 5)
+(defconst xim:caret-direction:next-line 6)
+(defconst xim:caret-direction:previous-line 7)
+(defconst xim:caret-direction:line-start 8)
+(defconst xim:caret-direction:line-end 9)
+(defconst xim:caret-direction:absolute-position 10)
+(defconst xim:caret-direction:dont-change 11)
+
+(defconst xim:string-conversion-operation:substitution 1)
+(defconst xim:string-conversion-operation:retrieval 2)
+
+(defclass xim:str-conversion-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:str-conversion-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (feedback :initarg :feedback :type xcb:CARD32)
+   (text :initarg :text :type xim:XIMSTRCONVTEXT)))
+
+;; Preedit callbacks
+(defclass xim:preedit-start (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-start)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+(defclass xim:preedit-start-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-start-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (return-value :initarg :return-value :type xcb:INT32)))
+
+(defclass xim:preedit-draw (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-draw)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (caret :initarg :caret :type xcb:INT32)
+   (chg-first :initarg :chg-first :type xcb:INT32)
+   (chg-length :initarg :chg-length :type xcb:INT32)
+   (status :initarg :status :type xim:BITMASK32)
+   (string-length :initarg :string-length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xcb:char
+                             size (xcb:-fieldref 'string-length))
+            :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'string-length)))
+          :type xcb:-pad)
+   (feedback-length :initarg :feedback-length :type xcb:-u2)
+   (pad~1 :initform 2 :type xcb:-pad)
+   (feedback :initarg :feedback :type xcb:-ignore)
+   (feedback~ :initform '(name feedback type xim:XIMFEEDBACK
+                               size (/ (xcb:-fieldref 'feedback-length) 4))
+              :type xcb:-list)))
+
+(defconst xim:preedit-draw-status:no-string 1)
+(defconst xim:preedit-draw-status:no-feedback 2)
+
+(defclass xim:preedit-caret (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-caret)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (position :initarg :position :type xcb:INT32)
+   (direction :initarg :direction :type xcb:CARD32)
+   (style :initarg :style :type xcb:CARD32)))
+
+(defconst xim:preedit-caret-style:invisible 0)
+(defconst xim:preedit-caret-style:primary 1)
+(defconst xim:preedit-caret-style:secondary 2)
+
+(defclass xim:preedit-caret-reply (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-caret-reply)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (position :initarg :position :type xcb:CARD32)))
+
+(defclass xim:preedit-done (xim:-request)
+  ((~major-opcode :initform xim:opcode:preedit-done)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+;; Preedit state notify
+(defclass xim:preeditstate (xim:-request)
+  ((~major-opcode :initform xim:opcode:preeditstate)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (state :initarg :state :type xim:BITMASK32)))
+
+(defconst xim:preeditstate:unknown 0)
+(defconst xim:preeditstate:enable 1)
+(defconst xim:preeditstate:disable 2)
+
+;; Status callbacks
+(defclass xim:status-start (xim:-request)
+  ((~major-opcode :initform xim:opcode:status-start)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+(defclass xim:status-draw (xim:-request)
+  ((~major-opcode :initform xim:opcode:status-draw)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)
+   (type :initarg :type :type xcb:CARD32)))
+
+(defconst xim:status-draw-type:text 0)
+(defconst xim:status-draw-type:bitmap 1)
+
+(defclass xim:status-draw-text (xim:status-draw)
+  ((type :initarg :type :initform xim:status-draw-type:text)
+   (status :initarg :status :type xim:BITMASK32)
+   (string-length :initarg :string-length :type xcb:-u2)
+   (string :initarg :string :type xcb:-ignore)
+   (string~ :initform '(name string type xcb:char
+                             size (xcb:-fieldref 'string-lessp))
+            :type xcb:-list)
+   (pad~0 :initform '(xim:PADDING (+ 2 (xcb:-fieldref 'string-length)))
+          :type xcb:-pad)
+   (feedback-length :initarg :feedback-length :type xcb:-u2)
+   (pad~1 :initform 2 :type xcb:-pad)
+   (feedback :initarg :feedback :type xcb:-ignore)
+   (feedback~ :initform '(name feedback type xim:XIMFEEDBACK
+                               size (/ (xcb:-fieldref 'feedback-length) 4))
+              :type xcb:-list)))
+
+(defclass xim:status-draw-bitmap (xim:status-draw)
+  ((type :initarg :type :initform xim:status-draw-type:bitmap)
+   (pixmap-data :initarg :pixmap-data :type xcb:PIXMAP)))
+
+(defclass xim:status-done (xim:-request)
+  ((~major-opcode :initform xim:opcode:status-done)
+   (im-id :initarg :im-id :type xcb:CARD16)
+   (ic-id :initarg :ic-id :type xcb:CARD16)))
+
+
+
+(provide 'xcb-xim)
+
+;;; xcb-xim.el ends here
diff --git a/xcb-xlib.el b/xcb-xlib.el
new file mode 100644
index 0000000..f5e86d8
--- /dev/null
+++ b/xcb-xlib.el
@@ -0,0 +1,113 @@
+;;; xcb-xlib.el --- Port of Xlib  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2015 Chris Feng
+
+;; Author: Chris Feng <address@hidden>
+;; Keywords: unix
+
+;; This file is not part of GNU Emacs.
+
+;; This file is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;  This file currently only contains constants from 'Xlib.h'
+
+;;; Code:
+
+(defconst xlib:XNRequiredCharSet "requiredCharSet")
+(defconst xlib:XNQueryOrientation "queryOrientation")
+(defconst xlib:XNBaseFontName "baseFontName")
+(defconst xlib:XNOMAutomatic "omAutomatic")
+(defconst xlib:XNMissingCharSet "missingCharSet")
+(defconst xlib:XNDefaultString "defaultString")
+(defconst xlib:XNOrientation "orientation")
+(defconst xlib:XNDirectionalDependentDrawing "directionalDependentDrawing")
+(defconst xlib:XNContextualDrawing "contextualDrawing")
+(defconst xlib:XNFontInfo "fontInfo")
+
+(defconst xlib:XNVaNestedList "XNVaNestedList")
+(defconst xlib:XNQueryInputStyle "queryInputStyle")
+(defconst xlib:XNClientWindow "clientWindow")
+(defconst xlib:XNInputStyle "inputStyle")
+(defconst xlib:XNFocusWindow "focusWindow")
+(defconst xlib:XNResourceName "resourceName")
+(defconst xlib:XNResourceClass "resourceClass")
+(defconst xlib:XNGeometryCallback "geometryCallback")
+(defconst xlib:XNDestroyCallback "destroyCallback")
+(defconst xlib:XNFilterEvents "filterEvents")
+(defconst xlib:XNPreeditStartCallback "preeditStartCallback")
+(defconst xlib:XNPreeditDoneCallback "preeditDoneCallback")
+(defconst xlib:XNPreeditDrawCallback "preeditDrawCallback")
+(defconst xlib:XNPreeditCaretCallback "preeditCaretCallback")
+(defconst xlib:XNPreeditStateNotifyCallback "preeditStateNotifyCallback")
+(defconst xlib:XNPreeditAttributes "preeditAttributes")
+(defconst xlib:XNStatusStartCallback "statusStartCallback")
+(defconst xlib:XNStatusDoneCallback "statusDoneCallback")
+(defconst xlib:XNStatusDrawCallback "statusDrawCallback")
+(defconst xlib:XNStatusAttributes "statusAttributes")
+(defconst xlib:XNArea "area")
+(defconst xlib:XNAreaNeeded "areaNeeded")
+(defconst xlib:XNSpotLocation "spotLocation")
+(defconst xlib:XNColormap "colorMap")
+(defconst xlib:XNStdColormap "stdColorMap")
+(defconst xlib:XNForeground "foreground")
+(defconst xlib:XNBackground "background")
+(defconst xlib:XNBackgroundPixmap "backgroundPixmap")
+(defconst xlib:XNFontSet "fontSet")
+(defconst xlib:XNLineSpace "lineSpace")
+(defconst xlib:XNCursor "cursor")
+(defconst xlib:XNQueryIMValuesList "queryIMValuesList")
+(defconst xlib:XNQueryICValuesList "queryICValuesList")
+(defconst xlib:XNVisiblePosition "visiblePosition")
+(defconst xlib:XNR6PreeditCallback "r6PreeditCallback")
+(defconst xlib:XNStringConversionCallback "stringConversionCallback")
+(defconst xlib:XNStringConversion "stringConversion")
+(defconst xlib:XNResetState "resetState")
+(defconst xlib:XNHotKey "hotKey")
+(defconst xlib:XNHotKeyState "hotKeyState")
+(defconst xlib:XNPreeditState "preeditState")
+(defconst xlib:XNSeparatorofNestedList "separatorofNestedList")
+
+(defconst xlib:XIMPreeditArea #x0001)
+(defconst xlib:XIMPreeditCallbacks #x0002)
+(defconst xlib:XIMPreeditPosition #x0004)
+(defconst xlib:XIMPreeditNothing #x0008)
+(defconst xlib:XIMPreeditNone #x0010)
+(defconst xlib:XIMStatusArea #x0100)
+(defconst xlib:XIMStatusCallbacks #x0200)
+(defconst xlib:XIMStatusNothing #x0400)
+(defconst xlib:XIMStatusNone #x0800)
+
+(defconst xlib:XIMReverse #x001)
+(defconst xlib:XIMUnderline #x002)
+(defconst xlib:XIMHighlight #x004)
+(defconst xlib:XIMPrimary #x010)
+(defconst xlib:XIMSecondary #x020)
+(defconst xlib:XIMTertiary #x040)
+(defconst xlib:XIMVisibleToForward #x080)
+(defconst xlib:XIMVisibleToBackword #x100)
+(defconst xlib:XIMVisibleToCenter #x200)
+
+(defconst xlib:XBufferOverflow -1)
+(defconst xlib:XLookupNone 1)
+(defconst xlib:XLookupChars 2)
+(defconst xlib:XLookupKeySym 3)
+(defconst xlib:XLookupBoth 4)
+
+
+
+(provide 'xcb-xlib)
+
+;;; xcb-xlib.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]