XICHANGEPROPERTY(3)

XIChangeProperty ✨

okay so bestie, we're doing XICHANGEPROPERTY(3) today β€” the whole change / retrieve / delete a device's property situation. no cap, this one's a banger. πŸŽ€

three functions, one vibe: XIChangeProperty, XIGetProperty, XIDeleteProperty. that's the family. 🫢


🌸 SYNOPSIS 🌸

#include <X11/extensions/XInput2.h>

void XIChangeProperty( Display* dpy,
                       int deviceid,
                       Atom property,
                       Atom type,
                       int format,
                       int mode,
                       unsigned char *data,
                       int num_items)

void XIDeleteProperty( Display *dpy,
                       int deviceid,
                       Atom property)

Status XIGetProperty( Display *dpy,
                      int deviceid,
                      Atom property,
                      long offset,
                      long length,
                      Bool delete_property,
                      Atom type,
                      Atom *type_return,
                      int *format_return,
                      unsigned long *num_items_return,
                      unsigned long *bytes_after_return,
                      unsigned char **data)

πŸ’… THE ARGUMENTS, ONE BY ONE (they ate) πŸ’…

  • bytes_after_return β€” hands you back how many bytes are still chillin' unread in the property, y'know, if the read got cut short and only did a partial.
  • data β€” the property data itself. that's it, that's the girl. πŸ’–
  • display β€” the connection to the X server. your lil phone line to the server, basically.
  • delete_property β€” a Boolean that decides whether the property gets deleted or not. yes/no energy.
  • deviceid β€” the device we're listing the properties for.
  • format β€” says whether the data should be read as a list of 8-bit, 16-bit, or 32-bit quantities. possible values: 8, 16, and 32. this is so the X server can do its byte-swap operations correctly when it needs to. ⚠️ lowkey important: if the format is 16-bit or 32-bit, you must explicitly cast your data pointer to an (unsigned char *) in the call to XIChangeProperty. do not skip that.
  • format_return β€” returns the actual format of the property. the real one. not the one you asked for.
  • length β€” the length in 32-bit multiples of the data you wanna retrieve.
  • offset β€” the offset in the specified property (in 32-bit quantities) where the data is to be retrieved.
  • mode β€” one of XIPropModeAppend, XIPropModePrepend or XIPropModeReplace. pick your fighter.
  • num_items β€” how many items are in data, in the format you specified.
  • nitems_return β€” returns the actual number of 8-bit, 16-bit, or 32-bit items stored in data.
  • property β€” the property name.
  • type β€” the type of the property. the X server does not interpret this type, it just hands it right back to whatever application later calls XIGetProperty. it's not nosy, it's just the messenger. πŸ™ˆ
  • type_return β€” returns the atom identifier that defines the actual type of the property.

πŸ”₯ DESCRIPTION πŸ”₯

so XIGetProperty returns, in order: the actual type of the property, the actual format of the property, the number of 8-bit/16-bit/32-bit items transferred, the number of bytes still left to read in the property, and a pointer to the data that actually got returned. she does a lot. πŸ‘‘

XIGetProperty sets the return arguments like this:

  • if the specified property doesn't exist for the specified device, XIGetProperty returns None to actual_type_return and the value zero to actual_format_return and bytes_after_return. the nitems_return argument is empty. and in this case, the delete argument is ignored. πŸ™…
  • if the specified property exists but its type doesn't match the specified type, XIGetProperty returns the actual property type to actual_type_return, the actual property format (never zero) to actual_format_return, and the property length in bytes (even if actual_format_return is 16 or 32) to bytes_after_return. it also ignores the delete argument. the nitems_return argument is empty.
  • if the specified property exists and either you assigned XIAnyPropertyType to the req_type argument or the specified type matches the actual property type, XIGetProperty returns the actual property type to actual_type_return and the actual property format (never zero) to actual_format_return. it also returns a value to bytes_after_return and nitems_return, by defining these values:
N = length of the stored property in bytes
I = 4 * offset
T = N - I
L = MINIMUM(T, 4 * 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 makes L go negative, you get a BadValue error. the value of bytes_after_return is A, which gives you the number of trailing unread bytes in the stored property.

so like, about the returned format:

  • 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 uint16_t array and you should cast it to that type to get the elements.
  • if the returned format is 32, the returned data is represented as a uint32_t array and you should cast it to that type to get the elements.

XIGetProperty always allocates one extra byte in prop_return (even if the property is zero length) and sets it to zero, so that simple properties made of characters don't have to be copied into yet another string before you can use them. it's giving considerate. πŸ₯Ίβœ¨

if delete is True and bytes_after_return is zero, XIGetProperty deletes the property from the window and generates an XIPropertyNotify event on the window.

the function returns Success if it executes successfully. to free the resulting data, use XFree. 🫢

XIGetProperty can generate BadAtom, BadValue, and BadWindow errors.


so XIChangeProperty alters the property for the specified device and causes the X server to generate an XIPropertyNotify event for that device. here's what it does:

  • if mode is XIPropModeReplace, XIChangeProperty discards the previous property value and stores the new data. out with the old, in with the new. πŸ’…
  • if mode is XIPropModePrepend or XIPropModeAppend, XIChangeProperty inserts 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 a BadMatch error results. if the property is undefined, it's treated as defined with the correct type and format with zero-length data.

format rules, no exceptions:

  • 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 uint16_t array.
  • if the specified format is 32, the property data must be a uint32_t array.

the lifetime of a property is not tied to the storing client. properties remain until explicitly deleted, until the device is removed, or until the server resets. the maximum size of a property is server dependent and can vary dynamically depending on how much memory the server has available. (if there's insufficient space, a BadAlloc error results.) so like, don't assume it'll always fit, bestie. 😭

XIChangeProperty can generate BadAlloc, BadAtom, BadMatch, BadValue, and BadDevice errors.

XIDeleteProperty deletes the specified property only if the property was defined on the specified device, and causes the X server to generate an XIPropertyNotify event for the device β€” unless the property doesn't exist, in which case, nothing. πŸ’€

XIDeleteProperty can generate BadAtom and BadDevice 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.
  • BadDevice β€” an invalid device was specified. the device does not exist.
  • BadAtom β€” an invalid property was specified. the property does not exist.
yes bestie, BadAtom shows up twice in the original list. i'm not gonna edit the universe, i'm just reporting it. πŸ™ˆ

πŸ› BUGS πŸ›

the protocol headers for XI 2.0 did not provide XIAnyPropertyType, XIPropModeReplace, XIPropModePrepend or XIPropModeAppend. use AnyPropertyType, PropModeReplace, PropModePrepend and PropModeAppend instead, respectively. so like, if the fancy XI 2.0 names aren't there, the old ones are your girls. πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

XIListProperties(3)


and that's the whole page, bestie!! πŸ¦‹ this version is the XICHANGEPROPERTY(3) manual page dated 05/18/2026 β€” go forth and manage your properties, you absolute icon. slay, periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from