XListFonts(3)
πΈ XListFonts(3) β the font-listing glow-up you didn't know you needed π
okay bestie, gather round, because we're talking about XListFonts, XFreeFontNames, XListFontsWithInfo, and XFreeFontInfo β the iconic little quartet from the Xlib C Language X Interface (X Version 11, libX11 1.8.14) that lets you obtain or free font names and font info. it's giving "backend bestie energy," and honestly? we're obsessed. π«Άβ¨
β¨ SYNTAX β¨
bestie, here's the exact shape of each function β copy these character for character, no cap:
char **XListFonts(Display *display, _Xconst char *pattern, int maxnames,
int *actual_count_return);
int XFreeFontNames(char *list[]);
char **XListFontsWithInfo(Display *display, _Xconst char *pattern, int
maxnames, int *count_return, XFontStruct **info_return);
int XFreeFontInfo(char **names, XFontStruct *free_info, int
actual_count);
π ARGUMENTS π
every single parameter, served fresh, no skips:
actual_countβ Specifies the actual number of font names.actual_count_returnβ Returns the actual number of font names.count_returnβ Returns the actual number of matched font names.displayβ Specifies the connection to the X server.info_returnβ Returns the font information.free_infoβ Specifies the font information.listβ Specifies the array of strings you want to free.maxnamesβ Specifies the maximum number of names to be returned.namesβ Specifies the list of font names.patternβ Specifies the null-terminated pattern string that can contain wildcard characters.
π DESCRIPTION π
okay so here's the tea on each one, and yes we're doing all of them π
π XListFonts
The XListFonts function returns an array of available font names (as controlled by the font search path; see XSetFontPath) that match the string you passed to the pattern argument. The pattern string can contain any characters, but each asterisk (*) is a wildcard for any number of characters, and each question mark (?) is a wildcard for a single character. If the pattern string is not in the Host Portable Character Encoding, the result is implementation-dependent. Use of uppercase or lowercase does not matter. Each returned string is null-terminated. If the data returned by the server is in the Latin Portable Character Encoding, then the returned strings are in the Host Portable Character Encoding. Otherwise, the result is implementation-dependent. If there are no matching font names, XListFonts returns NULL. The client should call XFreeFontNames when finished with the result to free the memory.
lowkey the wildcard thing is so cute β*= "any number of characters, idc" and?= "exactly one character bestie". also: uppercase/lowercase? doesn't matter. slay. π
πΈ XFreeFontNames
The XFreeFontNames function frees the array and strings returned by XListFonts or XListFontsWithInfo. literally the cleanup bestie β don't leave your memory hanging, periodt.
π¦ XListFontsWithInfo
The XListFontsWithInfo function returns a list of font names that match the specified pattern and their associated font information. The list of names is limited to size specified by maxnames. The information returned for each font is identical to what XLoadQueryFont would return except that the per-character metrics are not returned. The pattern string can contain any characters, but each asterisk (*) is a wildcard for any number of characters, and each question mark (?) is a wildcard for a single character. If the pattern string is not in the Host Portable Character Encoding, the result is implementation-dependent. Use of uppercase or lowercase does not matter. Each returned string is null-terminated. If the data returned by the server is in the Latin Portable Character Encoding, then the returned strings are in the Host Portable Character Encoding. Otherwise, the result is implementation-dependent. If there are no matching font names, XListFontsWithInfo returns NULL.
"except that the per-character metrics are not returned" β ok so it's the XLoadQueryFont experience but without the per-character metrics. we love a stripped-down icon. π
freeing strategy, because yes there's a whole decision tree:
- To free only the allocated name array, the client should call
XFreeFontNames. - To free both the name array and the font information array or to free just the font information array, the client should call
XFreeFontInfo.
π§ XFreeFontInfo
The XFreeFontInfo function frees a font structure or an array of font structures and optionally an array of font names.
- If
NULLis passed fornames, no font names are freed. - If a font structure for an open font (returned by
XLoadQueryFont) is passed, the structure is freed, but the font is not closed; useXUnloadFontto close the font.
heads up bestie β freeing the structure does NOT close the font. you need XUnloadFont for that. don't let anyone tell you otherwise. π
β οΈ IMPORTANT VIBE CHECK β οΈ Note thatXListFontsWithInfois not thread-safe. If other threads make X requests on the sameDisplay, then this function's behavior is undefined. fr fr, do not play with this. π
π SEE ALSO π
the whole friend group:
XLoadFont(3)XSetFontPath(3)Xlib - C Language X Interface
and that's the whole page, bestie! π this glamorous little manual brought to you by X Version 11, libX11 1.8.14, dated however long ago, with all the copyright and license energy baked right in β now go list those fonts and free that memory responsibly. mwah! πβ¨π¦ππ·
π¦ 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