Zum Hauptinhalt springen

Connection Setup

For remote clients, the X protocol can be built on top of any reliable byte stream. For TCP connections, displays on a given host a numbered starting from 0, and the server for display N listens and accepts connections on port 6000+N.

The client must send an initial byte of data to identify the byte order to be employed. The value of the byte must be octal 102 or 154. The value 102 (ASCII uppercase B) means values are transmitted most significant byte first, and value 154 (ASCII lowercase l) means values are transmitted least significant byte first. Except where explicitly noted in the protocol, all 16-bit and 32-bit quantities sent by the client must be transmitted with this byte order, and all 16-bit and 32-bit quantities returned by the server will be transmitted with this byte order.

Following the byte-order byte, the following information is sent by the client at connection setup:

protocol-major-version: CARD16
protocol-minor-version: CARD16
authorization-protocol-name: STRING8
authorization-protocol-data: STRING8

The version numbers indicate what version of the protocol the client expects the server to implement. See below for an explanation. The authorization name indicates what authorization protocol the client expects the server to use, and the data is specific to that protocol. Specification of valid authorization mechanisms is not part of the core X protocol. It is hoped that eventually one authorization protocol will be agreed upon. In the mean time, a server that implements a different protocol than the client expects, or a server that only implements the host-based mechanism, will simply ignore this information.

Received by the client at connection setup​

success: BOOL
protocol-major-version: CARD16
protocol-minor-version: CARD16
length: CARD16

Length is the amount of additional data to follow, in units of 4 bytes. The version numbers are an escape hatch in case future revisions of the protocol are necessary. In general, the major version would increment for incompatible changes, and the minor version would increment for small upward compatible changes. Barring changes, the major version will be eleven, and the minor version will be zero. The protocol version numbers returned indicate the protocol the server actually supports. This might not equal the version sent by the client. The server can (but need not) refuse connections from clients that offer a different version than the server supports. A server can (but need not) support more than one version simultaneously.

Additional data received if authorization fails​

reason: STRING8

Additional data received if authorization is accepted​

vendor: STRING8
release-number: CARD32
resource-id-base, resource-id-mask: CARD32
image-byte-order: {LSBFirst, MSBFirst}
bitmap-format-scanline-unit: {8, 16, 32}
bitmap-format-scanline-pad: {8, 16, 32}
bitmap-format-bit-order: {LeastSignificant, MostSignificant}
pixmap-formats: LISTofFORMAT
roots: LISTofSCREEN
keyboard: DEVICE
pointer: DEVICE
motion-buffer-size: CARD32
maximum-request-length: CARD16

where FORMAT: [depth: CARD8,

bits-per-pixel: {4, 8, 16, 24, 32}
scanline-pad: {8, 16, 32}]

SCREEN: [root: WINDOW

device: DEVICE
width-in-pixels, height-in-pixels: CARD16
width-in-millimeters,height-in-millimeters:CARD16
allowed-depths: LISTofDEPTH
root-depth: CARD8
root-visual: VISUALID
default-colormap: COLORMAP
white-pixel, black-pixel: CARD32
min-installed-maps, max-installed-maps: CARD16
backing-stores: {Never, WhenMapped, Always}
save-unders: BOOL
current-input-masks: SETofEVENT]

DEPTH: [depth: CARD8

visuals: LISTofVISUALTYPE]

VISUALTYPE: [visual-id: VISUALID

class: {StaticGray, StaticColor,
TrueColor,GrayScale, PseudoColor,
DirectColor}
red-mask, green-mask, blue-mask: CARD32
bits-per-rgb-value: CARD8
colormap-entries: CARD16]

Per server information​

The vendor string gives some indentification of the owner of the server implementation. The semantics of the release-number is controlled by the vendor.

The resource-id-mask contains a single contiguous set of bits (at least 18); the client allocates resource ids by choosing a value with (only) some subset of these bits set, and ORing it with resource-id-base. Only values constructed in this way can be used to name newly created resources over this connection. Resource ids never have the top 3 bits set. The client is not restricted to linear or contiguous allocation of resource ids. Once an id has been freed, it can be reused, but this should not be necessary. An id must be unique with respect to the ids of all other resources, not just other resources of the same type.

Although the server is in general responsible for byte swapping data to match the client, images are always transmitted and received in formats (including byte order) specified by the server. The byte order for images is given by image-byte-order, and applies to each scanline unit in XYFormat (bitmap) format, and to each pixel value in ZFormat.

