xcb_get_geometry(3)

πŸ“¦
version 1.17.0 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ xcb_get_geometry ✨

okay so bestie, we're in the XCB Requests chapter of the libxcb manual, and today's main character is xcb_get_geometry β€” aka the glow-up that tells you where a thing actually is on screen. 🫢


🌸 NAME 🌸

xcb_get_geometry β€” Get current window geometry πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <xcb/xproto.h>

πŸ¦‹ Request function

xcb_get_geometry_cookie_t xcb_get_geometry(xcb_connection_t *conn,
       xcb_drawable_t drawable);

πŸ¦‹ Reply datastructure

typedef struct xcb_get_geometry_reply_t {
    uint8_t      response_type;
    uint8_t      depth;
    uint16_t     sequence;
    uint32_t     length;
    xcb_window_t root;
    int16_t      x;
    int16_t      y;
    uint16_t     width;
    uint16_t     height;
    uint16_t     border_width;
    uint8_t      pad0[2];
} xcb_get_geometry_reply_t;

πŸ¦‹ Reply function

xcb_get_geometry_reply_t *xcb_get_geometry_reply(xcb_connection_t *conn,
       xcb_get_geometry_cookie_t cookie, xcb_generic_error_t **e);

πŸ’– REQUEST ARGUMENTS πŸ’–

  • conn β€” your XCB connection to X11, the lil telephone line to the server πŸ“ž
  • drawable β€” the drawable (Window or Pixmap) whose geometry we're about to go get. no cap, both count ✨

πŸ‘‘ REPLY FIELDS πŸ‘‘

  • response_type β€” the type of this reply, which in this case is XCB_GET_GEOMETRY. this field is also chillin' in the xcb_generic_reply_t, and you can use it to tell replies apart from each other. it's giving name tag at a party πŸŽ€
  • sequence β€” the sequence number of the last request processed by the X11 server. the receipts, basically 🧾
  • length β€” the length of the reply, in words (and a word here is 4 bytes, periodt)
  • depth β€” the depth of the drawable (bits per pixel for the object)
  • root β€” root window of the screen containing drawable. the ultimate ancestor, the mother of all windows πŸ’œ
  • x β€” the X coordinate of drawable. if drawable is a window, this coordinate specifies the upper-left outer corner relative to its parent's origin. if drawable is a pixmap, the X coordinate is always 0. literally always. zero. 😌
  • y β€” the Y coordinate of drawable. same deal: if drawable is a window, this coordinate specifies the upper-left outer corner relative to its parent's origin. if drawable is a pixmap, the Y coordinate is always 0. fr fr
  • width β€” the width of drawable
  • height β€” the height of drawable
  • border_width β€” the border width (in pixels). the little fit around the edges πŸ’…

🌈 DESCRIPTION 🌈

Gets the current geometry of the specified drawable (either Window or Pixmap). that's it, that's the vibe check. obsessed. ✨


πŸ’€ RETURN VALUE πŸ’€

Returns an xcb_get_geometry_cookie_t. Errors have to be handled when calling the reply function xcb_get_geometry_reply.

If you want to handle errors in the event loop instead, use xcb_get_geometry_unchecked. See xcb-requests(3) for details.

ok so real talk: the cookie is not the answer, it's the promise of an answer. go get your reply, bestie πŸ“

πŸ™ˆ ERRORS πŸ™ˆ

  • xcb_drawable_error_t β€” TODO: reasons?
  • xcb_window_error_t β€” TODO: reasons?
not me leaving the reasons as a mystery 😭 the original page literally says TODO: reasons? so we're keeping that energy exactly as-is. no inventing, no guessing, iykyk.

⭐ EXAMPLE ⭐

/*
 * Displays the x and y position of the given window.
 *
 */
void my_example(xcb_connection_t *c, xcb_window_t window) {
    xcb_get_geometry_cookie_t cookie;
    xcb_get_geometry_reply_t *reply;

    cookie = xcb_get_geometry(c, window);
    /* ... do other work here if possible ... */
    if ((reply = xcb_get_geometry_reply(c, cookie, NULL))) {
        printf("This window is at %d, %d\n", reply->x, reply->y);
    }
    free(reply);
}

look at that. send the request, go do your little side quests while the server thinks, then grab the reply and print the coordinates. main character energy, truly πŸ”₯


🧚 SEE ALSO 🧚


πŸ’œ AUTHOR πŸ’œ

Generated from xproto.xml. Contact xcb@lists.freedesktop.org for corrections and improvements.


and that's the whole page bestie!! this one's part of X Version 11, shipped with libxcb 1.17.0, and it goes by xcb_get_geometry(3) πŸŽ€πŸ¦‹βœ¨