Update .clang-format

Align with wlroots style
This commit is contained in:
Johan Malm 2020-09-28 20:41:41 +01:00
parent 96b5ab1fc1
commit 96e05057a3
32 changed files with 669 additions and 515 deletions

View file

@ -1,40 +1,48 @@
#define _POSIX_C_SOURCE 200809L
#include <ctype.h>
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <glib.h>
#include "theme/theme.h"
#include "common/dir.h"
#include "common/log.h"
#include "theme/theme.h"
static int hex_to_dec(char c)
static int
hex_to_dec(char c)
{
if (c >= '0' && c <= '9')
if (c >= '0' && c <= '9') {
return c - '0';
if (c >= 'a' && c <= 'f')
}
if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
}
if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
}
return 0;
}
void parse_hexstr(const char *hex, float *rgba)
void
parse_hexstr(const char *hex, float *rgba)
{
if (!hex || hex[0] != '#' || strlen(hex) < 7)
if (!hex || hex[0] != '#' || strlen(hex) < 7) {
return;
}
rgba[0] = (hex_to_dec(hex[1]) * 16 + hex_to_dec(hex[2])) / 255.0;
rgba[1] = (hex_to_dec(hex[3]) * 16 + hex_to_dec(hex[4])) / 255.0;
rgba[2] = (hex_to_dec(hex[5]) * 16 + hex_to_dec(hex[6])) / 255.0;
if (strlen(hex) > 7)
if (strlen(hex) > 7) {
rgba[3] = atoi(hex + 7) / 100.0;
else
} else {
rgba[3] = 1.0;
}
}
static bool match(const gchar *pattern, const gchar *string)
static bool
match(const gchar *pattern, const gchar *string)
{
return (bool)g_pattern_match_simple(pattern, string);
}
@ -42,60 +50,72 @@ static bool match(const gchar *pattern, const gchar *string)
/* clang-format off */
static void entry(const char *key, const char *value)
{
if (!key || !value)
if (!key || !value) {
return;
if (match(key, "window.active.title.bg.color"))
}
if (match(key, "window.active.title.bg.color")) {
parse_hexstr(value, theme.window_active_title_bg_color);
if (match(key, "window.active.handle.bg.color"))
} else if (match(key, "window.active.handle.bg.color")) {
parse_hexstr(value, theme.window_active_handle_bg_color);
if (match(key, "window.inactive.title.bg.color"))
} else if (match(key, "window.inactive.title.bg.color")) {
parse_hexstr(value, theme.window_inactive_title_bg_color);
if (match(key, "window.active.button.unpressed.image.color"))
} else if (match(key, "window.active.button.unpressed.image.color")) {
parse_hexstr(value, theme.window_active_button_unpressed_image_color);
if (match(key, "window.inactive.button.unpressed.image.color"))
} else if (match(key, "window.inactive.button.unpressed.image.color")) {
parse_hexstr(value, theme.window_inactive_button_unpressed_image_color);
}
}
/* clang-format on */
static void rtrim(char **s)
static void
rtrim(char **s)
{
size_t len = strlen(*s);
if (!len)
if (!len) {
return;
}
char *end = *s + len - 1;
while (end >= *s && isspace(*end))
while (end >= *s && isspace(*end)) {
end--;
}
*(end + 1) = '\0';
}
static char *strstrip(char *s)
static char *
strstrip(char *s)
{
rtrim(&s);
while (isspace(*s))
while (isspace(*s)) {
s++;
}
return s;
}
static void parse_config_line(char *line, char **key, char **value)
static void
parse_config_line(char *line, char **key, char **value)
{
char *p = strchr(line, ':');
if (!p)
if (!p) {
return;
}
*p = '\0';
*key = strstrip(line);
*value = strstrip(++p);
}
static void process_line(char *line)
static void
process_line(char *line)
{
if (line[0] == '\0' || line[0] == '#')
if (line[0] == '\0' || line[0] == '#') {
return;
}
char *key = NULL, *value = NULL;
parse_config_line(line, &key, &value);
entry(key, value);
}
void theme_read(const char *theme_name)
void
theme_read(const char *theme_name)
{
FILE *stream = NULL;
char *line = NULL;
@ -115,8 +135,9 @@ void theme_read(const char *theme_name)
info("reading themerc (%s)", themerc);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
if (p)
if (p) {
*p = '\0';
}
process_line(line);
}
free(line);