Skip to content

Instantly share code, notes, and snippets.

@iosdevzone
Last active November 18, 2020 06:56
Show Gist options
  • Save iosdevzone/d3268ee96b33678a160dd29ed10f2817 to your computer and use it in GitHub Desktop.
Save iosdevzone/d3268ee96b33678a160dd29ed10f2817 to your computer and use it in GitHub Desktop.
Quick and dirty `xcb_list_fonts` demo
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <xcb/xcb.h>
static void list_fonts(xcb_connection_t *c)
{
// On my mac there are 10,000+ fonts!
uint16_t max_names = 20000;
const char *pattern = "*";
uint16_t pattern_length = strlen(pattern);
xcb_list_fonts_cookie_t fonts_cookie = xcb_list_fonts(c, max_names, pattern_length, pattern);
xcb_generic_error_t *error = NULL;
xcb_list_fonts_reply_t *fonts_reply = xcb_list_fonts_reply(c, fonts_cookie, &error);
// Should error check here.
int nfonts = xcb_list_fonts_names_length(fonts_reply);
printf("Got %d fonts\n", nfonts);
for (xcb_str_iterator_t names_iterator = xcb_list_fonts_names_iterator(fonts_reply);
names_iterator.rem != 0; xcb_str_next(&names_iterator))
{
// WARNING: Not null-terminated!
const char *name = xcb_str_name(names_iterator.data);
int name_length = xcb_str_name_length(names_iterator.data);
printf("%.*s\n", name_length, name);
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment