XGetWindowAttributes(3)
๐ XGetWindowAttributes(3) ๐
okay bestie, welcome to the XLIB FUNCTIONS corner of the group chat ๐
this page is all about peeking at a windowโs current attributes or geometry, and also the whole XWindowAttributes struct situation. no cap, itโs giving โlook at me, I know whatโs happening inside the X serverโ energy โจ
๐ธ NAME ๐ธ
XGetWindowAttributes, XGetGeometry, XWindowAttributes โ grab the current window attribute or geometry, plus the current window attributes structure. iconic little trio fr fr ๐ซถ
โจ SYNTAX โจ
Status XGetWindowAttributes(Display *display, Window w,
XWindowAttributes *window_attributes_return);
Status XGetGeometry(Display *display, Drawable d, Window *root_return,
int *x_return, int *y_return, unsigned int *width_return,
unsigned int *height_return, unsigned int *border_width_return,
unsigned int *depth_return);
๐ ARGUMENTS ๐
border_width_returnโ returns the border width, in pixels ๐dโ specifies the drawable, which can be a window or a pixmap ๐ชdepth_returnโ returns the depth of the drawable (thatโs bits per pixel for the object) ๐displayโ specifies the connection to the X server ๐root_returnโ returns the root window ๐wโ specifies the window whose current attributes you want to obtain ๐width_return,height_returnโ return the drawableโs dimensions (width and height) ๐window_attributes_returnโ returns the specified windowโs attributes inside theXWindowAttributesstructure ๐งx_return,y_returnโ return the x and y coordinates that define the location of the drawable. For a window, these coordinates specify the upper-left outer corner relative to its parentโs origin. For pixmaps, these coordinates are always zero. periodt ๐
๐ฆ DESCRIPTION ๐ฆ
so XGetWindowAttributes returns the current attributes for the specified window into an XWindowAttributes structure. it returns a nonzero status on success; otherwise, it returns a zero status โจ
XGetWindowAttributes can generate BadDrawable and BadWindow errors. noted, bestie ๐ซถ
XGetGeometry returns the root window and the current geometry of the drawable. the geometry of the drawable includes the x and y coordinates, width and height, border width, and depth โ all described in the argument list above, iykyk ๐ it is legal to pass this function a window whose class is InputOnly. it returns a nonzero status on success; otherwise, it returns a zero status. slay ๐
๐ง STRUCTURES ๐ง
the XWindowAttributes structure contains:
typedef struct {
int x, y; /* location of window */
int width, height; /* width and height of window */
int border_width; /* border width of window */
int depth; /* depth of window */
Visual *visual; /* the associated visual structure */
Window root; /* root of screen containing window */
int class; /* InputOutput, InputOnly*/
int bit_gravity; /* one of the bit gravity values */
int win_gravity; /* one of the window gravity values */
int backing_store; /* NotUseful, WhenMapped, Always */
unsigned long backing_planes; /* planes to be preserved if possible */
unsigned long backing_pixel; /* value to be used when restoring planes */
Bool save_under; /* boolean, should bits under be saved? */
Colormap colormap; /* color map to be associated with window */
Bool map_installed; /* boolean, is color map currently installed*/
int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
long all_event_masks; /* set of events all people have interest in*/
long your_event_mask; /* my event mask */
long do_not_propagate_mask; /* set of events that should not propagate */
Bool override_redirect; /* boolean value for override-redirect */
Screen *screen; /* back pointer to correct screen */
} XWindowAttributes;
the x and y members are set to the upper-left outer corner relative to the parent windowโs origin. the width and height members are set to the inside size of the window, not including the border. the border_width member is set to the windowโs border width in pixels. the depth member is set to the depth of the window (that is, bits per pixel for the object). the visual member is a pointer to the screenโs associated Visual structure. the root member is set to the root window of the screen containing the window. the class member is set to the windowโs class and can be either InputOutput or InputOnly ๐
the bit_gravity member is set to the windowโs bit gravity and can be one of the following:
ForgetGravityNorthWestGravityNorthGravityNorthEastGravityWestGravityCenterGravityEastGravitySouthWestGravitySouthGravitySouthEastGravityStaticGravity
the win_gravity member is set to the windowโs window gravity and can be one of the following:
UnmapGravityNorthWestGravityNorthGravityNorthEastGravityWestGravityCenterGravityEastGravitySouthWestGravitySouthGravitySouthEastGravityStaticGravity
for additional information on gravity, see section 3.3. okay gravity lore ๐
the backing_store member is set to indicate how the X server should maintain the contents of a window and can be WhenMapped, Always, or NotUseful. the backing_planes member is set to indicate (with bits set to 1) which bit planes of the window hold dynamic data that must be preserved in backing_stores and during save_unders. the backing_pixel member is set to indicate what values to use for planes not set in backing_planes ๐
the save_under member is set to True or False. the colormap member is set to the colormap for the specified window and can be a colormap ID or None. the map_installed member is set to indicate whether the colormap is currently installed and can be True or False. the map_state member is set to indicate the state of the window and can be IsUnmapped, IsUnviewable, or IsViewable. IsUnviewable is used if the window is mapped but some ancestor is unmapped. literally the family tree of window states ๐ญ
the all_event_masks member is set to the bitwise inclusive OR of all event masks selected on the window by all clients. the your_event_mask member is set to the bitwise inclusive OR of all event masks selected by the querying client. the do_not_propagate_mask member is set to the bitwise inclusive OR of the set of events that should not propagate. event mask math, bestie ๐งฎโจ
the override_redirect member is set to indicate whether this window overrides structure control facilities and can be True or False. window manager clients should ignore the window if this member is True. noted, window manager girlies ๐
the screen member is set to a screen pointer that gives you a back pointer to the correct screen. this makes it easier to obtain the screen information without having to loop over the root window fields to see which field matches. thank you for your service, back pointer ๐ซถ
๐ DIAGNOSTICS ๐
BadDrawableโ a value for aDrawableargument does not name a definedWindoworPixmap.BadWindowโ a value for aWindowargument does not name a definedWindow.
๐ SEE ALSO ๐
XQueryPointer(3)XQueryTree(3)Xlib - C Language X Interface
xoxo, your libX11 bestie ๐ โ this page is from X Version 11, libX11 1.8.14, and the page name is XGetWindowAttributes(3). no separate date line in the footer, just so you know bestie ๐โจ
๐ฆ 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