* 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 */
#include <stdbool.h>
#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 };
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;
}
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);