XDrawString(3)
π XDrawString β drawing text characters, the iconic way
Okay bestie, so this is the XDrawString(3) page from the XLIB FUNCTIONS manual, and it's literally about putting text on a drawable. Two functions, one vibe. Let's get into it β¨
πΈ NAME πΈ
XDrawString, XDrawString16 β draw text characters. That's it, that's the whole thing. Text. On your drawable. Slay. π
β¨ SYNTAX β¨
int XDrawString(Display *display, Drawable d, GC gc, int x, int y,
_Xconst char *string, int length);
int XDrawString16(Display *display, Drawable d, GC gc, int x, int y,
_Xconst XChar2b *string, int length);
Two signatures, same energy. One takes a char *, the other takes an XChar2b *. Both return int. Both are your new besties π«Ά
π ARGUMENTS π
dβ Specifies the drawable. Like, the thing you're drawing on. The canvas. The main character.displayβ Specifies the connection to the X server. Your little link to the mothership πgcβ Specifies the GC. The Graphics Context. It's giving "settings bag" and honestly it kinda is.lengthβ Specifies the number of characters in thestringargument. Count 'em. Fr fr, count them.stringβ Specifies the character string. The actual text. The star of the show βx,yβ Specify the x and y coordinates, which are relative to the origin of the specified drawable and define the origin of the first character. So like, that's where your first letter starts. The spawn point, if you will.
π¦ DESCRIPTION π¦
Okay so here's the tea β β each character image, as defined by the font in the GC, is treated as an additional mask for a fill operation on the drawable. Think of it as: the letter is a stencil, and you're filling through it.
The drawable is modified only where the font character has a bit set to 1. Nowhere else. No sneaky stray pixels. Respect the mask, periodt π
For fonts defined with 2-byte matrix indexing and used with XDrawString16, each byte is used as a byte2 with a byte1 of zero. Like, that's just how it goes for those fonts, ngl.
Both functions use these GC components:
functionplane-maskfill-stylefontsubwindow-modeclip-x-originclip-y-originclip-mask
They also use these GC mode-dependent components:
foregroundbackgroundtilestippletile-stipple-x-origintile-stipple-y-origin
Heads up bestie βXDrawStringandXDrawString16can generateBadDrawable,BadGC, andBadMatcherrors. So like, vibe check your args, okay? π
π DIAGNOSTICS π
BadDrawableβ A value for aDrawableargument does not name a definedWindoworPixmap. So whatever you passed in? It's not a real thing. Ghosted. π»BadGCβ A value for aGContextargument does not name a definedGContext. Same situation, different argument. The GC said "not me" πBadMatchβ AnInputOnlywindow is used as aDrawable. Bestie no,InputOnlywindows are for input, not for drawing. That's literally their whole thing.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. Like, everything looks right but the request still said no. Type and range: valid. Vibes: misaligned. π
π§ SEE ALSO π§
XDrawImageString(3)XDrawText(3)XLoadFont(3)Xlib - C Language X Interface
π Okay that's the whole page! Go forth and draw your little strings, bestie. If you need me I'll be over here stanning plane-masks.
Later, icon π β this was the XDrawString(3) page, X Version 11, libX11 1.8.14. Bookmark it, iykyk ππβ¨
π¦ 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