commit 86ec92836b843680ddf12238b370436e883d437a from: Onana Onana Xavier Manuel date: Mon Jul 6 23:42:50 2026 UTC Added text color and small fix in xcb.c for connection commit - ab785159a83ddb3ca6309027f7e63139a707e5cf commit + 86ec92836b843680ddf12238b370436e883d437a blob - 5fc883410e7985f9df5ed098ac4eccf2d393f75e blob + bb3058c078154d7eb7f571756a7c0e392bd9c9ba --- aui.h +++ aui.h @@ -64,6 +64,7 @@ struct aui_window_config { }; struct aui_button_config { + struct aui_color fg; const char *text; /* Not allocated by libaui */ void (*command) (struct aui_button *, void *args); void *args; blob - 4897ca17c19fc08a18081dbf3320614ca265d819 blob + d1b87b2834c3c894c2546c1d69356c0ecd5abb1f --- button.c +++ button.c @@ -32,6 +32,7 @@ struct aui_color color[] = { static struct aui_button_config default_config = { .text = NULL, + .fg = { 0xff, 0, 0, 0xff } }; struct aui_button* @@ -56,6 +57,7 @@ aui_button_new(struct aui_widget *parent, struct aui_b driver->ops->set_rectangle_color(widget->window, widget->primitives.list[0], &color[0]); driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); driver->ops->set_text(widget->primitives.list[2], button->config.text, 0, 0); + driver->ops->set_text_color(widget->primitives.list[2], &button->config.fg); return button; } blob - 140a08107bf3306e7fe8fb7981fc063b88f53a1d blob + 0ee22df660d00d2889e0e6f995024c9d0a56132c --- driver.h +++ driver.h @@ -28,6 +28,7 @@ struct dri_ops { struct primitive *(*create_text) (void); void (*set_text) (struct primitive *, const char *, int16_t, int16_t); + void (*set_text_color) (struct primitive *, struct aui_color *); void (*render_text) (struct aui_window *, struct primitive *); struct aui_geometry (*get_text_geometry) (struct primitive *); blob - 68b44b9e7de9f46ca42c126550437393240b084f blob + 5d6c1758815a2dbf8c816da02ec80bb0a9566460 --- label.c +++ label.c @@ -25,6 +25,7 @@ static struct widget_ops label_ops = { struct aui_label_config default_config = { .text = "Hello AUI", + .fg = { 0, 0, 0, 255 }, }; struct aui_label* @@ -43,6 +44,7 @@ aui_label_new(struct aui_widget *parent, struct aui_la widget->primitives.list[0] = driver->ops->create_text(); driver->ops->set_text(widget->primitives.list[0], label->config.text, 0, 0); + driver->ops->set_text_color(widget->primitives.list[0], &config->fg); return label; } blob - 8bd389d63c432261823635c49c0457065c63cef9 blob + c9fef909ed137c86b40d0e076124e09cbc3fce13 --- xcb.c +++ xcb.c @@ -24,7 +24,6 @@ struct aui_dri_xcb { xcb_intern_atom_reply_t *wm_delete_window; xcb_render_glyphset_t glyphset; - xcb_render_picture_t glyphpic; struct glyph *glyphs; int font_height; xcb_render_pictformat_t fmt_normal; @@ -59,6 +58,7 @@ static void aui_dri_set_rectangle_geometry(struct aui_ static struct primitive *aui_dri_create_text(void); static void aui_dri_set_text(struct primitive *, const char *, int16_t, int16_t); +static void aui_dri_set_text_color(struct primitive*, struct aui_color*); static void aui_dri_render_text(struct aui_window *, struct primitive *); static struct aui_geometry aui_dri_get_text_geometry(struct primitive *); @@ -82,6 +82,7 @@ static struct dri_ops aui_dri_ops = { aui_dri_create_text, aui_dri_set_text, + aui_dri_set_text_color, aui_dri_render_text, aui_dri_get_text_geometry }; @@ -95,6 +96,8 @@ struct rectangle { struct text { struct primitive base; const char *data; /* Not allocated, pointer to string literal */ + xcb_render_color_t xcolor; + xcb_render_picture_t xpict; int16_t x, y; }; @@ -155,10 +158,6 @@ xcb_driver_open(void) dri_xcb->font_height = g->y_offset; } - dri_xcb->glyphpic = xcb_generate_id(dri_xcb->conn); - xcb_render_color_t color = { 0xffff/2, 0xffff/2, 0, 0xffff }; - xcb_render_create_solid_fill(dri_xcb->conn, dri_xcb->glyphpic, color); - return 0; } @@ -457,7 +456,12 @@ void aui_dri_set_rectangle_geometry(struct aui_window static struct primitive* aui_dri_create_text() { + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; struct text *t = calloc(1, sizeof(struct text)); + + t->xpict = xcb_generate_id(dri_xcb->conn); + t->xcolor = (xcb_render_color_t) { 0xffff/2, 0xffff/2, 0, 0xffff }; + xcb_render_create_solid_fill(dri_xcb->conn, t->xpict, t->xcolor); return &(t)->base; } @@ -471,6 +475,24 @@ aui_dri_set_text(struct primitive *p, const char *data t->y = y; } +static void +aui_dri_set_text_color(struct primitive *p, struct aui_color *c) +{ + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct text *t = (struct text *)p; + + t->xcolor = (xcb_render_color_t) { + c->red * 0xffff / 0xff, + c->green * 0xffff / 0xff, + c->blue * 0xffff / 0xff, + c->alpha * 0xffff / 0xff + }; + + xcb_render_free_picture(dri_xcb->conn, t->xpict); + t->xpict = xcb_generate_id(dri_xcb->conn); + xcb_render_create_solid_fill(dri_xcb->conn, t->xpict, t->xcolor); +} + /* * This renders text without the use of xcb_render utils. It utilises the * xcb_render_composite_glyphs_8 function which expects an 8 bytes header @@ -517,7 +539,7 @@ aui_dri_render_text(struct aui_window *aw, struct prim xcb_render_composite_glyphs_8( dri_xcb->conn, XCB_RENDER_PICT_OP_OVER, - dri_xcb->glyphpic, + t->xpict, aw_xcb->src_pict, 0, dri_xcb->glyphset, @@ -564,7 +586,7 @@ config_xcb(struct aui_dri_xcb *axcb) axcb->conn = xcb_connect(NULL, NULL); - if (axcb->conn == NULL) + if (xcb_connection_has_error(axcb->conn)) return -1; axcb->screen = xcb_setup_roots_iterator(xcb_get_setup(axcb->conn)).data;