Deprecated information

The following is a description of the devPrivates system before the serious overhaul. It is now outdated.

Client devPrivates are similar to those of the ScreenRec and DeviceIntRec structures, but those have their own API to initialize and access them. Please note that there a overhaul of the devPrivates system in progress and this information may be out of date soon - see http://lists.freedesktop.org/archives/xorg/2007-March/022212.html.

Need to be initialised at start time, as each time a client is allocated. The devPrivates are an array of DevUnions that are allocated when the client starts and released when the client finishes. Each client has the same size allocated for devPrivates and at the moment there are no methods to resize the array at a later point in time. Better make sure you allocate everything on server startup before the first client connects.

AllocateClientPrivatesIndex() gives you an index into the array. Each time you need to access your data, access it with client->devPrivates[MyIndex].ptr and cast it to your specific data information. Immediately after retrieving your index, call AllocateClientPrivate(MyIndex, size), where size is the number of bytes you need for your private struct in bytes. You can now assume that every client that connects will have enough space for your data.

Finally, you will probably want to add a callback to reset the data when a client starts up. Use AddCallback() to register your function and then do stuff. The first argument is always the same (ClientStateCallback), the second your callback proc and the third one some pointer data which will get passed into the callback function (argument closure in example below). Most extensions just pass in 0. You need to check the state of the client in the callback function. If client->state is ClientStateRunning then the client has just started up, ClientStateGone or ClientStateRetained means it has been shut down. There are a few other states. (comment by Eamon Walsh)

I recommend looking at damageext/damageext.c, it has a low signal-to-noise ratio. The full code you need:

Finally, you want to add a DeleteCallback() call to remove your callback when the extension resets.

Notes

The client that owns the root window is serverClient and will be created before extensions initialize. It will (most likely) not have devPrivates set to what you added, so make sure you cater for this.

Window DevPrivates

The devPrivates of a WindowRec are stored after the struct's memory. Each screen keeps a totalWindowSize for the memory that is to be allocated per screen. The memory for a WindowRec with 4 devPrivates entries looks approximately like this:

With 1 = &A, 2 = &B,etc. Before you allocate a window, you need to call AllocateWindowPrivate() with the size you need for your entry. A, B, C, D have the sizes that were specified for AllocateWindowPrivate