2020-06-29 19:27:59 +01:00
|
|
|
/*
|
|
|
|
|
* Create wlr textures based on xbm data
|
|
|
|
|
*
|
|
|
|
|
* Copyright Johan Malm 2020
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2020-08-03 20:56:38 +01:00
|
|
|
#include "theme/theme.h"
|
2020-06-29 19:27:59 +01:00
|
|
|
#include "theme/xbm/xbm.h"
|
|
|
|
|
#include "theme/xbm/parse.h"
|
2020-07-13 20:09:34 +01:00
|
|
|
#include "theme/theme-dir.h"
|
2020-08-03 20:56:38 +01:00
|
|
|
#include "config/rcxml.h"
|
2020-07-09 22:41:54 +01:00
|
|
|
|
2020-07-06 21:58:51 +01:00
|
|
|
/* built-in 6x6 buttons */
|
|
|
|
|
char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
|
|
|
|
|
char iconify_button_normal[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
|
|
|
|
|
char max_button_normal[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
|
|
|
|
|
char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
|
|
|
|
|
|
|
|
|
|
static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer,
|
|
|
|
|
struct pixmap *pixmap)
|
|
|
|
|
{
|
|
|
|
|
if (!pixmap)
|
|
|
|
|
return NULL;
|
|
|
|
|
return wlr_texture_from_pixels(renderer, WL_SHM_FORMAT_ARGB8888,
|
|
|
|
|
pixmap->width * 4, pixmap->width,
|
|
|
|
|
pixmap->height, pixmap->data);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 20:09:34 +01:00
|
|
|
static struct wlr_texture *texture_from_builtin(struct wlr_renderer *renderer,
|
2020-08-03 20:56:38 +01:00
|
|
|
const char *button)
|
2020-07-06 21:58:51 +01:00
|
|
|
{
|
|
|
|
|
struct pixmap pixmap = xbm_create_pixmap_builtin(button);
|
|
|
|
|
struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap);
|
|
|
|
|
if (pixmap.data)
|
|
|
|
|
free(pixmap.data);
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 22:41:54 +01:00
|
|
|
static char *xbm_path(const char *button)
|
|
|
|
|
{
|
|
|
|
|
static char buffer[4096] = { 0 };
|
2020-07-13 20:09:34 +01:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s/%s", theme_dir(rc.theme_name),
|
|
|
|
|
button);
|
2020-07-09 22:41:54 +01:00
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 20:09:34 +01:00
|
|
|
static void load_button(struct wlr_renderer *renderer, const char *filename,
|
|
|
|
|
struct wlr_texture **texture, char *button)
|
2020-06-29 19:27:59 +01:00
|
|
|
{
|
2020-07-13 20:09:34 +01:00
|
|
|
char *buffer = xbm_read_file(xbm_path(filename));
|
|
|
|
|
if (!buffer)
|
2020-07-06 21:58:51 +01:00
|
|
|
goto out;
|
2020-07-13 20:09:34 +01:00
|
|
|
fprintf(stderr, "loading %s\n", filename);
|
|
|
|
|
struct token *tokens = xbm_tokenize(buffer);
|
2020-06-29 19:27:59 +01:00
|
|
|
free(buffer);
|
|
|
|
|
struct pixmap pixmap = xbm_create_pixmap(tokens);
|
2020-07-13 20:09:34 +01:00
|
|
|
*texture = texture_from_pixmap(renderer, &pixmap);
|
2020-07-06 21:58:51 +01:00
|
|
|
if (tokens)
|
|
|
|
|
free(tokens);
|
2020-06-29 19:27:59 +01:00
|
|
|
if (pixmap.data)
|
|
|
|
|
free(pixmap.data);
|
2020-07-06 21:58:51 +01:00
|
|
|
out:
|
2020-07-13 20:09:34 +01:00
|
|
|
if (!(*texture))
|
|
|
|
|
*texture = texture_from_builtin(renderer, button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void xbm_load(struct wlr_renderer *r)
|
|
|
|
|
{
|
|
|
|
|
load_button(r, "close.xbm", &theme.xbm_close, close_button_normal);
|
|
|
|
|
load_button(r, "max.xbm", &theme.xbm_maximize, max_button_normal);
|
2020-08-03 20:56:38 +01:00
|
|
|
load_button(r, "iconify.xbm", &theme.xbm_iconify,
|
|
|
|
|
iconify_button_normal);
|
2020-06-29 19:27:59 +01:00
|
|
|
}
|