diff --git a/src/ctxt/ctxt.c b/src/ctxt/ctxt.c index ee06ed0..c0d059d 100644 --- a/src/ctxt/ctxt.c +++ b/src/ctxt/ctxt.c @@ -109,20 +109,26 @@ void ax_begin_theme(struct ax_ctxt* ax) struct ax_theme* ax_end_theme(struct ax_ctxt* ax) { - ASSERT(ax->thmb != NULL, "`ax_end_theme' called while not building a theme"); - - struct ax_theme* thm = ax__theme_builder_finish(ax->thmb, ax->init_rgn); + if (ax->thmb == NULL) { + ax_log(ax, "`ax_end_theme' called while not building a theme"); + return NULL; + } + struct ax_theme* thm = ax__theme_builder_finish( + ax->thmb, + ax->init_rgn, + ax__backend_msgq(ax->bac)); ax->thmb = NULL; rgn_clear(ax->thmb_rgn); - - ax__theme_load(thm, ax__backend_msgq(ax->bac)); return thm; } void ax_set_theme_color( struct ax_ctxt* ax, const char* cat_name, int64_t rgb) { - ASSERT(ax->thmb != NULL, "`ax_set_theme_color' called while not building a theme"); + if (ax->thmb == NULL) { + ax_log(ax, "`ax_set_theme_color' called while not building a theme"); + return; + } enum ax_color_cat cat; if (ax__string_to_color_cat(cat_name, &cat) != 0) { ax->thmb->err = @@ -135,7 +141,10 @@ void ax_set_theme_color( void ax_set_theme_font( struct ax_ctxt* ax, const char* cat_name, const char* fnt_path, size_t fnt_size) { - ASSERT(ax->thmb != NULL, "`ax_set_theme_font' called while not building a theme"); + if (ax->thmb == NULL) { + ax_log(ax, "`ax_set_theme_font' called while not building a theme"); + return; + } enum ax_font_cat cat; if (ax__string_to_font_cat(cat_name, &cat) != 0) { ax->thmb->err = @@ -148,7 +157,10 @@ void ax_set_theme_font( void ax_set_theme_iconset( struct ax_ctxt* ax, const char* iconset_dir) { - ASSERT(ax->thmb != NULL, "`ax_set_theme_iconset' called while not building a theme"); + if (ax->thmb == NULL) { + ax_log(ax, "`ax_set_theme_iconset' called while not building a theme"); + return; + } UNIMPLEMENTED(); } @@ -159,7 +171,10 @@ void ax_theme_wait_until_loaded(struct ax_ctxt* ax, struct ax_theme* thm) struct msgq* mq = msgq_new(rgn); ax__theme_on_load(thm, mq); msgq_begin_recv_and_wait(mq); - MSGQ_RECV_ALL(mq) {} + MSGQ_RECV_ALL(mq) { + default: + break; + } msgq_end_recv(mq); rgn_cleanup(rgn); } diff --git a/src/ctxt/theme.c b/src/ctxt/theme.c index 8c119ec..b219e2f 100644 --- a/src/ctxt/theme.c +++ b/src/ctxt/theme.c @@ -79,7 +79,8 @@ void ax__theme_set_font( struct ax_theme* ax__theme_builder_finish( struct ax_theme_builder* thmb, - struct rgn* dst_rgn) + struct rgn* dst_rgn, + struct msgq* req_to_load_mq) { struct ax_theme* thm = ralloc_typed(dst_rgn, struct ax_theme, 1); if (thmb->err != NULL) { @@ -99,6 +100,15 @@ struct ax_theme* ax__theme_builder_finish( thm->on_load = NULL; pthread_mutex_init(&thm->mx, NULL); rgn_pin(dst_rgn, thm, (void*) pthread_mutex_destroy); + + for (size_t i = 0; i < AX_FONT__COUNT; i++) { + struct ax_msg_load_font* m = + msgq_begin_send_typed(req_to_load_mq, ax_msg_load_font); + m->theme = thm; + m->category = i; + msgq_end_send(req_to_load_mq); + } + return thm; } @@ -157,16 +167,6 @@ void ax__theme_set_font_handle( pthread_mutex_unlock(&thm->mx); } -void ax__theme_load(struct ax_theme* thm, struct msgq* req_mq) -{ - for (size_t i = 0; i < AX_FONT__COUNT; i++) { - struct ax_msg_load_font* m = msgq_begin_send_typed(req_mq, ax_msg_load_font); - m->theme = thm; - m->category = i; - msgq_end_send(req_mq); - } -} - void ax__theme_on_load(struct ax_theme* thm, struct msgq* res_mq) { pthread_mutex_lock(&thm->mx); diff --git a/src/ctxt/theme.h b/src/ctxt/theme.h index f4ad927..6fb6668 100644 --- a/src/ctxt/theme.h +++ b/src/ctxt/theme.h @@ -8,6 +8,7 @@ struct rgn; struct msgq; struct msgq_list; +struct ax_font_h; #define THEME_BUILDER_DESIRED_REGION_SIZE (16*1024) @@ -36,8 +37,6 @@ enum ax_font_cat { AX_FONT__DEFAULT, }; -struct ax_font_h; // defined by backend - struct ax_theme { const char* err; int64_t color[AX_COLOR__COUNT]; @@ -75,7 +74,8 @@ void ax__theme_set_font( struct ax_theme* ax__theme_builder_finish( struct ax_theme_builder* thmb, - struct rgn* dst_rgn); + struct rgn* dst_rgn, + struct msgq* req_to_load_mq); static inline int64_t ax__theme_color( struct ax_theme* thm, @@ -107,10 +107,6 @@ void ax__theme_set_font_handle( enum ax_font_cat i, struct ax_font_h* h); -void ax__theme_load( - struct ax_theme* thm, - struct msgq* req_mq); - void ax__theme_on_load( struct ax_theme* thm, struct msgq* res_mq);