コード例 #1
0
ファイル: xcb.c プロジェクト: freexploit/i3wm
/*
 * Returns the ID of the font matching the given pattern and stores the height
 * of the font (in pixels) in *font_height. die()s if no font matches.
 *
 */
int get_font_id(xcb_connection_t *conn, char *pattern, int *font_height) {
        xcb_void_cookie_t font_cookie;
        xcb_list_fonts_with_info_cookie_t info_cookie;

        /* Send all our requests first */
        int result;
        result = xcb_generate_id(conn);
        font_cookie = xcb_open_font_checked(conn, result, strlen(pattern), pattern);
        info_cookie = xcb_list_fonts_with_info(conn, 1, strlen(pattern), pattern);

        xcb_generic_error_t *error = xcb_request_check(conn, font_cookie);
        if (error != NULL) {
                fprintf(stderr, "ERROR: Could not open font: %d\n", error->error_code);
                exit(1);
        }

        /* Get information (height/name) for this font */
        xcb_list_fonts_with_info_reply_t *reply = xcb_list_fonts_with_info_reply(conn, info_cookie, NULL);
        if (reply == NULL)
                errx(1, "Could not load font \"%s\"\n", pattern);

        *font_height = reply->font_ascent + reply->font_descent;

        return result;
}
コード例 #2
0
ファイル: nilwm.c プロジェクト: nqv/nilwm
static
int init_font() {
    xcb_void_cookie_t cookie;
    xcb_generic_error_t *err;
    xcb_list_fonts_with_info_cookie_t info_cookie;
    xcb_list_fonts_with_info_reply_t *info;

    /* open font */
    nil_.font.id = xcb_generate_id(nil_.con);
    cookie = xcb_open_font_checked(nil_.con, nil_.font.id,
        strlen(cfg_.font_name), cfg_.font_name);
    err = xcb_request_check(nil_.con, cookie);
    if (err) {
        NIL_ERR("open font: %d", err->error_code);
        return -1;
    }
    info_cookie = xcb_list_fonts_with_info(nil_.con, 1,
        strlen(cfg_.font_name), cfg_.font_name);
    info = xcb_list_fonts_with_info_reply(nil_.con, info_cookie, 0);
    if (!info) {
        NIL_ERR("load font: %s", cfg_.font_name);
        return -1;
    }
    NIL_LOG("font ascent=%d, descent=%d", info->font_ascent, info->font_descent);
    nil_.font.ascent = info->font_ascent;
    nil_.font.descent = info->font_descent;
    free(info);
    return 0;
}