From e2dbd9b4951261b6126724360f705dbf7ff6b771 Mon Sep 17 00:00:00 2001 From: Simon Long Date: Wed, 6 Dec 2023 08:58:24 +0000 Subject: [PATCH] Allow both max_toggled_hover and max_hover_toggled names for icon --- include/button/button-xbm.h | 4 ++-- src/button/button-xbm.c | 16 +++++++++++-- src/theme.c | 45 +++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/include/button/button-xbm.h b/include/button/button-xbm.h index 862a926d..8b864bd0 100644 --- a/include/button/button-xbm.h +++ b/include/button/button-xbm.h @@ -5,7 +5,7 @@ struct lab_data_buffer; /* button_xbm_load - Convert xbm file to buffer with cairo surface */ -void button_xbm_load(const char *button_name, struct lab_data_buffer **buffer, - char *fallback_button, float *rgba); +void button_xbm_load(const char *button_name, const char *alt_name, + struct lab_data_buffer **buffer, char *fallback_button, float *rgba); #endif /* LABWC_BUTTON_XBM_H */ diff --git a/src/button/button-xbm.c b/src/button/button-xbm.c index 9d558332..6435d654 100644 --- a/src/button/button-xbm.c +++ b/src/button/button-xbm.c @@ -259,8 +259,8 @@ parse_xbm_builtin(const char *button, int size) } void -button_xbm_load(const char *button_name, struct lab_data_buffer **buffer, - char *fallback_button, float *rgba) +button_xbm_load(const char *button_name, const char *alt_name, + struct lab_data_buffer **buffer, char *fallback_button, float *rgba) { struct pixmap pixmap = {0}; if (*buffer) { @@ -282,6 +282,18 @@ button_xbm_load(const char *button_name, struct lab_data_buffer **buffer, free(tokens); } } + if (!pixmap.data && *alt_name) { + button_filename(alt_name, filename, sizeof(filename)); + char *token_buffer = grab_file(filename); + if (token_buffer) { + struct token *tokens = tokenize_xbm(token_buffer); + free(token_buffer); + pixmap = parse_xbm_tokens(tokens); + if (tokens) { + free(tokens); + } + } + } if (!pixmap.data) { pixmap = parse_xbm_builtin(fallback_button, 6); } diff --git a/src/theme.c b/src/theme.c index b4c37f0b..1df54389 100644 --- a/src/theme.c +++ b/src/theme.c @@ -39,6 +39,7 @@ struct button { const char *name; + const char *alt_name; char fallback_button[6]; /* built-in 6x6 button */ struct { struct lab_data_buffer **buffer; @@ -60,7 +61,7 @@ load_buttons(struct theme *theme) { struct button buttons[] = { { - "menu", + "menu", NULL, { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 }, { &theme->button_menu_active_unpressed, @@ -72,7 +73,7 @@ load_buttons(struct theme *theme) }, }, { - "iconify", + "iconify", NULL, { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f }, { &theme->button_iconify_active_unpressed, @@ -84,7 +85,7 @@ load_buttons(struct theme *theme) }, }, { - "max", + "max", NULL, { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f }, { &theme->button_maximize_active_unpressed, @@ -96,7 +97,7 @@ load_buttons(struct theme *theme) }, }, { - "max_toggled", + "max_toggled", NULL, { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f }, { &theme->button_restore_active_unpressed, @@ -108,7 +109,7 @@ load_buttons(struct theme *theme) }, }, { - "close", + "close", NULL, { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 }, { &theme->button_close_active_unpressed, @@ -120,7 +121,7 @@ load_buttons(struct theme *theme) }, }, { - "menu_hover", + "menu_hover", NULL, { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 }, { &theme->button_menu_active_hover, @@ -132,7 +133,7 @@ load_buttons(struct theme *theme) }, }, { - "iconify_hover", + "iconify_hover", NULL, { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f }, { &theme->button_iconify_active_hover, @@ -144,7 +145,7 @@ load_buttons(struct theme *theme) }, }, { - "max_hover", + "max_hover", NULL, { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f }, { &theme->button_maximize_active_hover, @@ -156,7 +157,7 @@ load_buttons(struct theme *theme) }, }, { - "max_hover_toggled", + "max_hover_toggled", "max_toggled_hover", { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f }, { &theme->button_restore_active_hover, @@ -168,7 +169,7 @@ load_buttons(struct theme *theme) }, }, { - "close_hover", + "close_hover", NULL, { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 }, { &theme->button_close_active_hover, @@ -182,6 +183,7 @@ load_buttons(struct theme *theme) }; char filename[4096] = {0}; + char alt_filename[4096] = {0}; for (size_t i = 0; i < ARRAY_SIZE(buttons); ++i) { struct button *b = &buttons[i]; @@ -191,8 +193,16 @@ load_buttons(struct theme *theme) /* Try png icon first */ snprintf(filename, sizeof(filename), "%s-active.png", b->name); button_png_load(filename, b->active.buffer); + if (!*b->active.buffer && b->alt_name) { + snprintf(filename, sizeof(filename), "%s-active.png", b->alt_name); + button_png_load(filename, b->active.buffer); + } snprintf(filename, sizeof(filename), "%s-inactive.png", b->name); button_png_load(filename, b->inactive.buffer); + if (!*b->inactive.buffer && b->alt_name) { + snprintf(filename, sizeof(filename), "%s-inactive.png", b->alt_name); + button_png_load(filename, b->inactive.buffer); + } #if HAVE_RSVG /* Then try svg icon */ @@ -201,20 +211,31 @@ load_buttons(struct theme *theme) snprintf(filename, sizeof(filename), "%s-active.svg", b->name); button_svg_load(filename, b->active.buffer, size); } + if (!*b->active.buffer && b->alt_name) { + snprintf(filename, sizeof(filename), "%s-active.svg", b->alt_name); + button_svg_load(filename, b->active.buffer, size); + } if (!*b->inactive.buffer) { snprintf(filename, sizeof(filename), "%s-inactive.svg", b->name); button_svg_load(filename, b->inactive.buffer, size); } + if (!*b->active.buffer && b->alt_name) { + snprintf(filename, sizeof(filename), "%s-inactive.svg", b->alt_name); + button_svg_load(filename, b->inactive.buffer, size); + } #endif /* If there were no png/svg buttons, use xbm */ snprintf(filename, sizeof(filename), "%s.xbm", b->name); + if (b->alt_name) { + snprintf(alt_filename, sizeof(alt_filename), "%s.xbm", b->alt_name); + } if (!*b->active.buffer) { - button_xbm_load(filename, b->active.buffer, + button_xbm_load(filename, alt_filename, b->active.buffer, b->fallback_button, b->active.rgba); } if (!*b->inactive.buffer) { - button_xbm_load(filename, b->inactive.buffer, + button_xbm_load(filename, alt_filename, b->inactive.buffer, b->fallback_button, b->inactive.rgba); } }