Beispiel #1
0
char *xcb_util_get_property(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t atom,
        xcb_atom_t type, size_t size) {
    xcb_get_property_cookie_t cookie;
    xcb_get_property_reply_t *reply;
    xcb_generic_error_t *err;
    int reply_length;
    char *content;

    cookie = xcb_get_property(conn, 0, window, atom, type, 0, size);
    reply = xcb_get_property_reply(conn, cookie, &err);
    if (err != NULL) {
        FREE(err);
        return NULL;
    }

    if (reply == NULL || (reply_length = xcb_get_property_value_length(reply)) == 0) {
        FREE(reply);
        return NULL;
    }

    if (reply->bytes_after > 0) {
        size_t adjusted_size = size + ceil(reply->bytes_after / 4.0);
        FREE(reply);
        return xcb_util_get_property(conn, window, atom, type, adjusted_size);
    }

    if (asprintf(&content, "%.*s", reply_length, (char *)xcb_get_property_value(reply)) < 0) {
        FREE(reply);
        return NULL;
    }

    FREE(reply);
    return content;
}
Beispiel #2
0
/*
 * Loads the RESOURCE_MANAGER property and creates a database with its
 * contents. If the database could not be created, this function will return
 * NULL.
 *
 * @param conn A working XCB connection.
 * @param screen The xcb_screen_t* screen to use.
 * @returns The database described by the RESOURCE_MANAGER property.
 *
 * @ingroup xcb_xrm_database_t
 */
xcb_xrm_database_t *xcb_xrm_database_from_resource_manager(xcb_connection_t *conn, xcb_screen_t *screen) {
    xcb_xrm_database_t *database;

    char *resources = xcb_util_get_property(conn, screen->root, XCB_ATOM_RESOURCE_MANAGER,
            XCB_ATOM_STRING, 16 * 1024);
    if (resources == NULL) {
        return NULL;
    }

    /* Parse the resource string. */
    database = xcb_xrm_database_from_string(resources);
    FREE(resources);
    return database;
}