1ecce36beSmrg/*
2ecce36beSmrg * Copyright © 2008 Ian Osgood  <iano@quirkster.com>
3ecce36beSmrg * Copyright © 2008 Jamey Sharp <jamey@minilop.net>
4ecce36beSmrg * Copyright © 2008 Josh Triplett <josh@freedesktop.org>
5ecce36beSmrg * Copyright © 2008 Julien Danjou <julien@danjou.info>
6ecce36beSmrg *
7ecce36beSmrg * Permission is hereby granted, free of charge, to any person
8ecce36beSmrg * obtaining a copy of this software and associated documentation
9ecce36beSmrg * files (the "Software"), to deal in the Software without
10ecce36beSmrg * restriction, including without limitation the rights to use, copy,
11ecce36beSmrg * modify, merge, publish, distribute, sublicense, and/or sell copies
12ecce36beSmrg * of the Software, and to permit persons to whom the Software is
13ecce36beSmrg * furnished to do so, subject to the following conditions:
14ecce36beSmrg *
15ecce36beSmrg * The above copyright notice and this permission notice shall be
16ecce36beSmrg * included in all copies or substantial portions of the Software.
17ecce36beSmrg *
18ecce36beSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19ecce36beSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20ecce36beSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21ecce36beSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
22ecce36beSmrg * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23ecce36beSmrg * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24ecce36beSmrg * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25ecce36beSmrg *
26ecce36beSmrg * Except as contained in this notice, the names of the authors or
27ecce36beSmrg * their institutions shall not be used in advertising or otherwise to
28ecce36beSmrg * promote the sale, use or other dealings in this Software without
29ecce36beSmrg * prior written authorization from the authors.
30ecce36beSmrg */
31ecce36beSmrg
32ecce36beSmrg#include "xcb_reply.h"
33ecce36beSmrg
34ecce36beSmrg#include <string.h>
35ecce36beSmrg#include <stdio.h>
36ecce36beSmrg#include <stdlib.h>
37ecce36beSmrg#include <unistd.h>
38ecce36beSmrg
39ecce36beSmrgpthread_cond_t cond = PTHREAD_COND_INITIALIZER;
40ecce36beSmrgpthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
41ecce36beSmrg
42ecce36beSmrgvoid fontinfo_handler(void *data, xcb_connection_t *c, xcb_generic_reply_t *rg, xcb_generic_error_t *eg)
43ecce36beSmrg{
44ecce36beSmrg	xcb_list_fonts_with_info_reply_t *rep = (xcb_list_fonts_with_info_reply_t *) rg;
45ecce36beSmrg	if(rep)
46ecce36beSmrg	{
47ecce36beSmrg		int len = xcb_list_fonts_with_info_name_length(rep);
48ecce36beSmrg		if(len)
49ecce36beSmrg			printf("(+%u) Font \"%.*s\"\n",
50ecce36beSmrg					(unsigned int) rep->replies_hint,
51ecce36beSmrg					len, xcb_list_fonts_with_info_name(rep));
52ecce36beSmrg		else
53ecce36beSmrg		{
54ecce36beSmrg			pthread_mutex_lock(&lock);
55ecce36beSmrg			pthread_cond_broadcast(&cond);
56ecce36beSmrg			pthread_mutex_unlock(&lock);
57ecce36beSmrg			printf("End of font list.\n");
58ecce36beSmrg		}
59ecce36beSmrg	}
60ecce36beSmrg	if(eg)
61ecce36beSmrg		printf("Error from ListFontsWithInfo: %d\n", eg->error_code);
62ecce36beSmrg}
63ecce36beSmrg
64ecce36beSmrgint main(int argc, char **argv)
65ecce36beSmrg{
66ecce36beSmrg	int count = 10;
67ecce36beSmrg	char *pattern = "*";
68ecce36beSmrg	xcb_connection_t *c = xcb_connect(NULL, NULL);
69ecce36beSmrg	xcb_reply_handlers_t h;
70ecce36beSmrg        xcb_reply_handlers_init(c, &h);
71ecce36beSmrg
72ecce36beSmrg	if(argc > 1)
73ecce36beSmrg		count = atoi(argv[1]);
74ecce36beSmrg	if(argc > 2)
75ecce36beSmrg		pattern = argv[2];
76ecce36beSmrg
77ecce36beSmrg	xcb_reply_add_handler(&h, xcb_list_fonts_with_info(c, count, strlen(pattern), pattern).sequence, fontinfo_handler, 0);
78ecce36beSmrg	pthread_mutex_lock(&lock);
79ecce36beSmrg	xcb_reply_start_thread(&h);
80ecce36beSmrg	pthread_cond_wait(&cond, &lock);
81ecce36beSmrg	xcb_reply_stop_thread(&h);
82ecce36beSmrg	pthread_mutex_unlock(&lock);
83ecce36beSmrg
84ecce36beSmrg	xcb_disconnect(c);
85ecce36beSmrg	exit(0);
86ecce36beSmrg}
87