labwc/src/xbm/xbm.c.new
Johan Malm 34b2374fd0 Fix minor coding-style violations
...based on https://github.com/johanmalm/checkpatch.pl

```
src/server.c:161: ERROR: space required before the open parenthesis '('
src/server.c:473: CHECK: Blank lines aren't necessary after an open brace '{'
src/desktop.c:228: WARNING: function definition argument 'struct wl_list *' should also have an identifier name
src/output.c:289: CHECK: Blank lines aren't necessary before a close brace '}'
src/interactive.c:20: WARNING: suspect code indent for conditional statements (8, 17)
src/interactive.c:27: WARNING: Statements should start on a tabstop
src/config/rcxml.c:607: CHECK: Blank lines aren't necessary after an open brace '{'
src/config/rcxml.c:638: CHECK: line length of 91 exceeds 90 columns
src/config/rcxml.c:639: CHECK: Blank lines aren't necessary after an open brace '{'
src/debug.c:126: WARNING: suspect code indent for conditional statements (8, 24)
src/debug.c:129: WARNING: suspect code indent for conditional statements (8, 24)
src/view.c:307: CHECK: Please use a blank line after function/struct/union/enum declarations
src/workspaces.c:52: CHECK: Blank lines aren't necessary after an open brace '{'
src/workspaces.c:147: ERROR: space prohibited before that close parenthesis ')'
src/workspaces.c:226: CHECK: line length of 91 exceeds 90 columns
src/workspaces.c:290: CHECK: Please don't use multiple blank lines
src/workspaces.c:328: WARNING: else is not generally useful after a break or return
src/cursor.c:18: ERROR: do not initialise statics to NULL
src/cursor.c:20: CHECK: Please don't use multiple blank lines
src/common/scaled_font_buffer.c:55: CHECK: Assignment operator '=' should be on the previous line
src/common/graphic-helpers.c:44: CHECK: Blank lines aren't necessary after an open brace '{'
src/common/graphic-helpers.c:71: CHECK: multiple assignments should be avoided
src/common/scaled_scene_buffer.c:115: CHECK: Assignment operator '=' should be on the previous line
src/common/scaled_scene_buffer.c:135: CHECK: Assignment operator '=' should be on the previous line
src/common/fd_util.c:15: CHECK: line length of 106 exceeds 90 columns
src/common/fd_util.c:22: CHECK: line length of 106 exceeds 90 columns
src/common/fd_util.c:25: ERROR: code indent should use tabs where possible
src/common/fd_util.c:25: WARNING: please, no spaces at the start of a line
include/workspaces.h:13: ERROR: code indent should use tabs where possible
include/workspaces.h:13: WARNING: Block comments use * on subsequent lines
include/workspaces.h:13: WARNING: Block comments use a trailing */ on a separate line
include/workspaces.h:20: CHECK: Please don't use multiple blank lines
include/workspaces.h:26: ERROR: "foo * bar" should be "foo *bar"
include/action.h:11: ERROR: code indent should use tabs where possible
include/action.h:12: ERROR: code indent should use tabs where possible
include/action.h:12: WARNING: Block comments use a trailing */ on a separate line
include/common/scaled_scene_buffer.h:62: CHECK: Please don't use multiple blank lines
```
2022-09-17 12:25:44 +01:00

92 lines
2.9 KiB
Text

// SPDX-License-Identifier: GPL-2.0-only
/*
* Create pixmaps based on xbm data
*
* Copyright Johan Malm 2020
*/
#include <stdio.h>
#include <stdlib.h>
#include <drm_fourcc.h>
#include "common/dir.h"
#include "common/grab-file.h"
#include "config/rcxml.h"
#include "theme.h"
#include "xbm/parse.h"
#include "xbm/xbm.h"
#include "buffer.h"
/* built-in 6x6 buttons */
char menu_button_normal[] = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 };
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 };
char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
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(const char *filename, struct lab_data_buffer **buffer, char *button)
{
struct pixmap pixmap = {0};
if (*buffer) {
wlr_buffer_drop(&(*buffer)->base);
*buffer = NULL;
}
/* Read file into memory as it's easier to tokenzie that way */
char *token_buffer = grab_file(xbm_path(filename));
if (token_buffer) {
struct token *tokens = tokenize_xbm(token_buffer);
free(token_buffer);
pixmap = parse_xbm_tokens(tokens);
if (tokens) {
free(tokens);
}
}
if (!pixmap.data) {
pixmap = parse_xbm_builtin(button, 6);
}
/* Create buffer with free_on_destroy being true */
*buffer = buffer_create_wrap(pixmap.data, pixmap.width, pixmap.height,
pixmap.width * 4, true);
}
void
xbm_load(struct theme *theme)
{
parse_set_color(theme->window_active_button_menu_unpressed_image_color);
load_button("menu.xbm", &theme->xbm_menu_active_unpressed,
menu_button_normal);
parse_set_color(theme->window_active_button_iconify_unpressed_image_color);
load_button("iconify.xbm", &theme->xbm_iconify_active_unpressed,
iconify_button_normal);
parse_set_color(theme->window_active_button_max_unpressed_image_color);
load_button("max.xbm", &theme->xbm_maximize_active_unpressed,
max_button_normal);
parse_set_color(theme->window_active_button_close_unpressed_image_color);
load_button("close.xbm", &theme->xbm_close_active_unpressed,
close_button_normal);
parse_set_color(theme->window_inactive_button_menu_unpressed_image_color);
load_button("menu.xbm", &theme->xbm_menu_inactive_unpressed,
menu_button_normal);
parse_set_color(theme->window_inactive_button_iconify_unpressed_image_color);
load_button("iconify.xbm", &theme->xbm_iconify_inactive_unpressed,
iconify_button_normal);
parse_set_color(theme->window_inactive_button_max_unpressed_image_color);
load_button("max.xbm", &theme->xbm_maximize_inactive_unpressed,
max_button_normal);
parse_set_color(theme->window_inactive_button_close_unpressed_image_color);
load_button("close.xbm", &theme->xbm_close_inactive_unpressed,
close_button_normal);
}