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