XCreateWindow(3)
π XCreateWindow(3) π
ok so this is a page from XLIB FUNCTIONS and bestie, it's literally the origin story of every window you've ever seen on an X display. buckle up π
β¨ NAME β¨
XCreateWindow, XCreateSimpleWindow, XSetWindowAttributes β the trio that creates windows and hands you the window attributes structure. main character energy fr fr π
πΈ SYNTAX πΈ
Window XCreateWindow(Display *display, Window parent, int x, int y,
unsigned int width, unsigned int height, unsigned int
border_width, int depth, unsigned int class, Visual *visual,
unsigned long valuemask, XSetWindowAttributes *attributes);
Window XCreateSimpleWindow(Display *display, Window parent, int x, int
y, unsigned int width, unsigned int height, unsigned int
border_width, unsigned long border, unsigned long background);
like, XCreateWindow is the full-control queen and XCreateSimpleWindow is her low-effort little sister who still slays π
π¦ ARGUMENTS π¦
attributesβ this is the structure the values get pulled from (the ones your value mask says are set, anyway). the value mask needs the right bits turned on so it knows which attributes actually got set in the struct. no cap, the mask is the whole vibe check here.backgroundβ the background pixel value of the window. that's it, that's the tweet.borderβ the border pixel value of the window.border_widthβ how wide the created window's border is, in pixels. it's giving "frame thickness" β¨classβ the created window's class. you can passInputOutput,InputOnly, orCopyFromParent. and a class ofCopyFromParentmeans, yup, the class is taken from the parent. inheritance icon πdepthβ the window's depth. a depth ofCopyFromParentmeans the depth comes from the parent. same energy, same nepo-baby behavior π«Άdisplayβ the connection to the X server. your link to the mothership.parentβ the parent window. every window needs a mother, periodt.valuemaskβ which window attributes are defined in theattributesargument. this mask is the bitwise inclusive OR of the valid attribute mask bits. and listen: ifvaluemaskis zero, the attributes are ignored and not referenced. like, she's not even looking at them πvisualβ the visual type. a visual ofCopyFromParentmeans the visual type is taken from the parent. again with the inheritance, obsessed πwidth,heightβ the width and height, which are the created window's inside dimensions and do not include the created window's borders. so don't come crying when the border adds extra pixels, that's on you bestie.x,yβ the x and y coordinates, which are the top-left outside corner of the window's borders, and they're relative to the inside of the parent window's borders. read that twice, it matters π
π₯ DESCRIPTION π₯
So the XCreateWindow function creates an unmapped subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. and the created window? placed on top in the stacking order with respect to siblings. she's literally above the drama π
The coordinate system has the X axis horizontal and the Y axis vertical, with the origin [0, 0] at the upper-left corner. coordinates are integral, in terms of pixels, and coincide with pixel centers. every window and pixmap has its own coordinate system. for a window, the origin is inside the border at the inside, upper-left corner. cute little self-contained universe π§
Now the rules, and ngl these are the important ones:
- The
border_widthfor anInputOnlywindow must be zero, or aBadMatcherror results. - For class
InputOutput, the visual type and depth must be a combination supported for the screen, or aBadMatcherror results. - The depth need not be the same as the parent, but the parent must not be a window of class
InputOnly, or aBadMatcherror results. - For an
InputOnlywindow, the depth must be zero, and the visual must be one supported by the screen. if either condition is not met, aBadMatcherror results. - The parent window, however, may have any depth and class. slay, flexible queen π
- If you specify any invalid window attribute for a window, a
BadMatcherror results.
The created window is not yet displayed (mapped) on the user's display. to display the window, call XMapWindow. the new window initially uses the same cursor as its parent. a new cursor can be defined for the new window by calling XDefineCursor. and the window will not be visible on the screen unless it and all of its ancestors are mapped and it is not obscured by any of its ancestors. so like, if grandma's not showing up, nobody's showing up π
XCreateWindow can generate BadAlloc BadColor, BadCursor, BadMatch, BadPixmap, BadValue, and BadWindow errors.
Now the XCreateSimpleWindow function creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. created window goes on top in the stacking order with respect to siblings. any part of the window that extends outside its parent window is clipped βοΈ
The border_width for an InputOnly window must be zero, or a BadMatch error results. XCreateSimpleWindow inherits its depth, class, and visual from its parent. all other window attributes, except background and border, have their default values. lowkey the default settings enjoyer π
XCreateSimpleWindow can generate BadAlloc, BadMatch, BadValue, and BadWindow errors.
π STRUCTURES π
The XSetWindowAttributes structure contains:
/* Window attribute value mask bits */
#define CWBackPixmap (1L<<0)
#define CWBackPixel (1L<<1)
#define CWBorderPixmap (1L<<2)
#define CWBorderPixel (1L<<3)
#define CWBitGravity (1L<<4)
#define CWWinGravity (1L<<5)
#define CWBackingStore (1L<<6)
#define CWBackingPlanes (1L<<7)
#define CWBackingPixel (1L<<8)
#define CWOverrideRedirect (1L<<9)
#define CWSaveUnder (1L<<10)
#define CWEventMask (1L<<11)
#define CWDontPropagate (1L<<12)
#define CWColormap (1L<<13)
#define CWCursor (1L<<14)
/* Values */
typedef struct {
Pixmap background_pixmap; /* background, None, or ParentRelative */
unsigned long background_pixel; /* background pixel */
Pixmap border_pixmap; /* border of the window or CopyFromParent */
unsigned long border_pixel; /* border pixel value */
int bit_gravity; /* one of 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 use in restoring planes */
Bool save_under; /* should bits under be saved? (popups) */
long event_mask; /* set of events that should be saved */
long do_not_propagate_mask; /* set of events that should not propagate */
Bool override_redirect; /* boolean value for override_redirect */
Colormap colormap; /* color map to be associated with window */
Cursor cursor; /* cursor to be displayed (or None) */
} XSetWindowAttributes;
for a detailed explanation of the members of this structure, see Xlib - C Language X Interface. it's giving required reading π
π DIAGNOSTICS π
BadAllocβ the server failed to allocate the requested resource or server memory. she tried her best πBadColorβ a value for aColormapargument does not name a definedColormap.BadCursorβ a value for aCursorargument does not name a definedCursor.BadMatchβ the values do not exist for anInputOnlywindow.BadMatchβ some argument or pair of arguments has the correct type and range but fails to match in some other way required by the request. (yes bestie,BadMatchshows up twice, and both times it's a different flavor of "nope" π)BadPixmapβ a value for aPixmapargument does not name a definedPixmap.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 aWindowargument does not name a definedWindow. she doesn't know her π
π SEE ALSO π
XChangeWindowAttributes(3), XConfigureWindow(3), XDefineCursor(3), XDestroyWindow(3), XMapWindow(3), XRaiseWindow(3), XUnmapWindow(3), Xlib - C Language X Interface
and that's the whole page bestie π«Ά this one's from X Version 11, libX11 1.8.14, page XCreateWindow(3) β go forth and create windows, you absolute icon πβ¨
π¦ 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