XGetWindowProperty(3)
π
XGetWindowProperty(3) β window properties, but make it make sense
okay so welcome to the XLIB FUNCTIONS corner of the manual, bestie. This page is all about XGetWindowProperty, XListProperties, XChangeProperty, XRotateWindowProperties, and XDeleteProperty β the little property squad. Their whole thing is: obtain and change window properties. Periodt. π
β¨ NAME β¨
These five are the property girlies: XGetWindowProperty, XListProperties, XChangeProperty, XRotateWindowProperties, and XDeleteProperty β they obtain and change window properties. Thatβs the vibe. π«Ά
π¦ SYNTAX π¦
int XGetWindowProperty(Display *display, Window w, Atom property, long
long_offset, long long_length, Bool delete, Atom req_type, Atom
*actual_type_return, int *actual_format_return, unsigned long
*nitems_return, unsigned long *bytes_after_return, unsigned char
**prop_return);
Atom *XListProperties(Display *display, Window w, int *num_prop_return);
int XChangeProperty(Display *display, Window w, Atom property, Atom
type, int format, int mode, _Xconst unsigned char *data, int
nelements);
int XRotateWindowProperties(Display *display, Window w, Atom
properties[], int num_prop, int npositions);
int XDeleteProperty(Display *display, Window w, Atom property);
π ARGUMENTS π
actual_format_returnβ hands back the actual format of the property.actual_type_returnβ returns the atom identifier that defines the actual type of the property.bytes_after_returnβ returns the number of bytes remaining to be read in the property if a partial read was performed.dataβ specifies the property data.deleteβ a Boolean value that determines whether the property is deleted.displayβ specifies the connection to the X server.formatβ specifies whether the data should be viewed as a list of8-bit,16-bit, or32-bit quantities. Possible values are8,16, and32. This information allows the X server to correctly perform byte-swap operations as necessary. If the format is16-bit or32-bit, you must explicitly cast your data pointer to an(unsigned char *)in the call toXChangeProperty.long_lengthβ specifies the length in 32-bit multiples of the data to be retrieved.long_offsetβ specifies the offset in the specified property (in 32-bit quantities) where the data is to be retrieved.modeβ specifies the mode of the operation. You can passPropModeReplace,PropModePrepend, orPropModeAppend.nelementsβ specifies the number of elements of the specified data format.nitems_returnβ returns the actual number of 8-bit, 16-bit, or 32-bit items stored in theprop_returndata.num_propβ specifies the length of the properties array.num_prop_returnβ returns the length of the properties array.npositionsβ specifies the rotation amount.prop_returnβ returns the data in the specified format. If the returned format is8, the returned data is represented as a char array. If the returned format is16, the returned data is represented as an array of short int type and should be cast to that type to obtain the elements. If the returned format is32, the property data will be stored as an array of longs (which in a 64-bit application will be 64-bit values that are padded in the upper 4 bytes).propertyβ specifies the property name.propertiesβ specifies the array of properties that are to be rotated.req_typeβ specifies the atom identifier associated with the property type orAnyPropertyType.typeβ specifies the type of the property. The X server does not interpret the type but simply passes it back to an application that later callsXGetWindowProperty.wβ specifies the window whose property you want to obtain, change, rotate or delete.
πΈ DESCRIPTION πΈ
okay so XGetWindowProperty is the main character here. It returns the actual type of the property; the actual format of the property; the number of 8-bit, 16-bit, or 32-bit items transferred; the number of bytes remaining to be read in the property; and a pointer to the data actually returned. XGetWindowProperty sets the return arguments as follows:
- If the specified property does not exist for the specified window,
XGetWindowPropertyreturnsNonetoactual_type_returnand the value zero toactual_format_returnandbytes_after_return. Thenitems_returnargument is empty. In this case, thedeleteargument is ignored. - If the specified property exists but its type does not match the specified type,
XGetWindowPropertyreturns the actual property type toactual_type_return, the actual property format (never zero) toactual_format_return, and the property length in bytes (even if theactual_format_returnis16or32) tobytes_after_return. It also ignores thedeleteargument. Thenitems_returnargument is empty. - If the specified property exists and either you assign
AnyPropertyTypeto thereq_typeargument or the specified type matches the actual property type,XGetWindowPropertyreturns the actual property type toactual_type_returnand the actual property format (never zero) toactual_format_return. It also returns a value tobytes_after_returnandnitems_return, by defining the following values:
N = actual length of the stored property in bytes
(even if the format is 16 or 32)
I = 4 * long_offset
T = N - I
L = MINIMUM(T, 4 * long_length)
A = N - (I + L)
The returned value starts at byte index I in the property (indexing from zero), and its length in bytes is L. If the value for long_offset causes L to be negative, a BadValue error results. The value of bytes_after_return is A, giving the number of trailing unread bytes in the stored property.
If the returned format is 8, the returned data is represented as a char array. If the returned format is 16, the returned data is represented as a short array and should be cast to that type to obtain the elements. If the returned format is 32, the returned data is represented as a long array and should be cast to that type to obtain the elements.
XGetWindowProperty always allocates one extra byte in prop_return (even if the property is zero length) and sets it to zero so that simple properties consisting of characters do not have to be copied into yet another string before use. iconic behavior tbh. β¨
If delete is True and bytes_after_return is zero, XGetWindowProperty deletes the property from the window and generates a PropertyNotify event on the window.
The function returns Success if it executes successfully. To free the resulting data, use XFree.
XGetWindowProperty can generate BadAtom, BadValue, and BadWindow errors.
The XListProperties function returns a pointer to an array of atom properties that are defined for the specified window or returns NULL if no properties were found. To free the memory allocated by this function, use XFree. π§
XListProperties can generate a BadWindow error.
The XChangeProperty function alters the property for the specified window and causes the X server to generate a PropertyNotify event on that window. XChangeProperty performs the following:
- If
modeisPropModeReplace,XChangePropertydiscards the previous property value and stores the new data. - If
modeisPropModePrependorPropModeAppend,XChangePropertyinserts the specified data before the beginning of the existing data or onto the end of the existing data, respectively. The type and format must match the existing property value, or aBadMatcherror results. If the property is undefined, it is treated as defined with the correct type and format with zero-length data.
If the specified format is 8, the property data must be a char array. If the specified format is 16, the property data must be a short array. If the specified format is 32, the property data must be a long array.
The lifetime of a property is not tied to the storing client. Properties remain until explicitly deleted, until the window is destroyed, or until the server resets. For a discussion of what happens when the connection to the X server is closed, see section 2.6. The maximum size of a property is server dependent and can vary dynamically depending on the amount of memory the server has available. If there is insufficient space, a BadAlloc error results.
XChangeProperty can generate BadAlloc, BadAtom, BadMatch, BadValue, and BadWindow errors.
The XRotateWindowProperties function allows you to rotate properties on a window and causes the X server to generate PropertyNotify events. If the property names in the properties array are viewed as being numbered starting from zero and if there are num_prop property names in the list, then the value associated with property name I becomes the value associated with property name (I + npositions) mod N for all I from zero to N - 1. The effect is to rotate the states by npositions places around the virtual ring of property names (right for positive npositions, left for negative npositions). If npositions mod N is nonzero, the X server generates a PropertyNotify event for each property in the order that they are listed in the array. If an atom occurs more than once in the list or no property with that name is defined for the window, a BadMatch error results. If a BadAtom or BadMatch error results, no properties are changed.
XRotateWindowProperties can generate BadAtom, BadMatch, and BadWindow errors.
The XDeleteProperty function deletes the specified property only if the property was defined on the specified window and causes the X server to generate a PropertyNotify event on the window unless the property does not exist.
XDeleteProperty can generate BadAtom and BadWindow errors.
π DIAGNOSTICS π
BadAllocβ the server failed to allocate the requested resource or server memory.BadAtomβ a value for an Atom argument does not name a defined Atom.BadValueβ some numeric value falls outside the range of values accepted by the request. Unless a specific range is specified for an argument, the full range defined by the argumentβs type is accepted. Any argument defined as a set of alternatives can generate this error.BadWindowβ a value for a Window argument does not name a defined Window.
π SEE ALSO π
Go read XFree(3) and XInternAtom(3), plus the big one: Xlib - C Language X Interface. iykyk. π
mwah π β this page is stamped X Version 11 and libX11 1.8.14 in the footer, bestie; thereβs no separate date on that line, so Iβm not gonna invent one. π«Ά
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms