# XC-MISC Extension

## Overview

When an X client connects to an X server, it receives a fixed range of resource IDs to use to identify the client's resources inside the X server. Xlib hands these out sequentially as needed. When it overruns the end of the range, an IDChoice protocol error results. Long running clients, or clients that use resource IDs at a rapid rate, may encounter this circumstance. When it happens, there are usually many resource IDs available, but Xlib doesn't know about them.

One approach to solving this problem would be to have Xlib notice when a resource is freed and recycle its ID for future use. This strategy runs into difficulties because sometimes freeing one resource causes others to be freed (for example, when a window is destroyed, so are its children). To do a complete job, Xlib would have to maintain a large amount of state that currently resides only in the server (the entire window tree in the above example). Even if a less comprehensive strategy was adopted, such as recycling only those IDs that Xlib can identify without maintaining additional state, the additional bookkeeping at resource creation and destruction time would likely introduce unacceptable overhead.

To avoid the problems listed above, the server's complete knowledge of all resource IDs in use by a client is leveraged. This extension provides two ways for Xlib to query the server for available resource IDs. Xlib can use these extension requests behind the scenes when it has exhausted its current pool of resource IDs.

## Requests

`XCMiscGetVersion`

- `client_major_version`: CARD16

- `client_minor_version`: CARD16

=>

- `client_major_version`: CARD16

- `client_minor_version`: CARD16

If supplied, the `client_major_version` and `client_minor_version` indicate what version of the protocol the client wants the server to implement. The server version numbers returned indicate the protocol this extension actually supports. This might not equal the version sent by the client. An implementation can (but need not) support more than one version simultaneously. The `server_major_version` and the `server_minor_version` are a mechanism to support future revisions of the XC-MISC protocol which may be necessary. In general, the major version would increment for incompatible changes, and the minor version would increment for small, upward-compatible changes. Servers that support the protocol defined in this document will return a `server_major_version` of one (1), and a `server_minor_version` of one (1).

`XCMiscGetXIDRange`

=>

- `start_id`: XID

- `count`: CARD32

This request returns a range of available resource IDs for the client issuing the request. `start_id` is the first ID in the range. `count` is the number of IDs in the range. The returned range may or may not be the largest possible range.

`XCMiscGetXIDList`

- `count`: CARD32

=>

- `ids`: LISTofXID

This request returns the a list of individual resource IDs in `ids`. `count` is the number of resource IDs requested. The number returned may be smaller than the number requested.

## Events and Errors

No new events or errors are defined by this extension.

## Encoding

Please refer to the X11 Protocol Encoding document as this document uses conventions established there.

The name of this extension is “XC-MISC”.

    XCMiscGetVersion
         1     CARD8          opcode
         1     0                      XC-MISC opcode
         2     2                      request length
         2     CARD16         client_major_version
         2     CARD16         client_minor_version

     =>
         1     1          Reply
         1                unused
         2     CARD16     sequence number
         4     0          length
         2     CARD16     server_major_version
         2     CARD16     server_minor_version
         20               unused

    XCMiscGetXIDRange
         1     CARD8        opcode
         1     1                   XC-MISC opcode
         2     1                   request length

     =>
         1     1          Reply
         1                unused
         2     CARD16     sequence number
         4     0          length
         4     XID        start_id
         4     CARD32     count
         16               unused

    XCMiscGetXIDList
         1     CARD8          opcode
         1     2                      XC-MISC opcode
         2     2                      request length
         4     CARD32         count

     =>
         1     1          Reply
         1                unused
         2     CARD16     sequence number
         4     CARD32     length
         4     CARD32     number of XIDs in ids
         20               unused
         4n    LISTofXID  ids