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 */
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 */
--- /dev/null
+/* 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 */
#include <wlr/util/log.h>
#include "buffer.h"
#include "button/button-png.h"
-#include "common/dir.h"
+#include "button/common.h"
#include "labwc.h"
#include "theme.h"
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.
#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;
}
#include <string.h>
#include <drm_fourcc.h>
#include "button/button-xbm.h"
+#include "button/common.h"
#include "common/dir.h"
#include "common/grab-file.h"
#include "common/mem.h"
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};
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);
--- /dev/null
+// SPDX-License-Identifier: GPL-2.0-only
+#include <stdio.h>
+#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);
+}
labwc_sources += files(
'button-png.c',
'button-xbm.c',
+ 'common.c',
)