A bitmap is represented in scanline order. Each scanline is padded to a multiple of bits as given by bitmap-format-scanline-pad. The pad bits are of arbitrary value. The scanline is quantized in multiples of bits as given by bitmap-format-scanline-unit. Within each unit, the leftmost bit in the bitmap is either the least or most significant bit in the unit, as given by bitmap-format-bit-order. If a pixmap is represented in XYFormat, each plane is represented as a bitmap, and the planes appear from most to least significant in bit order.

For each pixmap depth supported by some screen, pixmap-formats lists the ZFormat used to represent images of that depth. In ZFormat, the pixels are in scanline order, left to right within a scanline. The number of bits used to hold each pixel is given by bits-per-pixel, and may be larger than strictly required by the depth. When the bits-per-pixel is 4, the order of nibbles in the byte is the same as the image byte-order. Each scanline is padded to a multiple of bits as given by scanline-pad.

How a pointing device roams the screens is up to the server implementation, and is transparent to the protocol. No geometry among screens is defined.

The server may retain the recent history of pointer motion, and to a finer granularity than is reported by MotionNotify events. Such history is available via the GetPointerMotions request. The approximate size of the history buffer is given by motion-buffer-size.

Maximum-request-length specifies the maximum length of a request, in 4-byte units, accepted by the server; i.e., this is the maximum value that can appear in the length field of a request. Requests larger than this generate a Length error, and the server will read and simply discard the entire request. Maximum-request-length will always be at least 4096 (i.e., requests of length up to and including 16384 bytes will be accepted by all servers).

Per screen information​

The allowed-depths specifies what pixmap and window depths are supported. Pixmaps are supported for each depth listed, and windows of that depth are supported if at least one visual type is listed for the depth. A pixmap depth of one is always supported and listed, but windows of depth one might not be supported. A depth of zero is never listed, but zero-depth InputOnly windows are always supported.

Root-depth and root-visual specify the depth and visual type of the root window. Width-in-pixels and height-in-pixels specify the size of the root window (which cannot be changed). The class of the root window is always InputOutput. Width-in-millimeters and height-in-millimeters can be used to determine the physical size and the aspect ratio.

The default-colormap is the one initially associated with the root window. Clients with minimal color requirements creating windows of the same depth as the root may want to allocate from this map by default.

Black-pixel and white-pixel can be used in implementing a "monochrome" application. These pixel values are for permanently allocated entries in the default-colormap; the actual RGB values may be settable on some screens.

The border of the root window is initially a pixmap filled with the black-pixel. The initial background of the root window is a pixmap filled with some unspecified two-color pattern using black-pixel and white-pixel.

Min-installed-maps specifies the number of maps that can be guaranteed to installed simultaneously (with InstallColormap), regardless of the number of entries allocated in each map. Max-installed-maps specifies the maximum number of maps that might possibly be installed simultaneously, depending on their allocations. For the typical case of a single hardware colormap, both values will be one.

Backing-stores indicates when the server supports backing stores for this screen, although it may be storage limited in the number of windows it can support at once. If save-unders is True, then the a server can support the save-under mode in CreateWindow and ChangeWindowAttributes, although again it may be storage limited.

The current-input-events is what GetWindowAttributes would return for the all-event-masks for the root window.

Per visual-type information​

A given visual type might be listed for more than one depth, or for more than one screen.

For PseudoColor, a pixel value indexes a colormap to produce independent RGB values; the RGB values can be changed dynamically. GrayScale is treated the same as PseudoColor, except which primary drives the screen is undefined, so the client should always store the same value for red, green, and blue in colormaps. For DirectColor, a pixel value is decomposed into separate RGB subfields, and each subfield separately indexes the colormap for the corresponding value; The RGB values can be changed dynamically. TrueColor is treated the same as DirectColor, except the colormap has predefined read-only RGB values, which are server-dependent, but provide (near-)linear ramps in each primary. StaticColor is treated the same as PseudoColor, except the colormap has predefined read-only RGB values, which are server-dependent. StaticGray is treated the same as StaticColor, except the red, green, and blue values are equal for any single pixel value, resulting in shades of gray. StaticGray with a two-entry colormap can be thought of as "monochrome".

The red-mask, green-mask, and blue-mask are only defined for DirectColor and TrueColor; each has one contiguous set of bits, with no intersections.

The bits-per-rgb-value specifies the log base 2 of the approximate number of distinct color values (individually) of red, green, and blue. Actual RGB values are always passed in the protocol within a 16-bit spectrum.

The colormap-entries defines the number of available colormap entries in a newly created colormap. For DirectColor and TrueColor, this will usually be the size of an individual pixel subfield.