Reference
Extra X Input 2 Samples
test_xi2 is a perfect example from Peter Hutterer on how to retrieve XI2 Events. To get to the details of the data format, please read the routines that print the events.
XI2 recipes is a series of six short programs from Peter on how to deal with the functionalities in XI2. The whole set of source code can be found at Peter's freedesktop.org page.
SDL is an up-to-date, real-world example.
X Input Headers and Protocol
XI2.h defines the XI2 event constants, event types, and event masks.
XInput2.h defines the XI2 data structs and functions. Your application only needs to include this header since XI2.h is included in this file.
xorgproto stores the latest XI2 protocol. If you are interested in how the protocol structs are defined, please take a look at XI2proto.h. This header file is only useful to libXi. Do not include it in your code.
XI1 event classes, constants, data structs, routines, and protocol structs are defined in XI.h, XInput.h and XIproto.h respectively, in case you need to compare the differences.