]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: use non-hover button variants as fallback
authorJohn Lindgren <john@jlindgren.net>
Sat, 16 Dec 2023 14:56:45 +0000 (09:56 -0500)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Thu, 21 Dec 2023 01:42:23 +0000 (02:42 +0100)
Some themes don't have hover variants for button pixmaps.
It looks better visually to use the non-hover variants as fallbacks
rather than the built-in 6x6 pixmaps.

include/button/button-xbm.h
include/theme.h
src/button/button-xbm.c
src/ssd/ssd_titlebar.c
src/theme.c

index 8b864bd03a155a7ad69b73a37ed583154de56cdb..173cdfd9f58836068c8ecd45d62e80ea67953c74 100644 (file)
@@ -6,6 +6,7 @@ struct lab_data_buffer;
 
 /* button_xbm_load - Convert xbm file to buffer with cairo surface */
 void button_xbm_load(const char *button_name, const char *alt_name,
-       struct lab_data_buffer **buffer, char *fallback_button, float *rgba);
+       struct lab_data_buffer **buffer, const char *fallback_button,
+       float *rgba);
 
 #endif /* LABWC_BUTTON_XBM_H */
index 5f958d2ebe3462c5821e1e5fde41e2b21500652f..b4c0e738a3b9758db5adc360a3b340cbdf9a239c 100644 (file)
@@ -92,6 +92,7 @@ struct theme {
        struct lab_data_buffer *button_iconify_inactive_unpressed;
        struct lab_data_buffer *button_menu_inactive_unpressed;
 
+       /* hover variants are optional and may be NULL */
        struct lab_data_buffer *button_close_active_hover;
        struct lab_data_buffer *button_maximize_active_hover;
        struct lab_data_buffer *button_restore_active_hover;
index 6435d65499531308136af4d513cb1bc8e45945d2..2d5c4e4fed345a711f18f3a5eb8a15d7cc741e37 100644 (file)
@@ -260,7 +260,8 @@ parse_xbm_builtin(const char *button, int size)
 
 void
 button_xbm_load(const char *button_name, const char *alt_name,
-       struct lab_data_buffer **buffer, char *fallback_button, float *rgba)
+       struct lab_data_buffer **buffer, const char *fallback_button,
+       float *rgba)
 {
        struct pixmap pixmap = {0};
        if (*buffer) {
@@ -270,7 +271,7 @@ button_xbm_load(const char *button_name, const char *alt_name,
 
        color = u32(rgba);
 
-       /* Read file into memory as it's easier to tokenzie that way */
+       /* Read file into memory as it's easier to tokenize that way */
        char filename[4096] = { 0 };
        button_filename(button_name, filename, sizeof(filename));
        char *token_buffer = grab_file(filename);
@@ -294,11 +295,13 @@ button_xbm_load(const char *button_name, const char *alt_name,
                        }
                }
        }
-       if (!pixmap.data) {
+       if (!pixmap.data && fallback_button) {
                pixmap = parse_xbm_builtin(fallback_button, 6);
        }
 
        /* Create buffer with free_on_destroy being true */
-       *buffer = buffer_create_wrap(pixmap.data, pixmap.width, pixmap.height,
-               pixmap.width * 4, true);
+       if (pixmap.data) {
+               *buffer = buffer_create_wrap(pixmap.data, pixmap.width,
+                       pixmap.height, pixmap.width * 4, true);
+       }
 }
index f31671626a1788690adad85bc5f854c06c77acd0..6d3e936cc7fd823a72946a5a72baeab5bcf18b41 100644 (file)
@@ -60,6 +60,7 @@ ssd_titlebar_create(struct ssd *ssd)
                        close_button_unpressed = &theme->button_close_active_unpressed->base;
                        maximize_button_unpressed = &theme->button_maximize_active_unpressed->base;
                        restore_button_unpressed = &theme->button_restore_active_unpressed->base;
+
                        menu_button_hover = &theme->button_menu_active_hover->base;
                        iconify_button_hover = &theme->button_iconify_active_hover->base;
                        close_button_hover = &theme->button_close_active_hover->base;
@@ -75,11 +76,13 @@ ssd_titlebar_create(struct ssd *ssd)
                                &theme->button_maximize_inactive_unpressed->base;
                        restore_button_unpressed = &theme->button_restore_inactive_unpressed->base;
                        close_button_unpressed = &theme->button_close_inactive_unpressed->base;
+
                        menu_button_hover = &theme->button_menu_inactive_hover->base;
                        iconify_button_hover = &theme->button_iconify_inactive_hover->base;
                        close_button_hover = &theme->button_close_inactive_hover->base;
                        maximize_button_hover = &theme->button_maximize_inactive_hover->base;
                        restore_button_hover = &theme->button_restore_inactive_hover->base;
+
                        wlr_scene_node_set_enabled(&parent->node, false);
                }
                wl_list_init(&subtree->parts);
