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 the XWindowAttributes structure ๐Ÿงš
  • 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:

  • ForgetGravity
  • NorthWestGravity
  • NorthGravity
  • NorthEastGravity
  • WestGravity
  • CenterGravity
  • EastGravity
  • SouthWestGravity
  • SouthGravity
  • SouthEastGravity
  • StaticGravity

the win_gravity member is set to the windowโ€™s window gravity and can be one of the following:

  • UnmapGravity
  • NorthWestGravity
  • NorthGravity
  • NorthEastGravity
  • WestGravity
  • CenterGravity
  • EastGravity
  • SouthWestGravity
  • SouthGravity
  • SouthEastGravity
  • StaticGravity

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 a Drawable argument does not name a defined Window or Pixmap.
  • BadWindow โ€” a value for a Window argument does not name a defined Window.

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


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