diff --git a/include/button/button-png.h b/include/button/button-png.h index 408a21fc..e238b9d8 100644 --- a/include/button/button-png.h +++ b/include/button/button-png.h @@ -4,6 +4,6 @@ struct lab_data_buffer; -void png_load(const char *filename, struct lab_data_buffer **buffer); +void png_load(const char *button_name, struct lab_data_buffer **buffer); #endif /* LABWC_BUTTON_PNG_H */ diff --git a/include/button/button-xbm.h b/include/button/button-xbm.h index ae78222e..862a926d 100644 --- a/include/button/button-xbm.h +++ b/include/button/button-xbm.h @@ -5,7 +5,7 @@ struct lab_data_buffer; /* button_xbm_load - Convert xbm file to buffer with cairo surface */ -void button_xbm_load(const char *filename, struct lab_data_buffer **buffer, +void button_xbm_load(const char *button_name, struct lab_data_buffer **buffer, char *fallback_button, float *rgba); #endif /* LABWC_BUTTON_XBM_H */ diff --git a/include/button/common.h b/include/button/common.h new file mode 100644 index 00000000..b23d3513 --- /dev/null +++ b/include/button/common.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef LABWC_BUTTON_COMMON_H +#define LABWC_BUTTON_COMMON_H + +/** + * button_filename() - Get full filename for button. + * @name: The name of the button (for example 'iconify.xbm'). + * @buf: Buffer to fill with the full filename + * @len: Length of buffer + * + * Example return value: /usr/share/themes/Numix/openbox-3/iconfify.xbm + */ +void button_filename(const char *name, char *buf, size_t len); + +#endif /* LABWC_BUTTON_COMMON_H */ diff --git a/src/button/button-png.c b/src/button/button-png.c index 399f988b..cc45594f 100644 --- a/src/button/button-png.c +++ b/src/button/button-png.c @@ -12,7 +12,7 @@ #include #include "buffer.h" #include "button/button-png.h" -#include "common/dir.h" +#include "button/common.h" #include "labwc.h" #include "theme.h" @@ -24,15 +24,6 @@ file_exists(const char *path) return (!stat(path, &st)); } -/* Share with xbm.c:xbm_path() */ -static char * -button_path(const char *filename) -{ - static char buffer[4096] = { 0 }; - snprintf(buffer, sizeof(buffer), "%s/%s", theme_dir(rc.theme_name), filename); - return buffer; -} - /* * cairo_image_surface_create_from_png() does not gracefully handle non-png * files, so we verify the header before trying to read the rest of the file. @@ -62,14 +53,15 @@ ispng(const char *filename) #undef PNG_BYTES_TO_CHECK void -png_load(const char *filename, struct lab_data_buffer **buffer) +png_load(const char *button_name, struct lab_data_buffer **buffer) { if (*buffer) { wlr_buffer_drop(&(*buffer)->base); *buffer = NULL; } - char *path = button_path(filename); + char path[4096] = { 0 }; + button_filename(button_name, path, sizeof(path)); if (!file_exists(path) || !ispng(path)) { return; } diff --git a/src/button/button-xbm.c b/src/button/button-xbm.c index eb2a39ec..9d558332 100644 --- a/src/button/button-xbm.c +++ b/src/button/button-xbm.c @@ -14,6 +14,7 @@ #include #include #include "button/button-xbm.h" +#include "button/common.h" #include "common/dir.h" #include "common/grab-file.h" #include "common/mem.h" @@ -257,16 +258,8 @@ parse_xbm_builtin(const char *button, int size) return pixmap; } -static char * -xbm_path(const char *button) -{ - static char buffer[4096] = { 0 }; - snprintf(buffer, sizeof(buffer), "%s/%s", theme_dir(rc.theme_name), button); - return buffer; -} - void -button_xbm_load(const char *filename, struct lab_data_buffer **buffer, +button_xbm_load(const char *button_name, struct lab_data_buffer **buffer, char *fallback_button, float *rgba) { struct pixmap pixmap = {0}; @@ -278,7 +271,9 @@ button_xbm_load(const char *filename, struct lab_data_buffer **buffer, color = u32(rgba); /* Read file into memory as it's easier to tokenzie that way */ - char *token_buffer = grab_file(xbm_path(filename)); + char filename[4096] = { 0 }; + button_filename(button_name, filename, sizeof(filename)); + char *token_buffer = grab_file(filename); if (token_buffer) { struct token *tokens = tokenize_xbm(token_buffer); free(token_buffer); diff --git a/src/button/common.c b/src/button/common.c new file mode 100644 index 00000000..b5a3aaa7 --- /dev/null +++ b/src/button/common.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include "button/common.h" +#include "common/dir.h" +#include "config/rcxml.h" + +void +button_filename(const char *name, char *buf, size_t len) +{ + snprintf(buf, len, "%s/%s", theme_dir(rc.theme_name), name); +} diff --git a/src/button/meson.build b/src/button/meson.build index 4d738895..b5b10d2b 100644 --- a/src/button/meson.build +++ b/src/button/meson.build @@ -1,4 +1,5 @@ labwc_sources += files( 'button-png.c', 'button-xbm.c', + 'common.c', )