xbm: parse_xbm_builtin() remove hard-coded values

This commit is contained in:
Johan Malm 2020-08-11 21:45:52 +01:00
parent 5dbc87a1f9
commit 5ea1527558
3 changed files with 15 additions and 10 deletions

View file

@ -26,6 +26,6 @@ struct pixmap parse_xbm_tokens(struct token *tokens);
* parse_xbm_builtin - parse builtin xbm button and create pixmap * parse_xbm_builtin - parse builtin xbm button and create pixmap
* @button: button byte array (xbm format) * @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 */ #endif /* __LABWC_PARSE_H */

View file

@ -12,6 +12,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "theme/xbm/parse.h" #include "theme/xbm/parse.h"
#include "common/bug-on.h"
/* TODO: should be window.active.button.unpressed.image.color */ /* TODO: should be window.active.button.unpressed.image.color */
static unsigned char defaultcolor[] = { 255, 255, 255, 255 }; static unsigned char defaultcolor[] = { 255, 255, 255, 255 };
@ -71,21 +72,25 @@ out:
return pixmap; return pixmap;
} }
/* Assuming a 6x6 button for the time being */ /*
/* TODO: pass width, height, vargs bytes */ * Openbox built-in icons are not bigger than 8x8, so have only written this
struct pixmap parse_xbm_builtin(const char *button) * 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 }; struct pixmap pixmap = { 0 };
pixmap.width = 6; BUG_ON(size > LABWC_BUILTIN_ICON_MAX_SIZE);
pixmap.height = 6; pixmap.width = size;
pixmap.height = size;
struct token t[7]; struct token t[LABWC_BUILTIN_ICON_MAX_SIZE + 1];
for (int i = 0; i < 6; i++) { for (int i = 0; i < size; i++) {
t[i].value = button[i]; t[i].value = button[i];
t[i].type = TOKEN_INT; t[i].type = TOKEN_INT;
} }
t[6].type = 0; t[size].type = 0;
process_bytes(&pixmap, t); process_bytes(&pixmap, t);
return pixmap; return pixmap;
} }

View file

@ -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, static struct wlr_texture *texture_from_builtin(struct wlr_renderer *renderer,
const char *button) 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); struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap);
if (pixmap.data) if (pixmap.data)
free(pixmap.data); free(pixmap.data);