]> git.mdlowis.com Git - proto/labwc.git/commitdiff
xbm: parse_xbm_builtin() remove hard-coded values
authorJohan Malm <jgm323@gmail.com>
Tue, 11 Aug 2020 20:45:52 +0000 (21:45 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 11 Aug 2020 20:45:52 +0000 (21:45 +0100)
include/theme/xbm/parse.h
src/theme/xbm/parse.c
src/theme/xbm/xbm.c

index bd9e06523db46936e15a62f18b34c80e31dc5229..bd09d8d9b81167d45f19e3dfd8dce563422b2243 100644 (file)
@@ -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 */
index c395fbf0077d75b078c71dbc7be639934e4c226b..a85f0ae4976037da4aa861146541db4637228f5a 100644 (file)
@@ -12,6 +12,7 @@
 #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 };
@@ -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;
 }
index 20ef210f578bb545de60ee5b406d3b1b3bc3dd3d..6ad0d1ebd948b1786cf8ea5d4bab4ec0075c0e8f 100644 (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,
                                                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);