mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
Render close, iconify and maximize buttons
This commit is contained in:
parent
e1b86555f4
commit
f7fa28ab42
10 changed files with 140 additions and 53 deletions
|
|
@ -36,10 +36,12 @@ static void process_bytes(struct pixmap *pixmap, struct token *tokens)
|
|||
}
|
||||
if (!t->type)
|
||||
return;
|
||||
int value = (int)strtol(t->name, NULL, 0);
|
||||
if (t->type != TOKEN_INT)
|
||||
return;
|
||||
int bit = 1 << (col % 8);
|
||||
if (value & bit)
|
||||
pixmap->data[row * pixmap->width + col] = u32(defaultcolor);
|
||||
if (t->value & bit)
|
||||
pixmap->data[row * pixmap->width + col] =
|
||||
u32(defaultcolor);
|
||||
}
|
||||
++t;
|
||||
}
|
||||
|
|
@ -65,6 +67,25 @@ out:
|
|||
return pixmap;
|
||||
}
|
||||
|
||||
/* Assuming a 6x6 button for the time being */
|
||||
/* TODO: pass width, height, vargs bytes */
|
||||
struct pixmap xbm_create_pixmap_builtin(const char *button)
|
||||
{
|
||||
struct pixmap pixmap = { 0 };
|
||||
|
||||
pixmap.width = 6;
|
||||
pixmap.height = 6;
|
||||
|
||||
struct token t[7];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
t[i].value = button[i];
|
||||
t[i].type = TOKEN_INT;
|
||||
}
|
||||
t[6].type = 0;
|
||||
process_bytes(&pixmap, t);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
char *xbm_read_file(const char *filename)
|
||||
{
|
||||
char *line = NULL;
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ struct token *xbm_tokenize(char *buffer)
|
|||
case '0' ... '9':
|
||||
add_token(TOKEN_INT);
|
||||
get_number_token();
|
||||
struct token *token = tokens + nr_tokens - 1;
|
||||
token->value = (int)strtol(token->name, NULL, 0);
|
||||
continue;
|
||||
case '{':
|
||||
add_token(TOKEN_SPECIAL);
|
||||
|
|
|
|||
|
|
@ -10,8 +10,38 @@
|
|||
#include "theme/xbm/xbm.h"
|
||||
#include "theme/xbm/parse.h"
|
||||
|
||||
/* 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 };
|
||||
|
||||
/*
|
||||
* TODO: parse rc.xml theme name and look for icons properly.
|
||||
* Just using random icon to prove the point.
|
||||
*/
|
||||
static char filename[] = "/usr/share/themes/Bear2/openbox-3/close.xbm";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static struct wlr_texture *builtin(struct wlr_renderer *renderer,
|
||||
const char *button)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void xbm_load(struct wlr_renderer *renderer)
|
||||
{
|
||||
struct token *tokens;
|
||||
|
|
@ -19,16 +49,20 @@ void xbm_load(struct wlr_renderer *renderer)
|
|||
char *buffer = xbm_read_file(filename);
|
||||
if (!buffer) {
|
||||
fprintf(stderr, "no buffer\n");
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
tokens = xbm_tokenize(buffer);
|
||||
free(buffer);
|
||||
struct pixmap pixmap = xbm_create_pixmap(tokens);
|
||||
free(tokens);
|
||||
|
||||
theme.xbm_close = wlr_texture_from_pixels(
|
||||
renderer, WL_SHM_FORMAT_ARGB8888, pixmap.width * 4,
|
||||
pixmap.width, pixmap.height, pixmap.data);
|
||||
theme.xbm_close = texture_from_pixmap(renderer, &pixmap);
|
||||
if (tokens)
|
||||
free(tokens);
|
||||
if (pixmap.data)
|
||||
free(pixmap.data);
|
||||
|
||||
out:
|
||||
if (!theme.xbm_close)
|
||||
theme.xbm_close = builtin(renderer, close_button_normal);
|
||||
theme.xbm_maximize = builtin(renderer, max_button_normal);
|
||||
theme.xbm_iconify = builtin(renderer, iconify_button_normal);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue