commit 86de45269288906cd51d0b8d6d87bd0dca48e65c from: Onana Onana Xavier Manuel date: Wed Jun 17 08:45:14 2026 UTC Indentation changed to tabs commit - 1b220a1d8645e9b28a0bdb5026296eafd2eb4458 commit + 86de45269288906cd51d0b8d6d87bd0dca48e65c blob - 31b0fd16a57399bf1bdd828c8d96964bbfd23d13 blob + 8e3ec3a29101299f9cf370fa6520b90f76b78e8a --- aui.h +++ aui.h @@ -4,69 +4,70 @@ #define AUI_WIDGET(widget) ((struct aui_widget *) widget) struct aui_color { - unsigned char red; - unsigned char green; - unsigned char blue; - unsigned char alpha; + unsigned char red; + unsigned char green; + unsigned char blue; + unsigned char alpha; }; struct aui_placepar { - int x, y; - float relx; - float rely; - unsigned int width; - unsigned int height; - float relwidth; - float relheight; -#define AUI_ANCHOR_NW 0 -#define AUI_ANCHOR_N 1 -#define AUI_ANCHOR_E 2 -#define AUI_ANCHOR_SE 3 -#define AUI_ANCHOR_S 4 -#define AUI_ANCHOR_SW 5 -#define AUI_ANCHOR_W 6 -#define AUI_ANCHOR_NE 7 + int x, y; + float relx; + float rely; + unsigned int width; + unsigned int height; + float relwidth; + float relheight; +#define AUI_ANCHOR_NW 0 +#define AUI_ANCHOR_N 1 +#define AUI_ANCHOR_E 2 +#define AUI_ANCHOR_SE 3 +#define AUI_ANCHOR_S 4 +#define AUI_ANCHOR_SW 5 +#define AUI_ANCHOR_W 6 +#define AUI_ANCHOR_NE 7 #define AUI_ANCHOR_CENTER 8 - unsigned char anchor; + unsigned char anchor; }; struct aui_packpar { - unsigned char anchor; + unsigned char anchor; #define AUI_FILL_NONE 0 -#define AUI_FILL_X 1 -#define AUI_FILL_Y 2 +#define AUI_FILL_X 1 +#define AUI_FILL_Y 2 #define AUI_FILL_BOTH 3 - unsigned char fill; -#define AUI_SIDE_TOP 1 -#define AUI_SIDE_RIGHT 2 -#define AUI_SIDE_LEFT 3 -#define AUI_SIDE_BOTTOM 4 - unsigned char side; + unsigned char fill; +#define AUI_SIDE_TOP 1 +#define AUI_SIDE_RIGHT 2 +#define AUI_SIDE_LEFT 3 +#define AUI_SIDE_BOTTOM 4 + unsigned char side; + unsigned char expand; }; struct aui_gridpar { - unsigned int column; - unsigned int row; + unsigned int column; + unsigned int row; }; struct aui_widget; struct aui_window; struct aui_frame; -struct aui_canvas; /* rendering free of rules */ +struct aui_canvas; /* rendering free of rules */ struct aui_button; struct aui_windowconfig { - unsigned int width; - unsigned int height; - const char *title; /* Should not be allocated, string literal */ + unsigned int width; + unsigned int height; + const char *title; /* Should not be allocated, string literal */ }; struct aui_buttonconfig { - const char *text; /* Should not be allocated, string literal */ + const char *text; /* Should not be allocated, string literal */ }; struct aui_frameconfig { - struct aui_color bg; + struct aui_color bg; }; void aui_run(void); blob - c3835f2fa4c36cfd1df65f0362a1b099240e53c6 blob + bc0fc94ea2c04cfacc6b65412d6b1279c50bc856 --- button.c +++ button.c @@ -14,49 +14,49 @@ static void button_free(struct aui_widget *); static struct aui_geometry button_get_min_size(struct aui_widget *); static struct widget_ops button_ops = { - button_mouse_hover, - button_mouse_unhover, - button_mouse_press, - button_mouse_release, - button_set_geometry, /* set geometry */ - button_free, - button_get_min_size, + button_mouse_hover, + button_mouse_unhover, + button_mouse_press, + button_mouse_release, + button_set_geometry, /* set geometry */ + button_free, + button_get_min_size, }; struct aui_color color[] = { - { 0xff, 0, 0, 0xff }, /* Borders */ - { 0, 0, 0, 0xff }, /* Normal */ - { 0x1b, 0x1b, 0x1b, 0xff }, /* Hover */ - { 0x3b, 0x3b, 0x3b, 0xff }, /* Press */ + { 0xff, 0, 0, 0xff }, /* Borders */ + { 0, 0, 0, 0xff }, /* Normal */ + { 0x1b, 0x1b, 0x1b, 0xff }, /* Hover */ + { 0x3b, 0x3b, 0x3b, 0xff }, /* Press */ }; static struct aui_buttonconfig default_config = { - .text = NULL, + .text = NULL, }; struct aui_button* aui_button_new(struct aui_widget *parent, struct aui_buttonconfig *config) { - struct aui_button *button = calloc(1, sizeof(struct aui_button)); + struct aui_button *button = calloc(1, sizeof(struct aui_button)); struct aui_widget *widget = &button->widget; - widget_init(&button->widget); - widget->in_ops = &button_ops; - widget->type = WIDGET_TYPE_BUTTON; + widget_init(&button->widget); + widget->in_ops = &button_ops; + widget->type = WIDGET_TYPE_BUTTON; /* * Creating the rectangle primitive */ - widget_add(parent, widget); - button->config = (config == NULL) ? default_config : *config; + widget_add(parent, widget); + button->config = (config == NULL) ? default_config : *config; - widget->primitives.count = 3; - widget->primitives.list = calloc(widget->primitives.count, sizeof(struct primitive*)); - widget->primitives.list[0] = driver->ops->create_rectangle(); - widget->primitives.list[1] = driver->ops->create_rectangle(); - widget->primitives.list[2] = driver->ops->create_text(); + widget->primitives.count = 3; + widget->primitives.list = calloc(widget->primitives.count, sizeof(struct primitive*)); + widget->primitives.list[0] = driver->ops->create_rectangle(); + widget->primitives.list[1] = driver->ops->create_rectangle(); + widget->primitives.list[2] = driver->ops->create_text(); - 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_rectangle_color(widget->window, widget->primitives.list[0], &color[0]); + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); return button; } @@ -64,80 +64,80 @@ aui_button_new(struct aui_widget *parent, struct aui_b void button_free(struct aui_widget *widget) { - struct aui_button *button = (struct aui_button *)widget; - widget_remove(widget->parent, widget); + struct aui_button *button = (struct aui_button *)widget; + widget_remove(widget->parent, widget); - driver->ops->delete_rectangle(widget->primitives.list[0]); - driver->ops->delete_rectangle(widget->primitives.list[1]); + driver->ops->delete_rectangle(widget->primitives.list[0]); + driver->ops->delete_rectangle(widget->primitives.list[1]); - widget->window->draw_flag = 1; + widget->window->draw_flag = 1; - free(button); + free(button); } static void button_mouse_hover(struct aui_widget *widget, uint16_t x, uint16_t y) { - struct aui_button *btn = (struct aui_button *)widget; - if (btn->pressed == 0) { - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[2]); - } else { - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[3]); - } + struct aui_button *btn = (struct aui_button *)widget; + if (btn->pressed == 0) { + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[2]); + } else { + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[3]); + } } static void button_mouse_unhover(struct aui_widget *widget) { - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); } static void button_mouse_press(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_button *btn = (struct aui_button *)widget; + struct aui_button *btn = (struct aui_button *)widget; - btn->pressed = 1; - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[3]); + btn->pressed = 1; + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[3]); } static void button_mouse_release(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_button *btn = (struct aui_button *)widget; - btn->pressed = 0; + struct aui_button *btn = (struct aui_button *)widget; + btn->pressed = 0; - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[1], &color[1]); } static void button_set_geometry(struct aui_widget *widget, struct aui_geometry *geom) { - struct aui_button *button = (struct aui_button *)widget; - struct aui_geometry fgeom = { 0 }; - struct aui_geometry tgeom = driver->ops->get_text_geometry(widget->primitives.list[2]); - int tx = geom->x + geom->width / 2 - tgeom.width / 2; - int ty = geom->y + geom->height / 2 + tgeom.height / 2; + struct aui_button *button = (struct aui_button *)widget; + struct aui_geometry fgeom = { 0 }; + struct aui_geometry tgeom = driver->ops->get_text_geometry(widget->primitives.list[2]); + int tx = geom->x + geom->width / 2 - tgeom.width / 2; + int ty = geom->y + geom->height / 2 + tgeom.height / 2; - fgeom.x = geom->x + 1; - fgeom.y = geom->y + 1; - fgeom.width = geom->width - 2; - fgeom.height = geom->height - 2; + fgeom.x = geom->x + 1; + fgeom.y = geom->y + 1; + fgeom.width = geom->width - 2; + fgeom.height = geom->height - 2; - memcpy(&widget->geom, geom, sizeof(struct aui_geometry)); - driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[0], geom); - driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[1], &fgeom); - driver->ops->set_text(widget->primitives.list[2], button->config.text, tx, ty); + memcpy(&widget->geom, geom, sizeof(struct aui_geometry)); + driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[0], geom); + driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[1], &fgeom); + driver->ops->set_text(widget->primitives.list[2], button->config.text, tx, ty); } static struct aui_geometry button_get_min_size(struct aui_widget *widget) { - struct aui_geometry geom = driver->ops->get_text_geometry(widget->primitives.list[2]); - struct aui_button *button = (struct aui_button *)widget; + struct aui_geometry geom = driver->ops->get_text_geometry(widget->primitives.list[2]); + struct aui_button *button = (struct aui_button *)widget; - geom.width = (geom.width < 30) ? geom.width = 30 : geom.width + 30; - geom.height = (button->config.text == NULL) ? 12 + 20 : geom.height + 20; + geom.width = (geom.width < 30) ? geom.width = 30 : geom.width + 30; + geom.height = (button->config.text == NULL) ? 12 + 20 : geom.height + 20; - return geom; + return geom; } blob - 24b0bb03ff00dbec2585c1826cba1e2fa44c6918 blob + 541800459ec99ef1b349cc301b1093997f0e234b --- driver.c +++ driver.c @@ -6,13 +6,13 @@ int driver_open(enum driver_type type) { - switch (type) { - case DRIVER_TYPE_X11: - xcb_driver_open(); - break; - default: - fprintf(stderr, "libaui: attempt to open unknown driver\n"); - return -1; - } - return 0; + switch (type) { + case DRIVER_TYPE_X11: + xcb_driver_open(); + break; + default: + fprintf(stderr, "libaui: attempt to open unknown driver\n"); + return -1; + } + return 0; } blob - 620b99a79fe9e97ea8b25ed17944042bb573ab63 blob + de8deb9ccfb468a2674f1d9993fa41b96297d65d --- driver.h +++ driver.h @@ -5,31 +5,31 @@ #include "widget.h" enum driver_type { - DRIVER_TYPE_X11 + DRIVER_TYPE_X11 }; struct aui_dri { - struct dri_ops *ops; + struct dri_ops *ops; }; struct dri_ops { - struct aui_window *(*create_window)(); - void (*delete_window)(struct aui_window *); - void (*handle_events)(void); - void (*resize_window)(struct aui_window *); - void (*render_background)(struct aui_window *); - void (*render_foreground)(struct aui_window *); + struct aui_window *(*create_window)(); + void (*delete_window)(struct aui_window *); + void (*handle_events)(void); + void (*resize_window)(struct aui_window *); + void (*render_background)(struct aui_window *); + void (*render_foreground)(struct aui_window *); struct primitive *(*create_rectangle)(void); - void (*delete_rectangle) (struct primitive *); - void (*render_rectangle) (struct aui_window *, struct primitive *); - void (*set_rectangle_color) (struct aui_window *, struct primitive *, struct aui_color *); - void (*set_rectangle_geometry) (struct aui_window *, struct primitive *, struct aui_geometry *); + void (*delete_rectangle) (struct primitive *); + void (*render_rectangle) (struct aui_window *, struct primitive *); + void (*set_rectangle_color) (struct aui_window *, struct primitive *, struct aui_color *); + void (*set_rectangle_geometry) (struct aui_window *, struct primitive *, struct aui_geometry *); - struct primitive *(*create_text) (void); - void (*set_text) (struct primitive *, const char *, int16_t, int16_t); - void (*render_text) (struct aui_window *, struct primitive *); - struct aui_geometry (*get_text_geometry) (struct primitive *); + struct primitive *(*create_text) (void); + void (*set_text) (struct primitive *, const char *, int16_t, int16_t); + void (*render_text) (struct aui_window *, struct primitive *); + struct aui_geometry (*get_text_geometry) (struct primitive *); }; extern struct aui_dri *driver; /* Associated with xcb backend */ blob - 243a31f2bae50ea4501d72a8b713bcc76d6ead5c blob + e88d99fca196c55054a1c84058646fab1c1bd911 --- event.h +++ event.h @@ -12,51 +12,51 @@ */ enum aui_event_type { - AUI_EVENT_QUIT, - AUI_EVENT_RESIZE, - AUI_EVENT_KEY_PRESS, - AUI_EVENT_MOUSE_PRESS, - AUI_EVENT_MOUSE_RELEASE, - AUI_EVENT_MOUSE_MOTION, + AUI_EVENT_QUIT, + AUI_EVENT_RESIZE, + AUI_EVENT_KEY_PRESS, + AUI_EVENT_MOUSE_PRESS, + AUI_EVENT_MOUSE_RELEASE, + AUI_EVENT_MOUSE_MOTION, }; TAILQ_HEAD(aui_event_queue, aui_event); struct aui_event { - int type; - struct aui_window *aw; - TAILQ_ENTRY(aui_event) entries; + int type; + struct aui_window *aw; + TAILQ_ENTRY(aui_event) entries; }; struct aui_event_quit { - struct aui_event event; + struct aui_event event; }; struct aui_event_key_press { - struct aui_event event; - unsigned int key; + struct aui_event event; + unsigned int key; }; struct aui_event_resize { - struct aui_event event; - uint16_t old_w, old_h; - uint16_t new_w, new_h; + struct aui_event event; + uint16_t old_w, old_h; + uint16_t new_w, new_h; }; struct aui_event_mouse_motion { - struct aui_event event; - uint16_t x, y; + struct aui_event event; + uint16_t x, y; }; struct aui_event_mouse_press { - struct aui_event event; - uint16_t x, y; - uint8_t button; + struct aui_event event; + uint16_t x, y; + uint8_t button; }; struct aui_event_mouse_release { - struct aui_event event; - uint16_t x, y; - uint8_t button; + struct aui_event event; + uint16_t x, y; + uint8_t button; }; extern struct aui_event_queue ev_queue; blob - 8107740db41370a86a6c633928fae71d642c87e0 blob + 1f102d48dd4007452f43c9b190d4d1735611fc12 --- font.c +++ font.c @@ -5,10 +5,10 @@ #include "font.h" struct _font { - FcConfig *fc_config; - FT_Library ft_library; - char *base; - unsigned int size; + FcConfig *fc_config; + FT_Library ft_library; + char *base; + unsigned int size; }; static struct _font font; @@ -18,94 +18,94 @@ static char *find_font_fc(const char *); int font_init() { - font.fc_config = FcInitLoadConfigAndFonts(); - if (font.fc_config == NULL) { - fprintf(stderr, "libaui: failed to load fontconfig\n"); - return -1; - } + font.fc_config = FcInitLoadConfigAndFonts(); + if (font.fc_config == NULL) { + fprintf(stderr, "libaui: failed to load fontconfig\n"); + return -1; + } - font.size = 12; - font.base = find_font_fc("sans-serif"); + font.size = 12; + font.base = find_font_fc("sans-serif"); - if (FT_Init_FreeType(&font.ft_library) != 0) { - fprintf(stderr, "libaui: FT_Init_FreeType failed!\n"); - return -1; - } + if (FT_Init_FreeType(&font.ft_library) != 0) { + fprintf(stderr, "libaui: FT_Init_FreeType failed!\n"); + return -1; + } - return 0; + return 0; } int font_load_glyphs(struct glyph *gptr, unsigned int dt) { - FT_Face face; + FT_Face face; - if (FT_New_Face(font.ft_library, font.base, 0, &face) != 0 ) { - fprintf(stderr, "libaui: failed to load new face\n"); - return -1; - } + if (FT_New_Face(font.ft_library, font.base, 0, &face) != 0 ) { + fprintf(stderr, "libaui: failed to load new face\n"); + return -1; + } - if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { - fprintf(stderr, "libaui: FT_SelectCharmap failed\n"); - return -1; - } + if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { + fprintf(stderr, "libaui: FT_SelectCharmap failed\n"); + return -1; + } - FT_Set_Pixel_Sizes(face, 0, font.size); + FT_Set_Pixel_Sizes(face, 0, font.size); - for (int i = 0; i < dt; i++) { - struct glyph *g = &gptr[i]; - if (FT_Load_Char(face, g->charcode, FT_LOAD_RENDER) != 0) { - fprintf(stderr, "libaui: FT_Load_Char failed\n"); - return -1; - } + for (int i = 0; i < dt; i++) { + struct glyph *g = &gptr[i]; + if (FT_Load_Char(face, g->charcode, FT_LOAD_RENDER) != 0) { + fprintf(stderr, "libaui: FT_Load_Char failed\n"); + return -1; + } - FT_Bitmap bmp = face->glyph->bitmap; + FT_Bitmap bmp = face->glyph->bitmap; - g->x = -face->glyph->bitmap_left; - g->y = face->glyph->bitmap_top; - g->height = bmp.rows; - g->width = bmp.width; - g->x_offset = face->glyph->advance.x >> 6; /* 26.6 format to pixels */ - g->y_offset = face->glyph->metrics.horiBearingY >> 6; - g->stride = (g->width + 3) &~3; - g->bitmap = calloc(g->stride * g->height, sizeof(*g->bitmap)); + g->x = -face->glyph->bitmap_left; + g->y = face->glyph->bitmap_top; + g->height = bmp.rows; + g->width = bmp.width; + g->x_offset = face->glyph->advance.x >> 6; /* 26.6 format to pixels */ + g->y_offset = face->glyph->metrics.horiBearingY >> 6; + g->stride = (g->width + 3) &~3; + g->bitmap = calloc(g->stride * g->height, sizeof(*g->bitmap)); - for (int y = 0; y < g->height; y++) - memcpy(g->bitmap + y * g->stride, bmp.buffer + y * g->width, g->width); - } + for (int y = 0; y < g->height; y++) + memcpy(g->bitmap + y * g->stride, bmp.buffer + y * g->width, g->width); + } - FT_Done_Face(face); - return 0; + FT_Done_Face(face); + return 0; } static char* find_font_fc(const char *name) { - FcPattern *pattern; - FcPattern *match; - FcResult result; - FcChar8 *file; - char *path; + FcPattern *pattern; + FcPattern *match; + FcResult result; + FcChar8 *file; + char *path; - pattern = FcNameParse((FcChar8 *)name); - if (pattern == NULL) - return NULL; + pattern = FcNameParse((FcChar8 *)name); + if (pattern == NULL) + return NULL; - if (FcConfigSubstitute(font.fc_config, pattern, FcMatchPattern) == FcFalse) { - fprintf(stderr, "libaui: FcConfigSubstitute failed!\n"); - return NULL; - } + if (FcConfigSubstitute(font.fc_config, pattern, FcMatchPattern) == FcFalse) { + fprintf(stderr, "libaui: FcConfigSubstitute failed!\n"); + return NULL; + } - FcConfigSetDefaultSubstitute(font.fc_config, pattern); - match = FcFontMatch(font.fc_config, pattern, &result); + FcConfigSetDefaultSubstitute(font.fc_config, pattern); + match = FcFontMatch(font.fc_config, pattern, &result); - if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultTypeMismatch) { - fprintf(stderr, "libaui: FcPatternGetString\n"); - return NULL; - } + if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultTypeMismatch) { + fprintf(stderr, "libaui: FcPatternGetString\n"); + return NULL; + } - path = strdup((char *)file); - FcPatternDestroy(match); - FcPatternDestroy(pattern); - return path; + path = strdup((char *)file); + FcPatternDestroy(match); + FcPatternDestroy(pattern); + return path; } blob - 52e3e2f0703e2f17efef4be023f2cc8acd1329f1 blob + 93f82183920b9cdbff84b43d81c664782946d2af --- font.h +++ font.h @@ -1,14 +1,14 @@ #ifndef FONT_H struct glyph { - unsigned int charcode; - int x, y; - unsigned int width; - unsigned int height; - int x_offset; - int y_offset; - unsigned int stride; - unsigned char *bitmap; + unsigned int charcode; + int x, y; + unsigned int width; + unsigned int height; + int x_offset; + int y_offset; + unsigned int stride; + unsigned char *bitmap; }; int font_init(void); blob - a5479ecb087d4be19941e7b4f678051e92e0c8f4 blob + 6d4b0c6b5556cb1ad2be7028e7150b3491f18bf8 --- frame.c +++ frame.c @@ -14,109 +14,111 @@ static void frame_free(struct aui_widget *); static struct aui_geometry frame_get_min_size(struct aui_widget *); static struct widget_ops frame_ops = { - frame_mouse_hover, - frame_mouse_unhover, - frame_mouse_press, - frame_mouse_release, - frame_set_geometry, - frame_free, - frame_get_min_size, + frame_mouse_hover, + frame_mouse_unhover, + frame_mouse_press, + frame_mouse_release, + frame_set_geometry, + frame_free, + frame_get_min_size, }; struct aui_color colors[] = { - { 0x77, 0x77, 0x77, 0xff }, + { 0x77, 0x77, 0x77, 0xff }, }; struct aui_frame* aui_frame_new(struct aui_widget *parent) { - struct aui_frame *frame = calloc(1, sizeof(struct aui_frame)); - struct aui_widget *widget = (struct aui_widget *)frame; + struct aui_frame *frame = calloc(1, sizeof(struct aui_frame)); + struct aui_widget *widget = (struct aui_widget *)frame; + struct aui_container *con = (struct aui_container *)frame; - widget_init(widget); - widget->in_ops = &frame_ops; - widget->type = WIDGET_TYPE_FRAME; + widget_init(widget); + widget->in_ops = &frame_ops; + widget->type = WIDGET_TYPE_FRAME; - widget_add(parent, widget); + widget_add(parent, widget); + con->map_count = 0; - widget->primitives.count = 1; - widget->primitives.list = calloc(widget->primitives.count, sizeof(struct primitive *)); - widget->primitives.list[0] = driver->ops->create_rectangle(); + widget->primitives.count = 1; + widget->primitives.list = calloc(widget->primitives.count, sizeof(struct primitive *)); + widget->primitives.list[0] = driver->ops->create_rectangle(); - driver->ops->set_rectangle_color(widget->window, widget->primitives.list[0], &colors[0]); + driver->ops->set_rectangle_color(widget->window, widget->primitives.list[0], &colors[0]); - return frame; + return frame; } static void frame_mouse_hover(struct aui_widget *widget, uint16_t x, uint16_t y) { - struct aui_container *con = (struct aui_container *)widget; - struct aui_widget *tohover = NULL; - struct aui_widget *child; + struct aui_container *con = (struct aui_container *)widget; + struct aui_widget *tohover = NULL; + struct aui_widget *child; - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped && widget_collides_with_point(child, x, y)) - tohover = child; - } + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped && widget_collides_with_point(child, x, y)) + tohover = child; + } - if (tohover != con->focus.hover && con->focus.hover != NULL) - con->focus.hover->in_ops->mouse_unhover(con->focus.hover); + if (tohover != con->focus.hover && con->focus.hover != NULL) + con->focus.hover->in_ops->mouse_unhover(con->focus.hover); - con->focus.hover = tohover; + con->focus.hover = tohover; - if (tohover != NULL) - tohover->in_ops->mouse_hover(tohover, x, y); + if (tohover != NULL) + tohover->in_ops->mouse_hover(tohover, x, y); } static void frame_mouse_unhover(struct aui_widget *widget) { - struct aui_container *con = (struct aui_container *)widget; + struct aui_container *con = (struct aui_container *)widget; - if (con->focus.hover) { - con->focus.hover->in_ops->mouse_unhover(con->focus.hover); - con->focus.hover = NULL; - } + if (con->focus.hover) { + con->focus.hover->in_ops->mouse_unhover(con->focus.hover); + con->focus.hover = NULL; + } } static void frame_mouse_press(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_container *con = (struct aui_container *)widget; - struct aui_widget *topress = NULL; - struct aui_widget *child; + struct aui_container *con = (struct aui_container *)widget; + struct aui_widget *topress = NULL; + struct aui_widget *child; - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped && widget_collides_with_point(child, x, y)) - topress = child; - } + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped && widget_collides_with_point(child, x, y)) + topress = child; + } - if (topress != con->focus.press && con->focus.press != NULL) - con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); + if (topress != con->focus.press && con->focus.press != NULL) + con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); - con->focus.press = topress; + con->focus.press = topress; - if (topress != NULL) - topress->in_ops->mouse_press(topress, x, y, button); + if (topress != NULL) + topress->in_ops->mouse_press(topress, x, y, button); } static void frame_mouse_release(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_container *con = (struct aui_container *)widget; + struct aui_container *con = (struct aui_container *)widget; - if (con->focus.press != NULL) { - con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); - con->focus.press = NULL; - } + if (con->focus.press != NULL) { + con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); + con->focus.press = NULL; + } } static void frame_set_geometry(struct aui_widget *widget, struct aui_geometry *geom) { - memcpy(&widget->geom, geom, sizeof(struct aui_geometry)); - driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[0], geom); + memcpy(&widget->geom, geom, sizeof(struct aui_geometry)); + driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[0], geom); } static void @@ -127,6 +129,6 @@ frame_free(struct aui_widget *widget) static struct aui_geometry frame_get_min_size(struct aui_widget *widget) { - struct aui_geometry geom = { 0, 0, 120, 120 }; - return geom; + struct aui_geometry geom = { 0, 0, 120, 120 }; + return geom; } blob - 8560abe87b8e39117e85a7308fc4bc6afff5e383 blob + 8b61cd2a318aec2f93ebbb799ddd1ff423e21a8c --- layout.c +++ layout.c @@ -8,463 +8,477 @@ static int can_add(struct aui_widget *widget, enum aui_layout_type type) { - struct aui_widget *parent = widget->parent; + struct aui_widget *parent = widget->parent; - if (parent->type != WIDGET_TYPE_WINDOW && parent->type != WIDGET_TYPE_CANVAS && - parent->type != WIDGET_TYPE_FRAME) { - fprintf(stderr, "libaui: cannot map widget in non-container\n"); - return -1; - } + if (parent->type != WIDGET_TYPE_WINDOW && parent->type != WIDGET_TYPE_CANVAS && + parent->type != WIDGET_TYPE_FRAME) { + fprintf(stderr, "libaui: cannot map widget in non-container\n"); + return -1; + } - struct aui_container *con = (struct aui_container *)parent; + struct aui_container *con = (struct aui_container *)parent; - if ((con->layout_type != type) && (con->layout_type != AUI_LAYOUT_NONE)) { - fprintf(stderr, "libaui: cannot map as mismatching type / non-empty container\n"); - return -1; - } + if ((con->layout_type != type) && (con->layout_type != AUI_LAYOUT_NONE)) { + fprintf(stderr, "libaui: cannot map as mismatching type / non-empty container\n"); + return -1; + } - return 0; + return 0; } void layout_organize(struct aui_widget *widget) { - struct aui_container *con = (struct aui_container *)widget; - struct aui_widget *child; + struct aui_container *con = (struct aui_container *)widget; + struct aui_widget *child; - switch (con->layout_type) { - case AUI_LAYOUT_PLACE: - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped == 0) - continue; + switch (con->layout_type) { + case AUI_LAYOUT_PLACE: + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped == 0) + continue; - struct aui_placepar *par = &child->placepar; - int dx = 0, dy = 0; + struct aui_placepar *par = &child->placepar; + int dx = 0, dy = 0; - struct aui_geometry geom = { - .x = widget->geom.x + child->placepar.x + widget->geom.width * child->placepar.relx, - .y = widget->geom.y + child->placepar.y + widget->geom.height * child->placepar.rely, - .width = child->placepar.width + child->placepar.relwidth * widget->geom.width, - .height = child->placepar.height + child->placepar.relheight * widget->geom.height }; + struct aui_geometry geom = { + .x = widget->geom.x + child->placepar.x + widget->geom.width * child->placepar.relx, + .y = widget->geom.y + child->placepar.y + widget->geom.height * child->placepar.rely, + .width = child->placepar.width + child->placepar.relwidth * widget->geom.width, + .height = child->placepar.height + child->placepar.relheight * widget->geom.height }; - switch (par->anchor) { - case AUI_ANCHOR_NW: - dx = 0; - dy = 0; - break; - case AUI_ANCHOR_NE: - dx = -geom.width; - dy = 0; - break; - case AUI_ANCHOR_N: - dx = -geom.width / 2; - dy = 0; - break; - case AUI_ANCHOR_W: - dx = 0; - dy = -geom.height / 2; - break; - case AUI_ANCHOR_E: - dx = -geom.width; - dy = -geom.height /2; - break; - case AUI_ANCHOR_SE: - dx = -geom.width; - dy = -geom.height; - break; - case AUI_ANCHOR_SW: - dx = 0; - dy = -geom.height; - break; - case AUI_ANCHOR_S: - dx = -geom.width / 2; - dy = -geom.height; - break; - case AUI_ANCHOR_CENTER: - dx = -geom.width / 2; - dy = -geom.height / 2; - break; - default: - break; - } + switch (par->anchor) { + case AUI_ANCHOR_NW: + dx = 0; + dy = 0; + break; + case AUI_ANCHOR_NE: + dx = -geom.width; + dy = 0; + break; + case AUI_ANCHOR_N: + dx = -geom.width / 2; + dy = 0; + break; + case AUI_ANCHOR_W: + dx = 0; + dy = -geom.height / 2; + break; + case AUI_ANCHOR_E: + dx = -geom.width; + dy = -geom.height /2; + break; + case AUI_ANCHOR_SE: + dx = -geom.width; + dy = -geom.height; + break; + case AUI_ANCHOR_SW: + dx = 0; + dy = -geom.height; + break; + case AUI_ANCHOR_S: + dx = -geom.width / 2; + dy = -geom.height; + break; + case AUI_ANCHOR_CENTER: + dx = -geom.width / 2; + dy = -geom.height / 2; + break; + default: + break; + } - geom.x += dx; - geom.y += dy; - child->in_ops->set_geometry(child, &geom); + geom.x += dx; + geom.y += dy; + child->in_ops->set_geometry(child, &geom); - switch (child->type) { - case WIDGET_TYPE_FRAME: - layout_organize(child); - break; - default: - break; - } - } - break; - case AUI_LAYOUT_GRID: { - uint8_t *rmap = calloc(con->grid_size[1], sizeof(uint8_t)); - uint8_t *cmap = calloc(con->grid_size[0], sizeof(uint8_t)); + switch (child->type) { + case WIDGET_TYPE_FRAME: + layout_organize(child); + break; + default: + break; + } + } + break; + case AUI_LAYOUT_GRID: { + uint8_t *rmap = calloc(con->grid_size[1], sizeof(uint8_t)); + uint8_t *cmap = calloc(con->grid_size[0], sizeof(uint8_t)); - unsigned int *rsize = calloc(con->grid_size[1], sizeof(unsigned int)); - unsigned int *csize = calloc(con->grid_size[0], sizeof(unsigned int)); + unsigned int *rsize = calloc(con->grid_size[1], sizeof(unsigned int)); + unsigned int *csize = calloc(con->grid_size[0], sizeof(unsigned int)); - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped == 0) - continue; + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped == 0) + continue; - struct aui_geometry min = child->in_ops->get_min_size(child); + struct aui_geometry min = child->in_ops->get_min_size(child); - rmap[child->gridpar.row] = 1; - cmap[child->gridpar.column] = 1; + rmap[child->gridpar.row] = 1; + cmap[child->gridpar.column] = 1; - rsize[child->gridpar.row] = (rsize[child->gridpar.row] < min.height) ? - min.height : rsize[child->gridpar.row]; + rsize[child->gridpar.row] = (rsize[child->gridpar.row] < min.height) ? + min.height : rsize[child->gridpar.row]; - csize[child->gridpar.column] = (csize[child->gridpar.column] < min.width) ? - min.width : csize[child->gridpar.column]; - } + csize[child->gridpar.column] = (csize[child->gridpar.column] < min.width) ? + min.width : csize[child->gridpar.column]; + } - unsigned int *rpos = calloc(con->grid_size[1], sizeof(unsigned int)); - unsigned int *cpos = calloc(con->grid_size[0], sizeof(unsigned int)); + unsigned int *rpos = calloc(con->grid_size[1], sizeof(unsigned int)); + unsigned int *cpos = calloc(con->grid_size[0], sizeof(unsigned int)); - unsigned int rowdt = 0; - unsigned int coldt = 0; + unsigned int rowdt = 0; + unsigned int coldt = 0; - for (int r = 0; r < con->grid_size[1]; r++) { - rpos[r] = rowdt; - rowdt = (rmap[r] == 1) ? rowdt + rsize[r] : rowdt; - } + for (int r = 0; r < con->grid_size[1]; r++) { + rpos[r] = rowdt; + rowdt = (rmap[r] == 1) ? rowdt + rsize[r] : rowdt; + } - for (int c = 0; c < con->grid_size[0]; c++) { - cpos[c] = coldt; - coldt = (cmap[c] == 1) ? coldt + csize[c] : coldt; - } + for (int c = 0; c < con->grid_size[0]; c++) { + cpos[c] = coldt; + coldt = (cmap[c] == 1) ? coldt + csize[c] : coldt; + } - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped == 0) - continue; + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped == 0) + continue; - struct aui_geometry min = child->in_ops->get_min_size(child); - struct aui_geometry geom = { 0 }; + struct aui_geometry min = child->in_ops->get_min_size(child); + struct aui_geometry geom = { 0 }; - int dx = (csize[child->gridpar.column] - min.width); - int dy = (rsize[child->gridpar.row] - min.height); + int dx = (csize[child->gridpar.column] - min.width); + int dy = (rsize[child->gridpar.row] - min.height); - geom.x = widget->geom.x + cpos[child->gridpar.column] + dx / 2; - geom.y = widget->geom.y + rpos[child->gridpar.row] + dy / 2; - geom.width = min.width; - geom.height = min.height; + geom.x = widget->geom.x + cpos[child->gridpar.column] + dx / 2; + geom.y = widget->geom.y + rpos[child->gridpar.row] + dy / 2; + geom.width = min.width; + geom.height = min.height; - child->in_ops->set_geometry(child, &geom); - } + child->in_ops->set_geometry(child, &geom); + } - free(rsize); - free(csize); - free(rpos); - free(cpos); - free(rmap); - free(cmap); + free(rsize); + free(csize); + free(rpos); + free(cpos); + free(rmap); + free(cmap); - TAILQ_FOREACH(child, &widget->queue, entries) { - switch (child->type) { - case WIDGET_TYPE_FRAME: - layout_organize(child); - break; - default: - break; - } - } - break; - } - /* - * As far as I'm aware of, Tk's pack is just a rectangle that shrinks - * depending on the side of the widget being added. - * - * The fill attribute is a bit tricky. You can set it to x, y and both - * but you have to keep in mind that x only works on side top and bottom - * and y works on side left and right. - * - * Keep in mind that expand can make the fill atributte that doesn't - * usually work on a side to changes its geometry. - * - * To implement expand, its necessary to do 2-passes. The first pass is - * to calculate extra spaces. The second pass is for changing geometry. - */ - case AUI_LAYOUT_PACK: { - struct aui_geometry space = widget->in_ops->get_min_size(widget); + TAILQ_FOREACH(child, &widget->queue, entries) { + switch (child->type) { + case WIDGET_TYPE_FRAME: + layout_organize(child); + break; + default: + break; + } + } + break; + } + /* + * As far as I'm aware of, Tk's pack is just a rectangle that shrinks + * depending on the side of the widget being added. + * + * The fill attribute is a bit tricky. You can set it to x, y and both + * but you have to keep in mind that x only works on side top and bottom + * and y works on side left and right. + * + * Keep in mind that expand can make the fill atributte that doesn't + * usually work on a side to changes its geometry. + * + * Expand is pretty much dividing the remaining space among children. + */ + case AUI_LAYOUT_PACK: { + struct aui_geometry space = widget->geom; + unsigned int hexpand = 0; + unsigned int vexpand = 0; + unsigned int req_w = 0; + unsigned int req_h = 0; - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped == 0) - continue; + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped == 0) + continue; - struct aui_geometry cgeom = child->in_ops->get_min_size(child); + struct aui_geometry cgeom = child->in_ops->get_min_size(child); - switch (child->packpar.side) { - case AUI_SIDE_TOP: - cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; - cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; + switch (child->packpar.side) { + case AUI_SIDE_TOP: + cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; + cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; - switch (child->packpar.fill) { - case AUI_FILL_X: - cgeom.width = space.width; - break; - case AUI_FILL_BOTH: - cgeom.width = space.width; - break; - case AUI_FILL_NONE: - default: - break; - } - switch (child->packpar.anchor) { - case AUI_ANCHOR_CENTER: - case AUI_ANCHOR_N: - case AUI_ANCHOR_S: - cgeom.x = space.x + space.width / 2 - cgeom.width / 2; - cgeom.y = space.y; - break; - case AUI_ANCHOR_NW: - case AUI_ANCHOR_SW: - case AUI_ANCHOR_W: - cgeom.x = space.x; - cgeom.y = space.y; - break; - case AUI_ANCHOR_NE: - case AUI_ANCHOR_SE: - case AUI_ANCHOR_E: - cgeom.x = space.x + space.width - cgeom.width; - cgeom.y = space.y; - break; - default: - break; - } - space.y += cgeom.height; - space.height -= cgeom.height; - break; - case AUI_SIDE_LEFT: - cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; - cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; - cgeom.x = space.x; - cgeom.y = space.y + space.height / 2 - cgeom.height / 2; + vexpand = (child->packpar.expand) ? vexpand + 1 : vexpand; - switch (child->packpar.fill) { - case AUI_FILL_Y: - cgeom.height = space.height; - break; - case AUI_FILL_BOTH: - cgeom.height = space.height; - break; - case AUI_FILL_NONE: - default: - break; - } - switch (child->packpar.anchor) { - case AUI_ANCHOR_CENTER: - case AUI_ANCHOR_E: - case AUI_ANCHOR_W: - cgeom.x = space.x; - cgeom.y = space.y + space.height / 2 - cgeom.height / 2; - break; - case AUI_ANCHOR_N: - case AUI_ANCHOR_NE: - case AUI_ANCHOR_NW: - cgeom.x = space.x; - cgeom.y = space.y; - break; - case AUI_ANCHOR_S: - case AUI_ANCHOR_SE: - case AUI_ANCHOR_SW: - cgeom.x = space.x; - cgeom.y = space.y + space.height - cgeom.height; - break; - default: - break; - } - space.width -= cgeom.width; - space.x += cgeom.width; - break; - case AUI_SIDE_RIGHT: - cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; - cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; + switch (child->packpar.fill) { + case AUI_FILL_X: + cgeom.width = space.width; + break; + case AUI_FILL_BOTH: + cgeom.width = space.width; + break; + case AUI_FILL_NONE: + default: + break; + } + switch (child->packpar.anchor) { + case AUI_ANCHOR_CENTER: + case AUI_ANCHOR_N: + case AUI_ANCHOR_S: + cgeom.x = space.x + space.width / 2 - cgeom.width / 2; + cgeom.y = space.y; + break; + case AUI_ANCHOR_NW: + case AUI_ANCHOR_SW: + case AUI_ANCHOR_W: + cgeom.x = space.x; + cgeom.y = space.y; + break; + case AUI_ANCHOR_NE: + case AUI_ANCHOR_SE: + case AUI_ANCHOR_E: + cgeom.x = space.x + space.width - cgeom.width; + cgeom.y = space.y; + break; + default: + break; + } + space.y += cgeom.height; + space.height -= cgeom.height; + break; + case AUI_SIDE_LEFT: + cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; + cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; + cgeom.x = space.x; + cgeom.y = space.y + space.height / 2 - cgeom.height / 2; - switch (child->packpar.fill) { - case AUI_FILL_Y: - cgeom.height = space.height; - break; - case AUI_FILL_BOTH: - cgeom.height = space.height; - break; - case AUI_FILL_NONE: - default: - break; - } - switch (child->packpar.anchor) { - case AUI_ANCHOR_CENTER: - case AUI_ANCHOR_E: - case AUI_ANCHOR_W: - cgeom.x = space.x + space.width - cgeom.width; - cgeom.y = space.y + space.height / 2 - cgeom.height / 2; - break; - case AUI_ANCHOR_N: - case AUI_ANCHOR_NE: - case AUI_ANCHOR_NW: - cgeom.x = space.x + space.width - cgeom.width; - cgeom.y = space.y; - break; - case AUI_ANCHOR_S: - case AUI_ANCHOR_SE: - case AUI_ANCHOR_SW: - cgeom.x = space.x + space.width - cgeom.width; - cgeom.y = space.y + space.height - cgeom.height; - break; - default: - break; - } - space.width -= cgeom.width; - break; - case AUI_SIDE_BOTTOM: - cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; - cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; + hexpand = (child->packpar.expand) ? hexpand + 1 : hexpand; - switch (child->packpar.fill) { - case AUI_FILL_X: - cgeom.width = space.width; - break; - case AUI_FILL_BOTH: - cgeom.width = space.width; - break; - case AUI_FILL_NONE: - default: - break; - } - switch (child->packpar.anchor) { - case AUI_ANCHOR_CENTER: - case AUI_ANCHOR_N: - case AUI_ANCHOR_S: - cgeom.x = space.x + space.width / 2 - cgeom.width / 2; - cgeom.y = space.y + space.height - cgeom.height; - break; - case AUI_ANCHOR_NW: - case AUI_ANCHOR_SW: - case AUI_ANCHOR_W: - cgeom.x = space.x; - cgeom.y = space.y + space.height - cgeom.height; - break; - case AUI_ANCHOR_NE: - case AUI_ANCHOR_SE: - case AUI_ANCHOR_E: - cgeom.x = space.x + space.width - cgeom.width; - cgeom.y = space.y + space.height - cgeom.height; - break; - default: - break; - } - space.height -= cgeom.height; - break; - default: - continue; - } - child->in_ops->set_geometry(child, &cgeom); - } + switch (child->packpar.fill) { + case AUI_FILL_Y: + cgeom.height = space.height; + break; + case AUI_FILL_BOTH: + cgeom.height = space.height; + break; + case AUI_FILL_NONE: + default: + break; + } + switch (child->packpar.anchor) { + case AUI_ANCHOR_CENTER: + case AUI_ANCHOR_E: + case AUI_ANCHOR_W: + cgeom.x = space.x; + cgeom.y = space.y + space.height / 2 - cgeom.height / 2; + break; + case AUI_ANCHOR_N: + case AUI_ANCHOR_NE: + case AUI_ANCHOR_NW: + cgeom.x = space.x; + cgeom.y = space.y; + break; + case AUI_ANCHOR_S: + case AUI_ANCHOR_SE: + case AUI_ANCHOR_SW: + cgeom.x = space.x; + cgeom.y = space.y + space.height - cgeom.height; + break; + default: + break; + } + space.width -= cgeom.width; + space.x += cgeom.width; + break; + case AUI_SIDE_RIGHT: + cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; + cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; - TAILQ_FOREACH(child, &widget->queue, entries) { - switch (child->type) { - case WIDGET_TYPE_FRAME: - layout_organize(child); - break; - default: - break; - } - } - break; - } - default: - break; - } + hexpand = (child->packpar.expand) ? hexpand + 1 : hexpand; + + switch (child->packpar.fill) { + case AUI_FILL_Y: + cgeom.height = space.height; + break; + case AUI_FILL_BOTH: + cgeom.height = space.height; + break; + case AUI_FILL_NONE: + default: + break; + } + switch (child->packpar.anchor) { + case AUI_ANCHOR_CENTER: + case AUI_ANCHOR_E: + case AUI_ANCHOR_W: + cgeom.x = space.x + space.width - cgeom.width; + cgeom.y = space.y + space.height / 2 - cgeom.height / 2; + break; + case AUI_ANCHOR_N: + case AUI_ANCHOR_NE: + case AUI_ANCHOR_NW: + cgeom.x = space.x + space.width - cgeom.width; + cgeom.y = space.y; + break; + case AUI_ANCHOR_S: + case AUI_ANCHOR_SE: + case AUI_ANCHOR_SW: + cgeom.x = space.x + space.width - cgeom.width; + cgeom.y = space.y + space.height - cgeom.height; + break; + default: + break; + } + space.width -= cgeom.width; + break; + case AUI_SIDE_BOTTOM: + cgeom.width = (cgeom.width > space.width) ? space.width : cgeom.width; + cgeom.height = (cgeom.height > space.height) ? space.height : cgeom.height; + + vexpand = (child->packpar.expand) ? vexpand + 1 : vexpand; + + switch (child->packpar.fill) { + case AUI_FILL_X: + cgeom.width = space.width; + break; + case AUI_FILL_BOTH: + cgeom.width = space.width; + break; + case AUI_FILL_NONE: + default: + break; + } + switch (child->packpar.anchor) { + case AUI_ANCHOR_CENTER: + case AUI_ANCHOR_N: + case AUI_ANCHOR_S: + cgeom.x = space.x + space.width / 2 - cgeom.width / 2; + cgeom.y = space.y + space.height - cgeom.height; + break; + case AUI_ANCHOR_NW: + case AUI_ANCHOR_SW: + case AUI_ANCHOR_W: + cgeom.x = space.x; + cgeom.y = space.y + space.height - cgeom.height; + break; + case AUI_ANCHOR_NE: + case AUI_ANCHOR_SE: + case AUI_ANCHOR_E: + cgeom.x = space.x + space.width - cgeom.width; + cgeom.y = space.y + space.height - cgeom.height; + break; + default: + break; + } + space.height -= cgeom.height; + break; + default: + continue; + } + child->in_ops->set_geometry(child, &cgeom); + } + + TAILQ_FOREACH(child, &widget->queue, entries) { + switch (child->type) { + case WIDGET_TYPE_FRAME: + layout_organize(child); + break; + default: + break; + } + } + break; + } + default: + break; + } } int aui_place(struct aui_widget *widget, struct aui_placepar *par) { - int check = can_add(widget, AUI_LAYOUT_PLACE); - struct aui_widget *parent; - struct aui_container *con; + int check = can_add(widget, AUI_LAYOUT_PLACE); + struct aui_widget *parent; + struct aui_container *con; - if (check == -1) - return -1; + if (check == -1) + return -1; - con = (struct aui_container *)widget->parent; - parent = (struct aui_widget *)widget->parent; - con->layout_type = AUI_LAYOUT_PLACE; - widget->placepar = *(par); - widget->mapped = 1; + con = (struct aui_container *)widget->parent; + parent = (struct aui_widget *)widget->parent; + con->layout_type = AUI_LAYOUT_PLACE; + widget->placepar = *(par); + widget->mapped = 1; + con->map_count++; - layout_organize(parent); + layout_organize(parent); - return 0; + return 0; } int aui_pack(struct aui_widget *widget, struct aui_packpar *par) { - int check = can_add(widget, AUI_LAYOUT_PACK); - struct aui_widget *parent; - struct aui_container *con; + int check = can_add(widget, AUI_LAYOUT_PACK); + struct aui_widget *parent; + struct aui_container *con; - if (check == -1) - return - 1; + if (check == -1) + return - 1; - con = (struct aui_container *)widget->parent; - parent = widget->parent; - con->layout_type = AUI_LAYOUT_PACK; - widget->packpar = *(par); - widget->mapped = 1; + con = (struct aui_container *)widget->parent; + parent = widget->parent; + con->layout_type = AUI_LAYOUT_PACK; + widget->packpar = *(par); + widget->mapped = 1; + con->map_count++; - layout_organize(parent); + layout_organize(parent); - return 0; + return 0; } int aui_grid(struct aui_widget *widget, struct aui_gridpar *par) { - int check = can_add(widget, AUI_LAYOUT_GRID); - struct aui_widget *parent; - struct aui_container *con; + int check = can_add(widget, AUI_LAYOUT_GRID); + struct aui_widget *parent; + struct aui_container *con; - if (check == -1) - return -1; + if (check == -1) + return -1; - con = (struct aui_container *)widget->parent; - parent = widget->parent; - con->layout_type = AUI_LAYOUT_GRID; - widget->gridpar = *(par); - widget->mapped = 1; + con = (struct aui_container *)widget->parent; + parent = widget->parent; + con->layout_type = AUI_LAYOUT_GRID; + widget->gridpar = *(par); + widget->mapped = 1; + con->map_count++; - con->grid_size[0] = (con->grid_size[0] > par->column + 1) ? con->grid_size[0] : par->column + 1; - con->grid_size[1] = (con->grid_size[1] > par->row + 1) ? con->grid_size[1] : par->row + 1; + con->grid_size[0] = (con->grid_size[0] > par->column + 1) ? con->grid_size[0] : par->column + 1; + con->grid_size[1] = (con->grid_size[1] > par->row + 1) ? con->grid_size[1] : par->row + 1; - layout_organize(parent); + layout_organize(parent); - return 0; + return 0; } int aui_getplacepar(struct aui_widget *widget, struct aui_placepar *par) { - *par = widget->placepar; - return 0; + *par = widget->placepar; + return 0; } int aui_getpackpar(struct aui_widget *widget, struct aui_packpar *par) { - *par = widget->packpar; - return 0; + *par = widget->packpar; + return 0; } int aui_getgridpar(struct aui_widget *widget, struct aui_gridpar *par) { - *par = widget->gridpar; - return 0; + *par = widget->gridpar; + return 0; } blob - 4abc23cd858e4af449fa6f1f1307845bc6319e7b blob + f85d43f0c4dc673b366f3193971ad988171b2d87 --- layout.h +++ layout.h @@ -2,10 +2,10 @@ #define LAYOUT_H enum aui_layout_type { - AUI_LAYOUT_NONE, - AUI_LAYOUT_PLACE, - AUI_LAYOUT_GRID, - AUI_LAYOUT_PACK + AUI_LAYOUT_NONE, + AUI_LAYOUT_PLACE, + AUI_LAYOUT_GRID, + AUI_LAYOUT_PACK }; void layout_organize(struct aui_widget *widget); blob - f7dd9ea8e96c48a44d32ce7d9fe65ff67d764457 blob + ede1ed63d3bbaa8855fba5620134082e59e9d449 --- primitive.h +++ primitive.h @@ -2,12 +2,12 @@ #define PRIMITIVE_H enum primitive_type { - PRIMITIVE_TYPE_RECTANGLE, - PRIMITIVE_TYPE_TEXT, + PRIMITIVE_TYPE_RECTANGLE, + PRIMITIVE_TYPE_TEXT, }; struct primitive { - unsigned int type; + unsigned int type; }; #endif blob - cd3f35f503057c9db280654aa530b7ce9d8072bb blob + cfee5f6224d955edc4c35a647d73c5094a7d5193 --- ui.c +++ ui.c @@ -13,147 +13,147 @@ struct aui_event_queue ev_queue; void aui_add_event(struct aui_event *event) { - struct aui_event *toadd; + struct aui_event *toadd; - switch (event->type) { - case AUI_EVENT_QUIT: { - struct aui_event_quit *qev = calloc(1, sizeof(struct aui_event_quit)); - memcpy((void *)qev, event, sizeof(struct aui_event_quit)); + switch (event->type) { + case AUI_EVENT_QUIT: { + struct aui_event_quit *qev = calloc(1, sizeof(struct aui_event_quit)); + memcpy((void *)qev, event, sizeof(struct aui_event_quit)); - toadd = &qev->event; - break; - } - case AUI_EVENT_RESIZE: { - struct aui_event_resize *erz = calloc(1, sizeof(struct aui_event_resize)); - memcpy((void *)erz, event, sizeof(struct aui_event_resize)); + toadd = &qev->event; + break; + } + case AUI_EVENT_RESIZE: { + struct aui_event_resize *erz = calloc(1, sizeof(struct aui_event_resize)); + memcpy((void *)erz, event, sizeof(struct aui_event_resize)); - /* - printf("libaui: resize %dx%d => %dx%d\n", erz->old_w, erz->old_h, erz->new_w, erz->new_h); - */ + /* + printf("libaui: resize %dx%d => %dx%d\n", erz->old_w, erz->old_h, erz->new_w, erz->new_h); + */ - toadd = &erz->event; - break; - } - case AUI_EVENT_MOUSE_MOTION: { - struct aui_event_mouse_motion *mev = calloc(1, sizeof(struct aui_event_mouse_motion)); - memcpy((void *)mev, event, sizeof(struct aui_event_mouse_motion)); + toadd = &erz->event; + break; + } + case AUI_EVENT_MOUSE_MOTION: { + struct aui_event_mouse_motion *mev = calloc(1, sizeof(struct aui_event_mouse_motion)); + memcpy((void *)mev, event, sizeof(struct aui_event_mouse_motion)); - toadd = &mev->event; - break; - } - case AUI_EVENT_MOUSE_PRESS: { - struct aui_event_mouse_press *mpe = calloc(1, sizeof(struct aui_event_mouse_press)); - memcpy((void *)mpe, event, sizeof(struct aui_event_mouse_press)); + toadd = &mev->event; + break; + } + case AUI_EVENT_MOUSE_PRESS: { + struct aui_event_mouse_press *mpe = calloc(1, sizeof(struct aui_event_mouse_press)); + memcpy((void *)mpe, event, sizeof(struct aui_event_mouse_press)); - toadd = &mpe->event; - break; - } - case AUI_EVENT_MOUSE_RELEASE: { - struct aui_event_mouse_release *mre = calloc(1, sizeof(struct aui_event_mouse_release)); - memcpy((void *)mre, event, sizeof(struct aui_event_mouse_release)); + toadd = &mpe->event; + break; + } + case AUI_EVENT_MOUSE_RELEASE: { + struct aui_event_mouse_release *mre = calloc(1, sizeof(struct aui_event_mouse_release)); + memcpy((void *)mre, event, sizeof(struct aui_event_mouse_release)); - toadd = &mre->event; - break; - } - default: - fprintf(stderr, "libaui: failed to add event\n"); - return; - } + toadd = &mre->event; + break; + } + default: + fprintf(stderr, "libaui: failed to add event\n"); + return; + } - TAILQ_INSERT_TAIL(&ev_queue, toadd, entries); + TAILQ_INSERT_TAIL(&ev_queue, toadd, entries); } void aui_run(void) { - while (!LIST_EMPTY(&wlist)) { - driver->ops->handle_events(); + while (!LIST_EMPTY(&wlist)) { + driver->ops->handle_events(); - /* - * Event Management - */ - struct aui_event *ev; - while (!TAILQ_EMPTY(&ev_queue)) { - ev = TAILQ_FIRST(&ev_queue); - TAILQ_REMOVE(&ev_queue, ev, entries); + /* + * Event Management + */ + struct aui_event *ev; + while (!TAILQ_EMPTY(&ev_queue)) { + ev = TAILQ_FIRST(&ev_queue); + TAILQ_REMOVE(&ev_queue, ev, entries); - switch (ev->type) { - case AUI_EVENT_QUIT: { - struct aui_event_quit *qev = (struct aui_event_quit *)ev; - struct aui_window *aw = ev->aw; - struct aui_widget *ww = (struct aui_widget *)aw; + switch (ev->type) { + case AUI_EVENT_QUIT: { + struct aui_event_quit *qev = (struct aui_event_quit *)ev; + struct aui_window *aw = ev->aw; + struct aui_widget *ww = (struct aui_widget *)aw; - ww->in_ops->free(ww); + ww->in_ops->free(ww); - free((void *)qev); - break; - } - case AUI_EVENT_RESIZE: { - struct aui_event_resize *rze = (struct aui_event_resize *)ev; - struct aui_window *aw = ev->aw; + free((void *)qev); + break; + } + case AUI_EVENT_RESIZE: { + struct aui_event_resize *rze = (struct aui_event_resize *)ev; + struct aui_window *aw = ev->aw; - aw->config.width = rze->new_w; - aw->config.height = rze->new_h; + aw->config.width = rze->new_w; + aw->config.height = rze->new_h; - driver->ops->resize_window(aw); - free((void *)rze); + driver->ops->resize_window(aw); + free((void *)rze); - layout_organize((struct aui_widget *)aw); - break; - } - case AUI_EVENT_MOUSE_MOTION: { - struct aui_event_mouse_motion *mev = (struct aui_event_mouse_motion *)ev; - struct aui_window *aw = ev->aw; - struct aui_widget *ww = (struct aui_widget *)aw; - struct widget_ops *ops = ww->in_ops; + layout_organize((struct aui_widget *)aw); + break; + } + case AUI_EVENT_MOUSE_MOTION: { + struct aui_event_mouse_motion *mev = (struct aui_event_mouse_motion *)ev; + struct aui_window *aw = ev->aw; + struct aui_widget *ww = (struct aui_widget *)aw; + struct widget_ops *ops = ww->in_ops; - ops->mouse_hover(ww, mev->x, mev->y); - free((void *)mev); - break; - } - case AUI_EVENT_MOUSE_PRESS: { - struct aui_event_mouse_press *mpe = (struct aui_event_mouse_press *)ev; - struct aui_window *aw = ev->aw; - struct aui_widget *ww = (struct aui_widget *)aw; - struct widget_ops *ops = ww->in_ops; + ops->mouse_hover(ww, mev->x, mev->y); + free((void *)mev); + break; + } + case AUI_EVENT_MOUSE_PRESS: { + struct aui_event_mouse_press *mpe = (struct aui_event_mouse_press *)ev; + struct aui_window *aw = ev->aw; + struct aui_widget *ww = (struct aui_widget *)aw; + struct widget_ops *ops = ww->in_ops; - ops->mouse_press(ww, mpe->x, mpe->y, mpe->button); - free((void *)mpe); - break; - } - case AUI_EVENT_MOUSE_RELEASE: { - struct aui_event_mouse_release *mre = (struct aui_event_mouse_release *)ev; - struct aui_window *aw = ev->aw; - struct aui_widget *ww = (struct aui_widget *)aw; - struct widget_ops *ops = ww->in_ops; + ops->mouse_press(ww, mpe->x, mpe->y, mpe->button); + free((void *)mpe); + break; + } + case AUI_EVENT_MOUSE_RELEASE: { + struct aui_event_mouse_release *mre = (struct aui_event_mouse_release *)ev; + struct aui_window *aw = ev->aw; + struct aui_widget *ww = (struct aui_widget *)aw; + struct widget_ops *ops = ww->in_ops; - ops->mouse_release(ww, mre->x, mre->y, mre->button); - free((void *)mre); - break; - } - default: - break; - } - } + ops->mouse_release(ww, mre->x, mre->y, mre->button); + free((void *)mre); + break; + } + default: + break; + } + } - /* - * Draw Calls - */ - struct aui_window *aw; - LIST_FOREACH(aw, &wlist, entries) { - if (aw->draw_flag) { - struct aui_widget *widget = (struct aui_widget *)aw; - driver->ops->render_background(aw); - widget_draw(widget); - driver->ops->render_foreground(aw); - aw->draw_flag = 0; - } - } - } + /* + * Draw Calls + */ + struct aui_window *aw; + LIST_FOREACH(aw, &wlist, entries) { + if (aw->draw_flag) { + struct aui_widget *widget = (struct aui_widget *)aw; + driver->ops->render_background(aw); + widget_draw(widget); + driver->ops->render_foreground(aw); + aw->draw_flag = 0; + } + } + } } void aui_destroy(struct aui_widget *widget) { - widget->in_ops->free(widget); + widget->in_ops->free(widget); } blob - 046eed04944f30c9dd8868af297e068a43c24b04 blob + 4804212e7cd8b12619f03db0f4fce2852bfe5b29 --- widget.c +++ widget.c @@ -9,60 +9,60 @@ void widget_init(struct aui_widget *widget) { - TAILQ_INIT(&(widget)->queue); - widget->geom = (struct aui_geometry) { 0 }; - widget->mapped = 0; + TAILQ_INIT(&(widget)->queue); + widget->geom = (struct aui_geometry) { 0 }; + widget->mapped = 0; - memset(&widget->placepar, 0, sizeof(struct aui_placepar)); - memset(&widget->gridpar, 0, sizeof(struct aui_gridpar)); - memset(&widget->packpar, 0, sizeof(struct aui_packpar)); + memset(&widget->placepar, 0, sizeof(struct aui_placepar)); + memset(&widget->gridpar, 0, sizeof(struct aui_gridpar)); + memset(&widget->packpar, 0, sizeof(struct aui_packpar)); } void widget_add(struct aui_widget *parent, struct aui_widget *child) { - child->parent = parent; - child->window = parent->window; - TAILQ_INSERT_TAIL(&parent->queue, child, entries); + child->parent = parent; + child->window = parent->window; + TAILQ_INSERT_TAIL(&parent->queue, child, entries); } void widget_remove(struct aui_widget *parent, struct aui_widget *child) { - TAILQ_REMOVE(&parent->queue, child, entries); + TAILQ_REMOVE(&parent->queue, child, entries); } void widget_draw(struct aui_widget *widget) { - if (widget->mapped == 0) - return; + if (widget->mapped == 0) + return; - struct primitive *prim; - for (int i = 0; i < widget->primitives.count; i++) { - prim = widget->primitives.list[i]; + struct primitive *prim; + for (int i = 0; i < widget->primitives.count; i++) { + prim = widget->primitives.list[i]; - switch (prim->type) { - case PRIMITIVE_TYPE_RECTANGLE: - driver->ops->render_rectangle(widget->window, prim); - break; - case PRIMITIVE_TYPE_TEXT: - driver->ops->render_text(widget->window, prim); - break; - default: - break; - } - } + switch (prim->type) { + case PRIMITIVE_TYPE_RECTANGLE: + driver->ops->render_rectangle(widget->window, prim); + break; + case PRIMITIVE_TYPE_TEXT: + driver->ops->render_text(widget->window, prim); + break; + default: + break; + } + } - struct aui_widget *child; - TAILQ_FOREACH(child, &widget->queue, entries) { - widget_draw(child); - } + struct aui_widget *child; + TAILQ_FOREACH(child, &widget->queue, entries) { + widget_draw(child); + } } int widget_collides_with_point(struct aui_widget *widget, uint16_t x, uint16_t y) { - return (x >= widget->geom.x && x < (widget->geom.x + widget->geom.width) && - y >= widget->geom.y && y < (widget->geom.y + widget->geom.height)); + return (x >= widget->geom.x && x < (widget->geom.x + widget->geom.width) && + y >= widget->geom.y && y < (widget->geom.y + widget->geom.height)); } blob - ea1275edf338f2e6c3ab8c83c1d8410f8c0d0f9d blob + 841d4a6f6dcc8401e886327bf1226c5c7d7bbac2 --- widget.h +++ widget.h @@ -9,85 +9,86 @@ * Gives screen position */ struct aui_geometry { - int x, y; - uint16_t width; - uint16_t height; + int x, y; + uint16_t width; + uint16_t height; }; enum widget_type { - WIDGET_TYPE_WINDOW, - WIDGET_TYPE_FRAME, - WIDGET_TYPE_CANVAS, + WIDGET_TYPE_WINDOW, + WIDGET_TYPE_FRAME, + WIDGET_TYPE_CANVAS, WIDGET_TYPE_BUTTON, }; TAILQ_HEAD(aui_widget_queue, aui_widget); struct aui_widget { - enum widget_type type; - struct aui_geometry geom; + enum widget_type type; + struct aui_geometry geom; struct aui_window *window; - struct widget_ops *in_ops; + struct widget_ops *in_ops; - struct aui_placepar placepar; - struct aui_gridpar gridpar; - struct aui_packpar packpar; + struct aui_placepar placepar; + struct aui_gridpar gridpar; + struct aui_packpar packpar; - unsigned int mapped; + unsigned int mapped; - struct widget_primitives { - unsigned int count; - struct primitive **list; - } primitives; + struct widget_primitives { + unsigned int count; + struct primitive **list; + } primitives; - struct aui_widget *parent; - struct aui_widget_queue queue; - TAILQ_ENTRY(aui_widget) entries; + struct aui_widget *parent; + struct aui_widget_queue queue; + TAILQ_ENTRY(aui_widget) entries; }; struct widget_ops { - void (*mouse_hover) (struct aui_widget *, uint16_t, uint16_t); - void (*mouse_unhover) (struct aui_widget *); - void (*mouse_press) (struct aui_widget *, uint16_t, uint16_t, uint8_t); - void (*mouse_release) (struct aui_widget *, uint16_t, uint16_t, uint8_t); - void (*set_geometry) (struct aui_widget *, struct aui_geometry *); - void (*free) (struct aui_widget *); - struct aui_geometry (*get_min_size) (struct aui_widget *); + void (*mouse_hover) (struct aui_widget *, uint16_t, uint16_t); + void (*mouse_unhover) (struct aui_widget *); + void (*mouse_press) (struct aui_widget *, uint16_t, uint16_t, uint8_t); + void (*mouse_release) (struct aui_widget *, uint16_t, uint16_t, uint8_t); + void (*set_geometry) (struct aui_widget *, struct aui_geometry *); + void (*free) (struct aui_widget *); + struct aui_geometry (*get_min_size) (struct aui_widget *); }; struct aui_container { - struct aui_widget widget; - enum aui_layout_type layout_type; - uint32_t grid_size[2]; + struct aui_widget widget; + enum aui_layout_type layout_type; + uint32_t grid_size[2]; + unsigned int map_count; - struct container_focus { - struct aui_widget *press; - struct aui_widget *hover; - } focus; + struct container_focus { + struct aui_widget *press; + struct aui_widget *hover; + } focus; }; LIST_HEAD(aui_window_list, aui_window); struct aui_window { - struct aui_container con; - const char *title; - int draw_flag; - struct aui_windowconfig config; + struct aui_container con; + const char *title; + int draw_flag; + struct aui_windowconfig config; - LIST_ENTRY(aui_window) entries; + LIST_ENTRY(aui_window) entries; }; struct aui_frame { - struct aui_container con; + struct aui_container con; }; struct aui_canvas { - struct aui_container con; + struct aui_container con; }; struct aui_button { struct aui_widget widget; - unsigned int pressed; - struct aui_buttonconfig config; + unsigned int pressed; + struct aui_buttonconfig config; }; extern struct aui_window_list wlist; blob - 15256c1c92b57321638eae18c58b770b1ddaf469 blob + c405d7fd1ddefd3eaaa7ed7f5aa873c8a97a3330 --- window.c +++ window.c @@ -17,76 +17,78 @@ static void window_free(struct aui_widget *); static struct aui_geometry window_get_min_size(struct aui_widget *); static struct widget_ops window_ops = { - window_mouse_hover, - window_mouse_unhover, - window_mouse_press, - window_mouse_release, - NULL, /* set geomtry */ - window_free, - window_get_min_size, + window_mouse_hover, + window_mouse_unhover, + window_mouse_press, + window_mouse_release, + NULL, /* set geomtry */ + window_free, + window_get_min_size, }; static struct aui_windowconfig default_config = { - .width = 200, - .height = 200, - .title = "aui", + .width = 200, + .height = 200, + .title = "aui", }; struct aui_window* aui_window_new(struct aui_windowconfig *config) { - if (driver == NULL) { - if (driver_open(DRIVER_TYPE_X11) == -1) { - return NULL; - } - TAILQ_INIT(&ev_queue); - LIST_INIT(&wlist); - } + if (driver == NULL) { + if (driver_open(DRIVER_TYPE_X11) == -1) { + return NULL; + } + TAILQ_INIT(&ev_queue); + LIST_INIT(&wlist); + } - struct aui_window *aw = driver->ops->create_window(); - struct aui_widget *widget = (struct aui_widget *)aw; - widget->type = WIDGET_TYPE_WINDOW; + struct aui_window *aw = driver->ops->create_window(); + struct aui_widget *widget = (struct aui_widget *)aw; + struct aui_container *con = (struct aui_container *)aw; + widget->type = WIDGET_TYPE_WINDOW; + con->map_count = 0; - LIST_INSERT_HEAD(&wlist, aw, entries); - widget_init(widget); + LIST_INSERT_HEAD(&wlist, aw, entries); + widget_init(widget); - widget->in_ops = &window_ops; - widget->mapped = 1; + widget->in_ops = &window_ops; + widget->mapped = 1; widget->window = aw; - aw->draw_flag = 1; - return aw; + aw->draw_flag = 1; + return aw; } void window_free(struct aui_widget *widget) { - struct aui_window *aw = (struct aui_window *)widget; + struct aui_window *aw = (struct aui_window *)widget; - LIST_REMOVE(aw, entries); - driver->ops->delete_window(aw); + LIST_REMOVE(aw, entries); + driver->ops->delete_window(aw); } static void window_mouse_hover(struct aui_widget *widget, uint16_t x, uint16_t y) { - struct aui_window *aw = (struct aui_window *)widget; - struct aui_container *con = (struct aui_container *)widget; - struct aui_widget *tohover = NULL; - struct aui_widget *child; + struct aui_window *aw = (struct aui_window *)widget; + struct aui_container *con = (struct aui_container *)widget; + struct aui_widget *tohover = NULL; + struct aui_widget *child; - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped && widget_collides_with_point(child, x, y)) - tohover = child; - } + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped && widget_collides_with_point(child, x, y)) + tohover = child; + } - if (tohover != con->focus.hover && con->focus.hover != NULL) - con->focus.hover->in_ops->mouse_unhover(con->focus.hover); + if (tohover != con->focus.hover && con->focus.hover != NULL) + con->focus.hover->in_ops->mouse_unhover(con->focus.hover); - con->focus.hover = tohover; + con->focus.hover = tohover; - if (tohover != NULL) - tohover->in_ops->mouse_hover(tohover, x, y); + if (tohover != NULL) + tohover->in_ops->mouse_hover(tohover, x, y); } static void @@ -98,45 +100,45 @@ window_mouse_unhover(struct aui_widget *widget) static void window_mouse_press(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_container *con = (struct aui_container *)widget; - struct aui_window *aw = (struct aui_window *)widget; - struct aui_widget *topress = NULL; - struct aui_widget *child; + struct aui_container *con = (struct aui_container *)widget; + struct aui_window *aw = (struct aui_window *)widget; + struct aui_widget *topress = NULL; + struct aui_widget *child; - TAILQ_FOREACH(child, &widget->queue, entries) { - if (child->mapped && widget_collides_with_point(child, x, y)) - topress = child; - } + TAILQ_FOREACH(child, &widget->queue, entries) { + if (child->mapped && widget_collides_with_point(child, x, y)) + topress = child; + } - if (topress != con->focus.press && con->focus.press != NULL) - con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); + if (topress != con->focus.press && con->focus.press != NULL) + con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); - con->focus.press = topress; + con->focus.press = topress; - if (topress != NULL) - topress->in_ops->mouse_press(topress, x, y, button); + if (topress != NULL) + topress->in_ops->mouse_press(topress, x, y, button); } static void window_mouse_release(struct aui_widget *widget, uint16_t x, uint16_t y, uint8_t button) { - struct aui_container *con = (struct aui_container *)widget; - struct aui_window *aw = (struct aui_window *)widget; + struct aui_container *con = (struct aui_container *)widget; + struct aui_window *aw = (struct aui_window *)widget; - if (con->focus.press != NULL) { - con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); - con->focus.press = NULL; + if (con->focus.press != NULL) { + con->focus.press->in_ops->mouse_release(con->focus.press, x, y, button); + con->focus.press = NULL; - window_mouse_hover(widget, x, y); - } + window_mouse_hover(widget, x, y); + } } static struct aui_geometry window_get_min_size(struct aui_widget *widget) { - struct aui_window *aw = (struct aui_window *)widget; - struct aui_geometry geom = { 0 }; - geom.width = aw->config.width; - geom.height = aw->config.height; - return geom; + struct aui_window *aw = (struct aui_window *)widget; + struct aui_geometry geom = { 0 }; + geom.width = aw->config.width; + geom.height = aw->config.height; + return geom; } blob - b88d6b81f550c899060e146947338007cd7960c5 blob + 4423a907eb4517e8175bf96e7f7c4e22e2f4e1d6 --- xcb.c +++ xcb.c @@ -14,31 +14,31 @@ #include "primitive.h" struct aui_dri_xcb { - struct aui_dri adr; + struct aui_dri adr; - struct pollfd pollfd; /* One reason, POSIX */ + struct pollfd pollfd; /* One reason, POSIX */ - xcb_connection_t *conn; - xcb_screen_t *screen; - xcb_intern_atom_reply_t *wm_protocols; - xcb_intern_atom_reply_t *wm_delete_window; + xcb_connection_t *conn; + xcb_screen_t *screen; + xcb_intern_atom_reply_t *wm_protocols; + 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; - xcb_render_pictformat_t fmt_alpha8; - xcb_render_pictformat_t fmt_argb32; + xcb_render_glyphset_t glyphset; + xcb_render_picture_t glyphpic; + struct glyph *glyphs; + int font_height; + xcb_render_pictformat_t fmt_normal; + xcb_render_pictformat_t fmt_alpha8; + xcb_render_pictformat_t fmt_argb32; }; struct aui_window_xcb { - struct aui_window aw; + struct aui_window aw; - xcb_window_t xw; - xcb_pixmap_t pixmap; - xcb_render_picture_t dst_pict; - xcb_render_picture_t src_pict; + xcb_window_t xw; + xcb_pixmap_t pixmap; + xcb_render_picture_t dst_pict; + xcb_render_picture_t src_pict; }; struct aui_dri *driver; @@ -55,7 +55,7 @@ static void aui_dri_delete_rectangle(struct primitive static void aui_dri_render_rectangle(struct aui_window *, struct primitive *); static void aui_dri_set_rectangle_color(struct aui_window *, struct primitive *, struct aui_color *); static void aui_dri_set_rectangle_geometry(struct aui_window *, struct primitive *, - struct aui_geometry *); + struct aui_geometry *); static struct primitive *aui_dri_create_text(void); static void aui_dri_set_text(struct primitive *, const char *, int16_t, int16_t); @@ -63,35 +63,35 @@ static void aui_dri_render_text(struct aui_window *, s static struct aui_geometry aui_dri_get_text_geometry(struct primitive *); static struct dri_ops aui_dri_ops = { - aui_dri_create_window, - aui_dri_delete_window, - aui_dri_handle_events, - aui_dri_resize_window, - aui_dri_render_background, - aui_dri_render_foreground, + aui_dri_create_window, + aui_dri_delete_window, + aui_dri_handle_events, + aui_dri_resize_window, + aui_dri_render_background, + aui_dri_render_foreground, - aui_dri_create_rectangle, - aui_dri_delete_rectangle, - aui_dri_render_rectangle, - aui_dri_set_rectangle_color, - aui_dri_set_rectangle_geometry, + aui_dri_create_rectangle, + aui_dri_delete_rectangle, + aui_dri_render_rectangle, + aui_dri_set_rectangle_color, + aui_dri_set_rectangle_geometry, - aui_dri_create_text, - aui_dri_set_text, - aui_dri_render_text, - aui_dri_get_text_geometry + aui_dri_create_text, + aui_dri_set_text, + aui_dri_render_text, + aui_dri_get_text_geometry }; struct rectangle { - struct primitive base; - xcb_rectangle_t xrect; - xcb_render_color_t xcolor; + struct primitive base; + xcb_rectangle_t xrect; + xcb_render_color_t xcolor; }; struct text { - struct primitive base; - const char *data; /* Not allocated, pointer to string literal */ - int16_t x, y; + struct primitive base; + const char *data; /* Not allocated, pointer to string literal */ + int16_t x, y; }; static int config_xcb(struct aui_dri_xcb*); @@ -101,129 +101,129 @@ static struct aui_window_xcb *find_window_xcb(xcb_wind int xcb_driver_open(void) { - struct aui_dri_xcb *dri_xcb; + struct aui_dri_xcb *dri_xcb; - dri_xcb = malloc(sizeof(struct aui_dri_xcb)); - if (dri_xcb == NULL) - return -1; + dri_xcb = malloc(sizeof(struct aui_dri_xcb)); + if (dri_xcb == NULL) + return -1; - /* Setting up the driver */ - dri_xcb->adr.ops = &aui_dri_ops; - driver = &dri_xcb->adr; + /* Setting up the driver */ + dri_xcb->adr.ops = &aui_dri_ops; + driver = &dri_xcb->adr; - if (config_xcb(dri_xcb) == -1) - return -1; + if (config_xcb(dri_xcb) == -1) + return -1; - dri_xcb->font_height = 0; - dri_xcb->glyphs = calloc(126, sizeof(struct glyph)); - for (int i = 32; i < 127; i++) dri_xcb->glyphs[i].charcode = i; + dri_xcb->font_height = 0; + dri_xcb->glyphs = calloc(126, sizeof(struct glyph)); + for (int i = 32; i < 127; i++) dri_xcb->glyphs[i].charcode = i; - font_init(); - font_load_glyphs(dri_xcb->glyphs + 32, 127 - 32); + font_init(); + font_load_glyphs(dri_xcb->glyphs + 32, 127 - 32); - dri_xcb->glyphset = xcb_generate_id(dri_xcb->conn); - xcb_render_create_glyph_set(dri_xcb->conn, dri_xcb->glyphset, dri_xcb->fmt_alpha8); + dri_xcb->glyphset = xcb_generate_id(dri_xcb->conn); + xcb_render_create_glyph_set(dri_xcb->conn, dri_xcb->glyphset, dri_xcb->fmt_alpha8); - for (int i = 0; i < (127 - 32); i++) { - uint32_t glyphid = 32 + i; - struct glyph *g = &dri_xcb->glyphs[i + 32]; - xcb_render_glyphinfo_t ginfo = { - .width = g->width, - .height = g->height, - .x = g->x, - .y = g->y, - .x_off = g->x_offset, - .y_off = 0, /* We are only rendering horizontaly. This is unecessary */ - }; + for (int i = 0; i < (127 - 32); i++) { + uint32_t glyphid = 32 + i; + struct glyph *g = &dri_xcb->glyphs[i + 32]; + xcb_render_glyphinfo_t ginfo = { + .width = g->width, + .height = g->height, + .x = g->x, + .y = g->y, + .x_off = g->x_offset, + .y_off = 0, /* We are only rendering horizontaly. This is unecessary */ + }; - xcb_render_add_glyphs( - dri_xcb->conn, - dri_xcb->glyphset, - 1, - &glyphid, - &ginfo, - g->stride * g->height, - g->bitmap - ); + xcb_render_add_glyphs( + dri_xcb->conn, + dri_xcb->glyphset, + 1, + &glyphid, + &ginfo, + g->stride * g->height, + g->bitmap + ); - if (dri_xcb->font_height < g->y_offset) - dri_xcb->font_height = g->y_offset; - } + if (dri_xcb->font_height < g->y_offset) + 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); + 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; + return 0; } static struct aui_window *aui_dri_create_window(void) { - struct aui_window_xcb *aw_xcb; - struct aui_dri_xcb *dri_xcb; - struct aui_window *aw; + struct aui_window_xcb *aw_xcb; + struct aui_dri_xcb *dri_xcb; + struct aui_window *aw; - aw_xcb = calloc(1, sizeof(struct aui_window_xcb)); + aw_xcb = calloc(1, sizeof(struct aui_window_xcb)); - if (aw_xcb == NULL) - return NULL; + if (aw_xcb == NULL) + return NULL; - dri_xcb = (struct aui_dri_xcb*)driver; - aw = &aw_xcb->aw; + dri_xcb = (struct aui_dri_xcb*)driver; + aw = &aw_xcb->aw; - int mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK; - uint32_t values[2] = {XCB_NONE, - XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | - XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | - XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS| - XCB_EVENT_MASK_BUTTON_RELEASE}; + int mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK; + uint32_t values[2] = {XCB_NONE, + XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | + XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | + XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_BUTTON_PRESS| + XCB_EVENT_MASK_BUTTON_RELEASE}; - aw_xcb->xw = xcb_generate_id(dri_xcb->conn); - xcb_create_window(dri_xcb->conn, - XCB_COPY_FROM_PARENT, - aw_xcb->xw, - dri_xcb->screen->root, - 0, 0, - 200, 200, - 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - dri_xcb->screen->root_visual, - mask, values); + aw_xcb->xw = xcb_generate_id(dri_xcb->conn); + xcb_create_window(dri_xcb->conn, + XCB_COPY_FROM_PARENT, + aw_xcb->xw, + dri_xcb->screen->root, + 0, 0, + 200, 200, + 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + dri_xcb->screen->root_visual, + mask, values); - xcb_atom_t data[] = { dri_xcb->wm_delete_window->atom }; - xcb_change_property(dri_xcb->conn, - XCB_PROP_MODE_REPLACE, - aw_xcb->xw, - dri_xcb->wm_protocols->atom, - XCB_ATOM_ATOM, - 32, - 1, - (const void *)data); + xcb_atom_t data[] = { dri_xcb->wm_delete_window->atom }; + xcb_change_property(dri_xcb->conn, + XCB_PROP_MODE_REPLACE, + aw_xcb->xw, + dri_xcb->wm_protocols->atom, + XCB_ATOM_ATOM, + 32, + 1, + (const void *)data); - struct aui_widget *ww = (struct aui_widget *)aw; - ww->geom.width = 200; - ww->geom.height = 200; - set_pixmap_xcb(aw_xcb); - xcb_map_window(dri_xcb->conn, aw_xcb->xw); - xcb_flush(dri_xcb->conn); - return aw; + struct aui_widget *ww = (struct aui_widget *)aw; + ww->geom.width = 200; + ww->geom.height = 200; + set_pixmap_xcb(aw_xcb); + xcb_map_window(dri_xcb->conn, aw_xcb->xw); + xcb_flush(dri_xcb->conn); + return aw; } static void aui_dri_delete_window(struct aui_window *aw) { - struct aui_window_xcb *aw_xcb; - struct aui_dri_xcb *dri_xcb; + struct aui_window_xcb *aw_xcb; + struct aui_dri_xcb *dri_xcb; - dri_xcb = (struct aui_dri_xcb *)driver; - aw_xcb = (struct aui_window_xcb *)aw; + dri_xcb = (struct aui_dri_xcb *)driver; + aw_xcb = (struct aui_window_xcb *)aw; - xcb_destroy_window(dri_xcb->conn, aw_xcb->xw); - free(aw_xcb); - xcb_flush(dri_xcb->conn); + xcb_destroy_window(dri_xcb->conn, aw_xcb->xw); + free(aw_xcb); + xcb_flush(dri_xcb->conn); } /* @@ -232,239 +232,239 @@ aui_dri_delete_window(struct aui_window *aw) static void aui_dri_handle_events() { - struct aui_dri_xcb *dri_xcb; - xcb_generic_event_t *event; - struct aui_window_xcb *aw_xcb; - struct aui_window *aw; - struct aui_widget *ww; - xcb_expose_event_t *exe; - xcb_motion_notify_event_t *mne; - xcb_client_message_event_t *cme; - xcb_configure_notify_event_t *cne; - xcb_button_press_event_t *bpe; - xcb_button_release_event_t *bre; + struct aui_dri_xcb *dri_xcb; + xcb_generic_event_t *event; + struct aui_window_xcb *aw_xcb; + struct aui_window *aw; + struct aui_widget *ww; + xcb_expose_event_t *exe; + xcb_motion_notify_event_t *mne; + xcb_client_message_event_t *cme; + xcb_configure_notify_event_t *cne; + xcb_button_press_event_t *bpe; + xcb_button_release_event_t *bre; - dri_xcb = (struct aui_dri_xcb *)driver; + dri_xcb = (struct aui_dri_xcb *)driver; - int ret = poll(&dri_xcb->pollfd, 1, 10); + int ret = poll(&dri_xcb->pollfd, 1, 10); - if (ret < 0) - return; + if (ret < 0) + return; - while ((event = xcb_poll_for_event(dri_xcb->conn)) != NULL) { - switch (event->response_type & ~0x80) { - case XCB_EXPOSE: - exe = (xcb_expose_event_t *)event; - aw_xcb = find_window_xcb(exe->window); - aw = (struct aui_window *)aw_xcb; - aw->draw_flag = 1; - break; - case XCB_CLIENT_MESSAGE: - cme = (xcb_client_message_event_t *)event; - aw_xcb = find_window_xcb(cme->window); - aw = (struct aui_window *)aw_xcb; + while ((event = xcb_poll_for_event(dri_xcb->conn)) != NULL) { + switch (event->response_type & ~0x80) { + case XCB_EXPOSE: + exe = (xcb_expose_event_t *)event; + aw_xcb = find_window_xcb(exe->window); + aw = (struct aui_window *)aw_xcb; + aw->draw_flag = 1; + break; + case XCB_CLIENT_MESSAGE: + cme = (xcb_client_message_event_t *)event; + aw_xcb = find_window_xcb(cme->window); + aw = (struct aui_window *)aw_xcb; - if (cme->data.data32[0] == dri_xcb->wm_delete_window->atom) { - struct aui_event_quit qev = { - .event = { .type = AUI_EVENT_QUIT, .aw = aw }, - }; - aui_add_event(&qev.event); - } - break; - case XCB_CONFIGURE_NOTIFY: - cne = (xcb_configure_notify_event_t *)event; - aw_xcb = find_window_xcb(cne->window); - aw = (struct aui_window *)aw_xcb; - ww = (struct aui_widget *)aw; + if (cme->data.data32[0] == dri_xcb->wm_delete_window->atom) { + struct aui_event_quit qev = { + .event = { .type = AUI_EVENT_QUIT, .aw = aw }, + }; + aui_add_event(&qev.event); + } + break; + case XCB_CONFIGURE_NOTIFY: + cne = (xcb_configure_notify_event_t *)event; + aw_xcb = find_window_xcb(cne->window); + aw = (struct aui_window *)aw_xcb; + ww = (struct aui_widget *)aw; - if (ww->geom.width != cne->width || ww->geom.height != cne->height) { - struct aui_event_resize rse = { - .event = { .type = AUI_EVENT_RESIZE, .aw = aw }, - .old_w = ww->geom.width, - .old_h = ww->geom.height, - .new_w = cne->width, - .new_h = cne->height, - }; - ww->geom.width = cne->width; - ww->geom.height = cne->height; - aui_add_event(&rse.event); - aw->draw_flag = 1; - } - break; - case XCB_MOTION_NOTIFY: - mne = (xcb_motion_notify_event_t *)event; - aw_xcb = find_window_xcb(mne->event); - aw = (struct aui_window *)aw_xcb; + if (ww->geom.width != cne->width || ww->geom.height != cne->height) { + struct aui_event_resize rse = { + .event = { .type = AUI_EVENT_RESIZE, .aw = aw }, + .old_w = ww->geom.width, + .old_h = ww->geom.height, + .new_w = cne->width, + .new_h = cne->height, + }; + ww->geom.width = cne->width; + ww->geom.height = cne->height; + aui_add_event(&rse.event); + aw->draw_flag = 1; + } + break; + case XCB_MOTION_NOTIFY: + mne = (xcb_motion_notify_event_t *)event; + aw_xcb = find_window_xcb(mne->event); + aw = (struct aui_window *)aw_xcb; - struct aui_event_mouse_motion mev = { - .event = { .type = AUI_EVENT_MOUSE_MOTION, .aw = aw }, - .x = mne->event_x, .y = mne->event_y - }; - aui_add_event(&mev.event); - break; - case XCB_BUTTON_PRESS: - bpe = (xcb_button_press_event_t *)event; - aw_xcb = find_window_xcb(bpe->event); - aw = (struct aui_window *)aw_xcb; + struct aui_event_mouse_motion mev = { + .event = { .type = AUI_EVENT_MOUSE_MOTION, .aw = aw }, + .x = mne->event_x, .y = mne->event_y + }; + aui_add_event(&mev.event); + break; + case XCB_BUTTON_PRESS: + bpe = (xcb_button_press_event_t *)event; + aw_xcb = find_window_xcb(bpe->event); + aw = (struct aui_window *)aw_xcb; - struct aui_event_mouse_press mpe = { - .event = { .type = AUI_EVENT_MOUSE_PRESS, .aw = aw }, - .x = bpe->event_x, .y = bpe->event_y, .button = bpe->detail - }; - aui_add_event(&mpe.event); - break; - case XCB_BUTTON_RELEASE: - bre = (xcb_button_release_event_t *)event; - aw_xcb = find_window_xcb(bre->event); - aw = (struct aui_window *)aw_xcb; + struct aui_event_mouse_press mpe = { + .event = { .type = AUI_EVENT_MOUSE_PRESS, .aw = aw }, + .x = bpe->event_x, .y = bpe->event_y, .button = bpe->detail + }; + aui_add_event(&mpe.event); + break; + case XCB_BUTTON_RELEASE: + bre = (xcb_button_release_event_t *)event; + aw_xcb = find_window_xcb(bre->event); + aw = (struct aui_window *)aw_xcb; - struct aui_event_mouse_release mre = { - .event = { .type = AUI_EVENT_MOUSE_RELEASE, .aw = aw }, - .x = bre->event_x, .y = bre->event_y, .button = bre->detail - }; - aui_add_event(&mre.event); - break; - default: - break; - } - free(event); - } + struct aui_event_mouse_release mre = { + .event = { .type = AUI_EVENT_MOUSE_RELEASE, .aw = aw }, + .x = bre->event_x, .y = bre->event_y, .button = bre->detail + }; + aui_add_event(&mre.event); + break; + default: + break; + } + free(event); + } } static void aui_dri_resize_window(struct aui_window *aw) { - set_pixmap_xcb((struct aui_window_xcb *)aw); - aw->draw_flag = 1; + set_pixmap_xcb((struct aui_window_xcb *)aw); + aw->draw_flag = 1; } static void aui_dri_render_background(struct aui_window *aw) { - xcb_render_color_t color = { .red = 0xd9d9, .green = 0xd9d9, .blue = 0xd9d9, .alpha = 0xffff }; - struct aui_widget *ww = (struct aui_widget *)aw; - xcb_rectangle_t rects[] = { { .x = 0, .y = 0, .width = ww->geom.width, - .height = ww->geom.height } }; - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; + xcb_render_color_t color = { .red = 0xd9d9, .green = 0xd9d9, .blue = 0xd9d9, .alpha = 0xffff }; + struct aui_widget *ww = (struct aui_widget *)aw; + xcb_rectangle_t rects[] = { { .x = 0, .y = 0, .width = ww->geom.width, + .height = ww->geom.height } }; + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; - xcb_render_fill_rectangles(dri_xcb->conn, - XCB_RENDER_PICT_OP_OVER, - aw_xcb->src_pict, - color, - 1, - rects); + xcb_render_fill_rectangles(dri_xcb->conn, + XCB_RENDER_PICT_OP_OVER, + aw_xcb->src_pict, + color, + 1, + rects); } static void aui_dri_render_foreground(struct aui_window *aw) { - struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct aui_widget *ww = (struct aui_widget *)aw; + struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct aui_widget *ww = (struct aui_widget *)aw; - xcb_render_composite(dri_xcb->conn, - XCB_RENDER_PICT_OP_OVER, - aw_xcb->src_pict, - XCB_NONE, - aw_xcb->dst_pict, - 0, 0, 0, 0, 0, 0, - ww->geom.width, ww->geom.height); + xcb_render_composite(dri_xcb->conn, + XCB_RENDER_PICT_OP_OVER, + aw_xcb->src_pict, + XCB_NONE, + aw_xcb->dst_pict, + 0, 0, 0, 0, 0, 0, + ww->geom.width, ww->geom.height); - xcb_flush(dri_xcb->conn); + xcb_flush(dri_xcb->conn); } static struct primitive* aui_dri_create_rectangle() { - struct rectangle *rect = calloc(1, sizeof(struct rectangle)); + struct rectangle *rect = calloc(1, sizeof(struct rectangle)); - rect->base.type = PRIMITIVE_TYPE_RECTANGLE; - rect->xrect.x = 0; - rect->xrect.y = 0; - rect->xrect.width = 0; - rect->xrect.height = 0; + rect->base.type = PRIMITIVE_TYPE_RECTANGLE; + rect->xrect.x = 0; + rect->xrect.y = 0; + rect->xrect.width = 0; + rect->xrect.height = 0; - rect->xcolor.red = 0; - rect->xcolor.green = 0; - rect->xcolor.blue = 0; - rect->xcolor.alpha = 0; + rect->xcolor.red = 0; + rect->xcolor.green = 0; + rect->xcolor.blue = 0; + rect->xcolor.alpha = 0; - return &(rect)->base; + return &(rect)->base; } static void aui_dri_delete_rectangle(struct primitive *prim) { - struct rectangle *rect = (struct rectangle *)prim; - free(rect); + struct rectangle *rect = (struct rectangle *)prim; + free(rect); } static void aui_dri_render_rectangle(struct aui_window *aw, struct primitive *prim) { - struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct rectangle *rect = (struct rectangle *)prim; + struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct rectangle *rect = (struct rectangle *)prim; - if (prim->type != PRIMITIVE_TYPE_RECTANGLE) { - fprintf(stderr, "libaui: attempt to render rectangle with mismatching type.\n"); - return; - } + if (prim->type != PRIMITIVE_TYPE_RECTANGLE) { + fprintf(stderr, "libaui: attempt to render rectangle with mismatching type.\n"); + return; + } - xcb_render_fill_rectangles(dri_xcb->conn, - XCB_RENDER_PICT_OP_OVER, - aw_xcb->src_pict, - rect->xcolor, - 1, - &rect->xrect); + xcb_render_fill_rectangles(dri_xcb->conn, + XCB_RENDER_PICT_OP_OVER, + aw_xcb->src_pict, + rect->xcolor, + 1, + &rect->xrect); } static void aui_dri_set_rectangle_color(struct aui_window *aw, struct primitive *prim, struct aui_color *color) { - struct rectangle *rect = (struct rectangle *)prim; + struct rectangle *rect = (struct rectangle *)prim; - if (prim->type != PRIMITIVE_TYPE_RECTANGLE) { - fprintf(stderr, "libaui: attempt to set_rectangle_color for mismatching type\n"); - return; - } + if (prim->type != PRIMITIVE_TYPE_RECTANGLE) { + fprintf(stderr, "libaui: attempt to set_rectangle_color for mismatching type\n"); + return; + } - rect->xcolor.red = (color->red * 0xFFFF) / 0xFF; - rect->xcolor.green = (color->green * 0xFFFF) / 0xFF; - rect->xcolor.blue = (color->blue * 0xFFFF) / 0xFF; - rect->xcolor.alpha = (color->alpha * 0xFFFF) / 0xFF; + rect->xcolor.red = (color->red * 0xFFFF) / 0xFF; + rect->xcolor.green = (color->green * 0xFFFF) / 0xFF; + rect->xcolor.blue = (color->blue * 0xFFFF) / 0xFF; + rect->xcolor.alpha = (color->alpha * 0xFFFF) / 0xFF; - aw->draw_flag = 1; + aw->draw_flag = 1; } static void aui_dri_set_rectangle_geometry(struct aui_window *aw, struct primitive *prim, - struct aui_geometry *geom) + struct aui_geometry *geom) { - struct rectangle *rect = (struct rectangle *)prim; + struct rectangle *rect = (struct rectangle *)prim; - rect->xrect.x = geom->x; - rect->xrect.y = geom->y; - rect->xrect.width = geom->width; - rect->xrect.height = geom->height; + rect->xrect.x = geom->x; + rect->xrect.y = geom->y; + rect->xrect.width = geom->width; + rect->xrect.height = geom->height; } static struct primitive* aui_dri_create_text() { - struct text *t = calloc(1, sizeof(struct text)); - return &(t)->base; + struct text *t = calloc(1, sizeof(struct text)); + return &(t)->base; } static void aui_dri_set_text(struct primitive *p, const char *data, int16_t x, int16_t y) { - struct text *t = (struct text *)p; - t->base.type = PRIMITIVE_TYPE_TEXT; - t->data = data; - t->x = x; - t->y = y; + struct text *t = (struct text *)p; + t->base.type = PRIMITIVE_TYPE_TEXT; + t->data = data; + t->x = x; + t->y = y; } /* @@ -472,79 +472,79 @@ aui_dri_set_text(struct primitive *p, const char *data * xcb_render_composite_glyphs_8 function which expects an 8 bytes header * where. Can only be up to 255 characters: * - * byte0=> len + * byte0=> len * byte1-3=> padding * byte4-5=> dx * byte6-7=> dy */ struct ghead { - uint8_t len; - uint8_t pad[3]; - int16_t dx; - int16_t dy; + uint8_t len; + uint8_t pad[3]; + int16_t dx; + int16_t dy; }; static void aui_dri_render_text(struct aui_window *aw, struct primitive *p) { - struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct text *t = (struct text *)p; + struct aui_window_xcb *aw_xcb = (struct aui_window_xcb *)aw; + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct text *t = (struct text *)p; - size_t len = (t->data == NULL) ? 0 : strlen(t->data); - struct ghead cmd = { .len = len, .dx = t->x, .dy = t->y }; + size_t len = (t->data == NULL) ? 0 : strlen(t->data); + struct ghead cmd = { .len = len, .dx = t->x, .dy = t->y }; - size_t cmd_len = len + 8; - uint8_t *glyphcmds = malloc(cmd_len); + size_t cmd_len = len + 8; + uint8_t *glyphcmds = malloc(cmd_len); - if (glyphcmds == NULL) - return; + if (glyphcmds == NULL) + return; - glyphcmds[0] = cmd.len; - glyphcmds[1] = 0; - glyphcmds[2] = 0; - glyphcmds[3] = 0; + glyphcmds[0] = cmd.len; + glyphcmds[1] = 0; + glyphcmds[2] = 0; + glyphcmds[3] = 0; - memcpy(&glyphcmds[4], &cmd.dx, 2); - memcpy(&glyphcmds[6], &cmd.dy, 2); + memcpy(&glyphcmds[4], &cmd.dx, 2); + memcpy(&glyphcmds[6], &cmd.dy, 2); - memcpy(glyphcmds + 8, t->data, len); + memcpy(glyphcmds + 8, t->data, len); - xcb_render_composite_glyphs_8( - dri_xcb->conn, - XCB_RENDER_PICT_OP_OVER, - dri_xcb->glyphpic, - aw_xcb->src_pict, - 0, - dri_xcb->glyphset, - 0, 0, - cmd_len, - glyphcmds); + xcb_render_composite_glyphs_8( + dri_xcb->conn, + XCB_RENDER_PICT_OP_OVER, + dri_xcb->glyphpic, + aw_xcb->src_pict, + 0, + dri_xcb->glyphset, + 0, 0, + cmd_len, + glyphcmds); - free(glyphcmds); + free(glyphcmds); } static struct aui_geometry aui_dri_get_text_geometry(struct primitive *p) { - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct aui_geometry geom = { 0 }; - struct text *t = (struct text *)p; - size_t len = (t->data == NULL) ? 0 : strlen(t->data); + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct aui_geometry geom = { 0 }; + struct text *t = (struct text *)p; + size_t len = (t->data == NULL) ? 0 : strlen(t->data); - for (int i = 0; i < len; i++) { - uint32_t glyphid = (uint32_t)t->data[i]; - if (glyphid < 32 || glyphid > 126) { - fprintf(stderr, "libaui: unknown geometry for glyph id: %d\n", glyphid); - continue; - } + for (int i = 0; i < len; i++) { + uint32_t glyphid = (uint32_t)t->data[i]; + if (glyphid < 32 || glyphid > 126) { + fprintf(stderr, "libaui: unknown geometry for glyph id: %d\n", glyphid); + continue; + } - struct glyph *g = &dri_xcb->glyphs[glyphid]; - geom.width += g->x_offset; - } - geom.height = dri_xcb->font_height; + struct glyph *g = &dri_xcb->glyphs[glyphid]; + geom.width += g->x_offset; + } + geom.height = dri_xcb->font_height; - return geom; + return geom; } /* @@ -556,99 +556,99 @@ aui_dri_get_text_geometry(struct primitive *p) static int config_xcb(struct aui_dri_xcb *axcb) { - xcb_intern_atom_cookie_t cookies[2]; + xcb_intern_atom_cookie_t cookies[2]; - axcb->conn = xcb_connect(NULL, NULL); + axcb->conn = xcb_connect(NULL, NULL); - if (axcb->conn == NULL) - return -1; + if (axcb->conn == NULL) + return -1; - axcb->screen = xcb_setup_roots_iterator(xcb_get_setup(axcb->conn)).data; + axcb->screen = xcb_setup_roots_iterator(xcb_get_setup(axcb->conn)).data; - if (axcb->screen == NULL) - return -1; + if (axcb->screen == NULL) + return -1; - axcb->pollfd.fd = xcb_get_file_descriptor(axcb->conn); - axcb->pollfd.events = POLLIN; + axcb->pollfd.fd = xcb_get_file_descriptor(axcb->conn); + axcb->pollfd.events = POLLIN; - /* - * Prevents auto delete - */ - cookies[0] = xcb_intern_atom(axcb->conn, 1, strlen("WM_PROTOCOLS"), "WM_PROTOCOLS"); - axcb->wm_protocols = xcb_intern_atom_reply(axcb->conn, cookies[0], NULL); + /* + * Prevents auto delete + */ + cookies[0] = xcb_intern_atom(axcb->conn, 1, strlen("WM_PROTOCOLS"), "WM_PROTOCOLS"); + axcb->wm_protocols = xcb_intern_atom_reply(axcb->conn, cookies[0], NULL); - cookies[1] = xcb_intern_atom(axcb->conn, 1, strlen("WM_DELETE_WINDOW"), "WM_DELETE_WINDOW"); - axcb->wm_delete_window = xcb_intern_atom_reply(axcb->conn, cookies[1], NULL); + cookies[1] = xcb_intern_atom(axcb->conn, 1, strlen("WM_DELETE_WINDOW"), "WM_DELETE_WINDOW"); + axcb->wm_delete_window = xcb_intern_atom_reply(axcb->conn, cookies[1], NULL); - /* - * XCB Render - */ - xcb_render_query_pict_formats_cookie_t rcookie = xcb_render_query_pict_formats(axcb->conn); - xcb_render_query_pict_formats_reply_t *rreply; - xcb_render_pictscreen_iterator_t rpiter; + /* + * XCB Render + */ + xcb_render_query_pict_formats_cookie_t rcookie = xcb_render_query_pict_formats(axcb->conn); + xcb_render_query_pict_formats_reply_t *rreply; + xcb_render_pictscreen_iterator_t rpiter; - rreply = xcb_render_query_pict_formats_reply(axcb->conn, rcookie, NULL); - rpiter = xcb_render_query_pict_formats_screens_iterator(rreply); + rreply = xcb_render_query_pict_formats_reply(axcb->conn, rcookie, NULL); + rpiter = xcb_render_query_pict_formats_screens_iterator(rreply); - /* - * This is `NORMAL` format - */ - while (rpiter.rem != 0) { - xcb_render_pictdepth_iterator_t rditer; - rditer = xcb_render_pictscreen_depths_iterator(rpiter.data); + /* + * This is `NORMAL` format + */ + while (rpiter.rem != 0) { + xcb_render_pictdepth_iterator_t rditer; + rditer = xcb_render_pictscreen_depths_iterator(rpiter.data); - while (rditer.rem != 0) { - xcb_render_pictvisual_iterator_t rviter; - rviter = xcb_render_pictdepth_visuals_iterator(rditer.data); + while (rditer.rem != 0) { + xcb_render_pictvisual_iterator_t rviter; + rviter = xcb_render_pictdepth_visuals_iterator(rditer.data); - while (rviter.rem != 0) { - if (rviter.data->visual == axcb->screen->root_visual) - axcb->fmt_normal = rviter.data->format; - xcb_render_pictvisual_next(&rviter); - } - xcb_render_pictdepth_next(&rditer); - } - xcb_render_pictscreen_next(&rpiter); - } + while (rviter.rem != 0) { + if (rviter.data->visual == axcb->screen->root_visual) + axcb->fmt_normal = rviter.data->format; + xcb_render_pictvisual_next(&rviter); + } + xcb_render_pictdepth_next(&rditer); + } + xcb_render_pictscreen_next(&rpiter); + } - /* - * Formats for `ARGB32` and `ALPHA8` - */ - xcb_render_pictforminfo_iterator_t rfiter; - rfiter = xcb_render_query_pict_formats_formats_iterator(rreply); + /* + * Formats for `ARGB32` and `ALPHA8` + */ + xcb_render_pictforminfo_iterator_t rfiter; + rfiter = xcb_render_query_pict_formats_formats_iterator(rreply); - while (rfiter.rem != 0) { - xcb_render_pictforminfo_t *info = rfiter.data; + while (rfiter.rem != 0) { + xcb_render_pictforminfo_t *info = rfiter.data; - if (info->type == XCB_RENDER_PICT_TYPE_DIRECT && - info->depth == 32 && - info->direct.red_shift == 16 && - info->direct.red_mask == 0xff && - info->direct.green_shift == 8 && - info->direct.green_mask == 0xff && - info->direct.blue_shift == 0 && - info->direct.blue_mask == 0xff && - info->direct.alpha_shift == 24 && - info->direct.alpha_mask == 0xff) - axcb->fmt_argb32 = rfiter.data->id; + if (info->type == XCB_RENDER_PICT_TYPE_DIRECT && + info->depth == 32 && + info->direct.red_shift == 16 && + info->direct.red_mask == 0xff && + info->direct.green_shift == 8 && + info->direct.green_mask == 0xff && + info->direct.blue_shift == 0 && + info->direct.blue_mask == 0xff && + info->direct.alpha_shift == 24 && + info->direct.alpha_mask == 0xff) + axcb->fmt_argb32 = rfiter.data->id; - if (info->type == XCB_RENDER_PICT_TYPE_DIRECT && - info->depth == 8 && - info->direct.red_shift == 0 && - info->direct.red_mask == 0x00 && - info->direct.green_shift == 0 && - info->direct.green_mask == 0x00 && - info->direct.blue_shift == 0 && - info->direct.blue_mask == 0x00 && - info->direct.alpha_shift == 0 && - info->direct.alpha_mask == 0xff) - axcb->fmt_alpha8 = rfiter.data->id; - xcb_render_pictforminfo_next(&rfiter); - } + if (info->type == XCB_RENDER_PICT_TYPE_DIRECT && + info->depth == 8 && + info->direct.red_shift == 0 && + info->direct.red_mask == 0x00 && + info->direct.green_shift == 0 && + info->direct.green_mask == 0x00 && + info->direct.blue_shift == 0 && + info->direct.blue_mask == 0x00 && + info->direct.alpha_shift == 0 && + info->direct.alpha_mask == 0xff) + axcb->fmt_alpha8 = rfiter.data->id; + xcb_render_pictforminfo_next(&rfiter); + } - free(rreply); + free(rreply); - return 0; + return 0; } /* @@ -658,50 +658,50 @@ config_xcb(struct aui_dri_xcb *axcb) static void set_pixmap_xcb(struct aui_window_xcb *aw_xcb) { - struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; - struct aui_window *aw = (struct aui_window *)aw_xcb; - struct aui_widget *ww = (struct aui_widget *)aw; + struct aui_dri_xcb *dri_xcb = (struct aui_dri_xcb *)driver; + struct aui_window *aw = (struct aui_window *)aw_xcb; + struct aui_widget *ww = (struct aui_widget *)aw; - xcb_render_free_picture(dri_xcb->conn, aw_xcb->dst_pict); - xcb_render_free_picture(dri_xcb->conn, aw_xcb->src_pict); - xcb_free_pixmap(dri_xcb->conn, aw_xcb->pixmap); + xcb_render_free_picture(dri_xcb->conn, aw_xcb->dst_pict); + xcb_render_free_picture(dri_xcb->conn, aw_xcb->src_pict); + xcb_free_pixmap(dri_xcb->conn, aw_xcb->pixmap); - aw_xcb->pixmap = xcb_generate_id(dri_xcb->conn); - xcb_create_pixmap(dri_xcb->conn, - 32, - aw_xcb->pixmap, - aw_xcb->xw, - ww->geom.width, - ww->geom.height); + aw_xcb->pixmap = xcb_generate_id(dri_xcb->conn); + xcb_create_pixmap(dri_xcb->conn, + 32, + aw_xcb->pixmap, + aw_xcb->xw, + ww->geom.width, + ww->geom.height); - aw_xcb->src_pict = xcb_generate_id(dri_xcb->conn); - xcb_render_create_picture(dri_xcb->conn, - aw_xcb->src_pict, - aw_xcb->pixmap, - dri_xcb->fmt_argb32, - 0, - NULL); + aw_xcb->src_pict = xcb_generate_id(dri_xcb->conn); + xcb_render_create_picture(dri_xcb->conn, + aw_xcb->src_pict, + aw_xcb->pixmap, + dri_xcb->fmt_argb32, + 0, + NULL); - aw_xcb->dst_pict = xcb_generate_id(dri_xcb->conn); - xcb_render_create_picture(dri_xcb->conn, - aw_xcb->dst_pict, - aw_xcb->xw, - dri_xcb->fmt_normal, - 0, - NULL); + aw_xcb->dst_pict = xcb_generate_id(dri_xcb->conn); + xcb_render_create_picture(dri_xcb->conn, + aw_xcb->dst_pict, + aw_xcb->xw, + dri_xcb->fmt_normal, + 0, + NULL); } static struct aui_window_xcb* find_window_xcb(xcb_window_t xw) { - struct aui_window_xcb *aw_xcb; - struct aui_window *aw; + struct aui_window_xcb *aw_xcb; + struct aui_window *aw; - LIST_FOREACH(aw, &wlist, entries) { - aw_xcb = (struct aui_window_xcb *)aw; - if (aw_xcb->xw == xw) - return aw_xcb; - } + LIST_FOREACH(aw, &wlist, entries) { + aw_xcb = (struct aui_window_xcb *)aw; + if (aw_xcb->xw == xw) + return aw_xcb; + } - return NULL; + return NULL; }