From 5ea1527558d19d1f450868de116a85f6be1d421a Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 11 Aug 2020 21:45:52 +0100 Subject: [PATCH] xbm: parse_xbm_builtin() remove hard-coded values --- include/theme/xbm/parse.h | 2 +- src/theme/xbm/parse.c | 21 +++++++++++++-------- src/theme/xbm/xbm.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/theme/xbm/parse.h b/include/theme/xbm/parse.h index bd9e0652..bd09d8d9 100644 --- a/include/theme/xbm/parse.h +++ b/include/theme/xbm/parse.h @@ -26,6 +26,6 @@ struct pixmap parse_xbm_tokens(struct token *tokens); * parse_xbm_builtin - parse builtin xbm button and create pixmap * @button: button byte array (xbm format) */ -struct pixmap parse_xbm_builtin(const char *button); +struct pixmap parse_xbm_builtin(const char *button, int size); #endif /* __LABWC_PARSE_H */ diff --git a/src/theme/xbm/parse.c b/src/theme/xbm/parse.c index c395fbf0..a85f0ae4 100644 --- a/src/theme/xbm/parse.c +++ b/src/theme/xbm/parse.c @@ -12,6 +12,7 @@ #include #include "theme/xbm/parse.h" +#include "common/bug-on.h" /* TODO: should be window.active.button.unpressed.image.color */ static unsigned char defaultcolor[] = { 255, 255, 255, 255 }; @@ -71,21 +72,25 @@ out: return pixmap; } -/* Assuming a 6x6 button for the time being */ -/* TODO: pass width, height, vargs bytes */ -struct pixmap parse_xbm_builtin(const char *button) +/* + * Openbox built-in icons are not bigger than 8x8, so have only written this + * function to cope wit that max size + */ +#define LABWC_BUILTIN_ICON_MAX_SIZE (8) +struct pixmap parse_xbm_builtin(const char *button, int size) { struct pixmap pixmap = { 0 }; - pixmap.width = 6; - pixmap.height = 6; + BUG_ON(size > LABWC_BUILTIN_ICON_MAX_SIZE); + pixmap.width = size; + pixmap.height = size; - struct token t[7]; - for (int i = 0; i < 6; i++) { + struct token t[LABWC_BUILTIN_ICON_MAX_SIZE + 1]; + for (int i = 0; i < size; i++) { t[i].value = button[i]; t[i].type = TOKEN_INT; } - t[6].type = 0; + t[size].type = 0; process_bytes(&pixmap, t); return pixmap; } diff --git a/src/theme/xbm/xbm.c b/src/theme/xbm/xbm.c index 20ef210f..6ad0d1eb 100644 --- a/src/theme/xbm/xbm.c +++ b/src/theme/xbm/xbm.c @@ -33,7 +33,7 @@ static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer, static struct wlr_texture *texture_from_builtin(struct wlr_renderer *renderer, const char *button) { - struct pixmap pixmap = parse_xbm_builtin(button); + struct pixmap pixmap = parse_xbm_builtin(button, 6); struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap); if (pixmap.data) free(pixmap.data);