index 624c015fd6b7b2202ec8a6702477c66f84f75198..ce71a4d49107b3442845bc27d1d2888e86b8e287 100644 (file)
@@ -40,7 +40,7 @@
 struct button {
        const char *name;
        const char *alt_name;
-       char fallback_button[6];        /* built-in 6x6 button */
+       const char *fallback_button;  /* built-in 6x6 button */
        struct {
                struct lab_data_buffer **buffer;
                float *rgba;
@@ -91,56 +91,56 @@ load_buttons(struct theme *theme)
 {
        struct button buttons[] = { {
                .name = "menu",
-               .fallback_button = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 },
+               .fallback_button = (const char[]){ 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 },
                .active.buffer = &theme->button_menu_active_unpressed,
                .active.rgba = theme->window_active_button_menu_unpressed_image_color,
                .inactive.buffer = &theme->button_menu_inactive_unpressed,
                .inactive.rgba = theme->window_inactive_button_menu_unpressed_image_color,
        }, {
                .name = "iconify",
-               .fallback_button = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f },
+               .fallback_button = (const char[]){ 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f },
                .active.buffer = &theme->button_iconify_active_unpressed,
                .active.rgba = theme->window_active_button_iconify_unpressed_image_color,
                .inactive.buffer = &theme->button_iconify_inactive_unpressed,
                .inactive.rgba = theme->window_inactive_button_iconify_unpressed_image_color,
        }, {
                .name = "max",
-               .fallback_button = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f },
+               .fallback_button = (const char[]){ 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f },
                .active.buffer = &theme->button_maximize_active_unpressed,
                .active.rgba = theme->window_active_button_max_unpressed_image_color,
                .inactive.buffer = &theme->button_maximize_inactive_unpressed,
                .inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
        }, {
                .name = "max_toggled",
-               .fallback_button = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f },
+               .fallback_button = (const char[]){ 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f },
                .active.buffer = &theme->button_restore_active_unpressed,
                .active.rgba = theme->window_active_button_max_unpressed_image_color,
                .inactive.buffer = &theme->button_restore_inactive_unpressed,
                .inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
        }, {
                .name = "close",
-               .fallback_button = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 },
+               .fallback_button = (const char[]){ 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 },
                .active.buffer = &theme->button_close_active_unpressed,
                .active.rgba = theme->window_active_button_close_unpressed_image_color,
                .inactive.buffer = &theme->button_close_inactive_unpressed,
                .inactive.rgba = theme->window_inactive_button_close_unpressed_image_color,
        }, {
                .name = "menu_hover",
-               .fallback_button = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 },
+               /* no fallback (non-hover variant is used instead) */
                .active.buffer = &theme->button_menu_active_hover,
                .active.rgba = theme->window_active_button_menu_unpressed_image_color,
                .inactive.buffer = &theme->button_menu_inactive_hover,
                .inactive.rgba = theme->window_inactive_button_menu_unpressed_image_color,
        }, {
                .name = "iconify_hover",
-               .fallback_button = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f },
+               /* no fallback (non-hover variant is used instead) */
                .active.buffer = &theme->button_iconify_active_hover,
                .active.rgba = theme->window_active_button_iconify_unpressed_image_color,
                .inactive.buffer = &theme->button_iconify_inactive_hover,
                .inactive.rgba = theme->window_inactive_button_iconify_unpressed_image_color,
        }, {
                .name = "max_hover",
-               .fallback_button = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f },
+               /* no fallback (non-hover variant is used instead) */
                .active.buffer = &theme->button_maximize_active_hover,
                .active.rgba = theme->window_active_button_max_unpressed_image_color,
                .inactive.buffer = &theme->button_maximize_inactive_hover,
@@ -148,14 +148,14 @@ load_buttons(struct theme *theme)
        }, {
                .name = "max_toggled_hover",
                .alt_name = "max_hover_toggled",
-               .fallback_button = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f },
+               /* no fallback (non-hover variant is used instead) */
                .active.buffer = &theme->button_restore_active_hover,
                .active.rgba = theme->window_active_button_max_unpressed_image_color,
                .inactive.buffer = &theme->button_restore_inactive_hover,
                .inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
        }, {
                .name = "close_hover",
-               .fallback_button = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 },
+               /* no fallback (non-hover variant is used instead) */
                .active.buffer = &theme->button_close_active_hover,
                .active.rgba = theme->window_active_button_close_unpressed_image_color,
                .inactive.buffer = &theme->button_close_inactive_hover,