mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
mv xbm/ ..
This commit is contained in:
parent
a042aad9f6
commit
fd8d9a395d
16 changed files with 22 additions and 13 deletions
|
|
@ -2,4 +2,3 @@ labwc_sources += files(
|
|||
'theme.c',
|
||||
)
|
||||
|
||||
subdir('xbm')
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
labwc_sources += files(
|
||||
'parse.c',
|
||||
'tokenize.c',
|
||||
'xbm.c',
|
||||
)
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Parse xbm token to create pixmap
|
||||
*
|
||||
* Copyright Johan Malm 2020
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "theme/xbm/parse.h"
|
||||
#include "common/bug-on.h"
|
||||
|
||||
static uint32_t color;
|
||||
|
||||
static uint32_t u32(float *rgba)
|
||||
{
|
||||
uint32_t r[4] = { 0 };
|
||||
for (int i = 0; i < 4; i++)
|
||||
r[i] = rgba[i] * 255;
|
||||
return ((r[3] & 0xff) << 24) | ((r[0] & 0xff) << 16) |
|
||||
((r[1] & 0xff) << 8) | (r[2] & 0xff);
|
||||
}
|
||||
|
||||
void parse_set_color(float *rgba)
|
||||
{
|
||||
color = u32(rgba);
|
||||
}
|
||||
|
||||
static void process_bytes(struct pixmap *pixmap, struct token *tokens)
|
||||
{
|
||||
pixmap->data = (uint32_t *)calloc(pixmap->width * pixmap->height,
|
||||
sizeof(uint32_t));
|
||||
struct token *t = tokens;
|
||||
for (int row = 0; row < pixmap->height; row++) {
|
||||
int byte = 1;
|
||||
for (int col = 0; col < pixmap->width; col++) {
|
||||
if (col == byte * 8) {
|
||||
++byte;
|
||||
++t;
|
||||
}
|
||||
if (!t->type)
|
||||
return;
|
||||
if (t->type != TOKEN_INT)
|
||||
return;
|
||||
int bit = 1 << (col % 8);
|
||||
if (t->value & bit)
|
||||
pixmap->data[row * pixmap->width + col] = color;
|
||||
}
|
||||
++t;
|
||||
}
|
||||
}
|
||||
|
||||
struct pixmap parse_xbm_tokens(struct token *tokens)
|
||||
{
|
||||
struct pixmap pixmap = { 0 };
|
||||
|
||||
for (struct token *t = tokens; t->type; t++) {
|
||||
if (pixmap.width && pixmap.height) {
|
||||
if (t->type != TOKEN_INT)
|
||||
continue;
|
||||
process_bytes(&pixmap, t);
|
||||
goto out;
|
||||
}
|
||||
if (strstr(t->name, "width"))
|
||||
pixmap.width = atoi((++t)->name);
|
||||
else if (strstr(t->name, "height"))
|
||||
pixmap.height = atoi((++t)->name);
|
||||
}
|
||||
out:
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
/*
|
||||
* Openbox built-in icons are not bigger than 8x8, so have only written this
|
||||
* function to cope wit that max size
|
||||
*/
|
||||
#define LABWC_BUILTIN_ICON_MAX_SIZE (8)
|
||||
struct pixmap parse_xbm_builtin(const char *button, int size)
|
||||
{
|
||||
struct pixmap pixmap = { 0 };
|
||||
|
||||
BUG_ON(size > LABWC_BUILTIN_ICON_MAX_SIZE);
|
||||
pixmap.width = size;
|
||||
pixmap.height = size;
|
||||
|
||||
struct token t[LABWC_BUILTIN_ICON_MAX_SIZE + 1];
|
||||
for (int i = 0; i < size; i++) {
|
||||
t[i].value = button[i];
|
||||
t[i].type = TOKEN_INT;
|
||||
}
|
||||
t[size].type = 0;
|
||||
process_bytes(&pixmap, t);
|
||||
return pixmap;
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* XBM file tokenizer
|
||||
*
|
||||
* Copyright Johan Malm 2020
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "theme/xbm/tokenize.h"
|
||||
|
||||
static char *current_buffer_position;
|
||||
static struct token *tokens;
|
||||
static int nr_tokens, alloc_tokens;
|
||||
|
||||
static void add_token(enum token_type token_type)
|
||||
{
|
||||
if (nr_tokens == alloc_tokens) {
|
||||
alloc_tokens = (alloc_tokens + 16) * 2;
|
||||
tokens = realloc(tokens, alloc_tokens * sizeof(struct token));
|
||||
}
|
||||
struct token *token = tokens + nr_tokens;
|
||||
memset(token, 0, sizeof(*token));
|
||||
nr_tokens++;
|
||||
token->type = token_type;
|
||||
}
|
||||
|
||||
static void get_identifier_token()
|
||||
{
|
||||
struct token *token = tokens + nr_tokens - 1;
|
||||
token->name[token->pos] = current_buffer_position[0];
|
||||
token->pos++;
|
||||
if (token->pos == MAX_TOKEN_SIZE - 1)
|
||||
return;
|
||||
current_buffer_position++;
|
||||
switch (current_buffer_position[0]) {
|
||||
case '\0':
|
||||
return;
|
||||
case 'a' ... 'z':
|
||||
case 'A' ... 'Z':
|
||||
case '0' ... '9':
|
||||
case '_':
|
||||
case '#':
|
||||
get_identifier_token();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void get_number_token()
|
||||
{
|
||||
struct token *token = tokens + nr_tokens - 1;
|
||||
token->name[token->pos] = current_buffer_position[0];
|
||||
token->pos++;
|
||||
if (token->pos == MAX_TOKEN_SIZE - 1)
|
||||
return;
|
||||
current_buffer_position++;
|
||||
switch (current_buffer_position[0]) {
|
||||
case '\0':
|
||||
return;
|
||||
case '0' ... '9':
|
||||
case 'a' ... 'f':
|
||||
case 'A' ... 'F':
|
||||
case 'x':
|
||||
get_number_token();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void get_special_char_token()
|
||||
{
|
||||
struct token *token = tokens + nr_tokens - 1;
|
||||
token->name[0] = current_buffer_position[0];
|
||||
current_buffer_position++;
|
||||
}
|
||||
|
||||
struct token *tokenize_xbm(char *buffer)
|
||||
{
|
||||
tokens = NULL;
|
||||
nr_tokens = 0;
|
||||
alloc_tokens = 0;
|
||||
|
||||
current_buffer_position = buffer;
|
||||
|
||||
for (;;) {
|
||||
switch (current_buffer_position[0]) {
|
||||
case '\0':
|
||||
goto out;
|
||||
case 'a' ... 'z':
|
||||
case 'A' ... 'Z':
|
||||
case '_':
|
||||
case '#':
|
||||
add_token(TOKEN_IDENT);
|
||||
get_identifier_token();
|
||||
continue;
|
||||
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);
|
||||
get_special_char_token();
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
++current_buffer_position;
|
||||
}
|
||||
out:
|
||||
add_token(TOKEN_NONE); /* vector end marker */
|
||||
return tokens;
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Create wlr textures based on xbm data
|
||||
*
|
||||
* Copyright Johan Malm 2020
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "theme/theme.h"
|
||||
#include "theme/xbm/xbm.h"
|
||||
#include "theme/xbm/parse.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/grab-file.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 };
|
||||
|
||||
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 *texture_from_builtin(struct wlr_renderer *renderer,
|
||||
const char *button)
|
||||
{
|
||||
struct pixmap pixmap = parse_xbm_builtin(button, 6);
|
||||
struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap);
|
||||
if (pixmap.data)
|
||||
free(pixmap.data);
|
||||
return texture;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void load_button(struct wlr_renderer *renderer, const char *filename,
|
||||
struct wlr_texture **texture, char *button)
|
||||
{
|
||||
/* Read file into memory as it's easier to tokenzie that way */
|
||||
char *buffer = grab_file(xbm_path(filename));
|
||||
if (!buffer)
|
||||
goto out;
|
||||
struct token *tokens = tokenize_xbm(buffer);
|
||||
free(buffer);
|
||||
|
||||
struct pixmap pixmap = parse_xbm_tokens(tokens);
|
||||
*texture = texture_from_pixmap(renderer, &pixmap);
|
||||
if (tokens)
|
||||
free(tokens);
|
||||
if (pixmap.data)
|
||||
free(pixmap.data);
|
||||
out:
|
||||
if (!(*texture))
|
||||
*texture = texture_from_builtin(renderer, button);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
void xbm_load(struct wlr_renderer *r)
|
||||
{
|
||||
parse_set_color(theme.window_active_button_unpressed_image_color);
|
||||
load_button(r, "close.xbm", &theme.xbm_close_active_unpressed, close_button_normal);
|
||||
load_button(r, "max.xbm", &theme.xbm_maximize_active_unpressed, max_button_normal);
|
||||
load_button(r, "iconify.xbm", &theme.xbm_iconify_active_unpressed, iconify_button_normal);
|
||||
|
||||
parse_set_color(theme.window_inactive_button_unpressed_image_color);
|
||||
load_button(r, "close.xbm", &theme.xbm_close_inactive_unpressed, close_button_normal);
|
||||
load_button(r, "max.xbm", &theme.xbm_maximize_inactive_unpressed, max_button_normal);
|
||||
load_button(r, "iconify.xbm", &theme.xbm_iconify_inactive_unpressed, iconify_button_normal);
|
||||
}
|
||||
/* clang-format on */
|
||||
Loading…
Add table
Add a link
Reference in a new issue