mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
Update .clang-format
Align with wlroots style
This commit is contained in:
parent
96b5ab1fc1
commit
96e05057a3
32 changed files with 669 additions and 515 deletions
|
|
@ -1,21 +1,21 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <wayland-server-core.h>
|
||||
|
||||
#include "config/rcxml.h"
|
||||
#include "config/keybind.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/bug-on.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/font.h"
|
||||
#include "common/log.h"
|
||||
#include "config/keybind.h"
|
||||
#include "config/rcxml.h"
|
||||
|
||||
static bool in_keybind = false;
|
||||
static bool is_attribute = false;
|
||||
|
|
@ -30,21 +30,26 @@ enum font_place {
|
|||
/* TODO: Add all places based on Openbox's rc.xml */
|
||||
};
|
||||
|
||||
static void rstrip(char *buf, const char *pattern)
|
||||
static void
|
||||
rstrip(char *buf, const char *pattern)
|
||||
{
|
||||
char *p = strstr(buf, pattern);
|
||||
if (!p)
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
static void fill_keybind(char *nodename, char *content)
|
||||
static void
|
||||
fill_keybind(char *nodename, char *content)
|
||||
{
|
||||
if (!content)
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
rstrip(nodename, ".keybind.keyboard");
|
||||
if (!strcmp(nodename, "key"))
|
||||
if (!strcmp(nodename, "key")) {
|
||||
current_keybind = keybind_create(content);
|
||||
}
|
||||
/* We expect <keybind key=""> to come first */
|
||||
BUG_ON(!current_keybind);
|
||||
if (!strcmp(nodename, "name.action")) {
|
||||
|
|
@ -54,56 +59,70 @@ static void fill_keybind(char *nodename, char *content)
|
|||
}
|
||||
}
|
||||
|
||||
static bool get_bool(const char *s)
|
||||
static bool
|
||||
get_bool(const char *s)
|
||||
{
|
||||
if (!s)
|
||||
if (!s) {
|
||||
return false;
|
||||
if (!strcasecmp(s, "yes"))
|
||||
}
|
||||
if (!strcasecmp(s, "yes")) {
|
||||
return true;
|
||||
if (!strcasecmp(s, "true"))
|
||||
}
|
||||
if (!strcasecmp(s, "true")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void fill_font(char *nodename, char *content, enum font_place place)
|
||||
static void
|
||||
fill_font(char *nodename, char *content, enum font_place place)
|
||||
{
|
||||
if (!content)
|
||||
if (!content) {
|
||||
return;
|
||||
}
|
||||
rstrip(nodename, ".font.theme");
|
||||
|
||||
/* TODO: implement for all font places */
|
||||
if (place != FONT_PLACE_ACTIVEWINDOW)
|
||||
if (place != FONT_PLACE_ACTIVEWINDOW) {
|
||||
return;
|
||||
if (!strcmp(nodename, "name"))
|
||||
}
|
||||
if (!strcmp(nodename, "name")) {
|
||||
rc.font_name_activewindow = strdup(content);
|
||||
else if (!strcmp(nodename, "size"))
|
||||
} else if (!strcmp(nodename, "size")) {
|
||||
rc.font_size_activewindow = atoi(content);
|
||||
}
|
||||
}
|
||||
|
||||
static enum font_place enum_font_place(const char *place)
|
||||
static enum font_place
|
||||
enum_font_place(const char *place)
|
||||
{
|
||||
if (!place)
|
||||
if (!place) {
|
||||
return FONT_PLACE_UNKNOWN;
|
||||
if (!strcasecmp(place, "ActiveWindow"))
|
||||
}
|
||||
if (!strcasecmp(place, "ActiveWindow")) {
|
||||
return FONT_PLACE_ACTIVEWINDOW;
|
||||
else if (!strcasecmp(place, "InactiveWindow"))
|
||||
} else if (!strcasecmp(place, "InactiveWindow")) {
|
||||
return FONT_PLACE_INACTIVEWINDOW;
|
||||
}
|
||||
return FONT_PLACE_UNKNOWN;
|
||||
}
|
||||
|
||||
static void entry(xmlNode *node, char *nodename, char *content)
|
||||
static void
|
||||
entry(xmlNode *node, char *nodename, char *content)
|
||||
{
|
||||
/* current <theme><font place=""></theme> */
|
||||
static enum font_place font_place = FONT_PLACE_UNKNOWN;
|
||||
|
||||
if (!nodename)
|
||||
if (!nodename) {
|
||||
return;
|
||||
}
|
||||
rstrip(nodename, ".openbox_config");
|
||||
|
||||
/* for debugging */
|
||||
if (write_to_nodename_buffer) {
|
||||
if (is_attribute)
|
||||
if (is_attribute) {
|
||||
buf_add(nodename_buffer, "@");
|
||||
}
|
||||
buf_add(nodename_buffer, nodename);
|
||||
if (content) {
|
||||
buf_add(nodename_buffer, ": ");
|
||||
|
|
@ -112,34 +131,41 @@ static void entry(xmlNode *node, char *nodename, char *content)
|
|||
buf_add(nodename_buffer, "\n");
|
||||
}
|
||||
|
||||
if (!content)
|
||||
if (!content) {
|
||||
return;
|
||||
if (in_keybind)
|
||||
}
|
||||
if (in_keybind) {
|
||||
fill_keybind(nodename, content);
|
||||
}
|
||||
|
||||
if (is_attribute && !strcmp(nodename, "place.font.theme"))
|
||||
if (is_attribute && !strcmp(nodename, "place.font.theme")) {
|
||||
font_place = enum_font_place(content);
|
||||
}
|
||||
|
||||
if (!strcmp(nodename, "xdg_shell_server_side_deco.lab"))
|
||||
if (!strcmp(nodename, "xdg_shell_server_side_deco.lab")) {
|
||||
rc.xdg_shell_server_side_deco = get_bool(content);
|
||||
else if (!strcmp(nodename, "layout.keyboard.lab"))
|
||||
} else if (!strcmp(nodename, "layout.keyboard.lab")) {
|
||||
setenv("XKB_DEFAULT_LAYOUT", content, 1);
|
||||
else if (!strcmp(nodename, "name.theme"))
|
||||
} else if (!strcmp(nodename, "name.theme")) {
|
||||
rc.theme_name = strdup(content);
|
||||
else if (!strcmp(nodename, "name.font.theme"))
|
||||
} else if (!strcmp(nodename, "name.font.theme")) {
|
||||
fill_font(nodename, content, font_place);
|
||||
else if (!strcmp(nodename, "size.font.theme"))
|
||||
} else if (!strcmp(nodename, "size.font.theme")) {
|
||||
fill_font(nodename, content, font_place);
|
||||
}
|
||||
}
|
||||
|
||||
static char *nodename(xmlNode *node, char *buf, int len)
|
||||
static char *
|
||||
nodename(xmlNode *node, char *buf, int len)
|
||||
{
|
||||
if (!node || !node->name)
|
||||
if (!node || !node->name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ignore superflous 'text.' in node name */
|
||||
if (node->parent && !strcmp((char *)node->name, "text"))
|
||||
if (node->parent && !strcmp((char *)node->name, "text")) {
|
||||
node = node->parent;
|
||||
}
|
||||
|
||||
char *p = buf;
|
||||
p[--len] = 0;
|
||||
|
|
@ -153,44 +179,52 @@ static char *nodename(xmlNode *node, char *buf, int len)
|
|||
}
|
||||
*p = 0;
|
||||
node = node->parent;
|
||||
if (!node || !node->name)
|
||||
if (!node || !node->name) {
|
||||
return buf;
|
||||
}
|
||||
*p++ = '.';
|
||||
if (!--len)
|
||||
if (!--len) {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void process_node(xmlNode *node)
|
||||
static void
|
||||
process_node(xmlNode *node)
|
||||
{
|
||||
char *content;
|
||||
static char buffer[256];
|
||||
char *name;
|
||||
|
||||
content = (char *)node->content;
|
||||
if (xmlIsBlankNode(node))
|
||||
if (xmlIsBlankNode(node)) {
|
||||
return;
|
||||
}
|
||||
name = nodename(node, buffer, sizeof(buffer));
|
||||
entry(node, name, content);
|
||||
}
|
||||
|
||||
static void xml_tree_walk(xmlNode *node);
|
||||
|
||||
static void traverse(xmlNode *n)
|
||||
static void
|
||||
traverse(xmlNode *n)
|
||||
{
|
||||
process_node(n);
|
||||
is_attribute = true;
|
||||
for (xmlAttr *attr = n->properties; attr; attr = attr->next)
|
||||
for (xmlAttr *attr = n->properties; attr; attr = attr->next) {
|
||||
xml_tree_walk(attr->children);
|
||||
}
|
||||
is_attribute = false;
|
||||
xml_tree_walk(n->children);
|
||||
}
|
||||
|
||||
static void xml_tree_walk(xmlNode *node)
|
||||
static void
|
||||
xml_tree_walk(xmlNode *node)
|
||||
{
|
||||
for (xmlNode *n = node; n && n->name; n = n->next) {
|
||||
if (!strcasecmp((char *)n->name, "comment"))
|
||||
if (!strcasecmp((char *)n->name, "comment")) {
|
||||
continue;
|
||||
}
|
||||
if (!strcasecmp((char *)n->name, "keybind")) {
|
||||
in_keybind = true;
|
||||
traverse(n);
|
||||
|
|
@ -202,7 +236,8 @@ static void xml_tree_walk(xmlNode *node)
|
|||
}
|
||||
|
||||
/* Exposed in header file to allow unit tests to parse buffers */
|
||||
void rcxml_parse_xml(struct buf *b)
|
||||
void
|
||||
rcxml_parse_xml(struct buf *b)
|
||||
{
|
||||
xmlDoc *d = xmlParseMemory(b->buf, b->len);
|
||||
if (!d) {
|
||||
|
|
@ -214,38 +249,47 @@ void rcxml_parse_xml(struct buf *b)
|
|||
xmlCleanupParser();
|
||||
}
|
||||
|
||||
static void pre_processing(void)
|
||||
static void
|
||||
pre_processing(void)
|
||||
{
|
||||
rc.xdg_shell_server_side_deco = true;
|
||||
rc.font_size_activewindow = 8;
|
||||
}
|
||||
|
||||
static void rcxml_init()
|
||||
static void
|
||||
rcxml_init()
|
||||
{
|
||||
static bool has_run;
|
||||
|
||||
if (has_run)
|
||||
if (has_run) {
|
||||
return;
|
||||
}
|
||||
has_run = true;
|
||||
LIBXML_TEST_VERSION
|
||||
wl_list_init(&rc.keybinds);
|
||||
pre_processing();
|
||||
}
|
||||
|
||||
static void bind(const char *binding, const char *action, const char *command)
|
||||
static void
|
||||
bind(const char *binding, const char *action, const char *command)
|
||||
{
|
||||
if (!binding || !action)
|
||||
if (!binding || !action) {
|
||||
return;
|
||||
}
|
||||
struct keybind *k = keybind_create(binding);
|
||||
if (!k)
|
||||
if (!k) {
|
||||
return;
|
||||
if (action)
|
||||
}
|
||||
if (action) {
|
||||
k->action = strdup(action);
|
||||
if (command)
|
||||
}
|
||||
if (command) {
|
||||
k->command = strdup(command);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_title_height(void)
|
||||
static void
|
||||
set_title_height(void)
|
||||
{
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf), "%s %d", rc.font_name_activewindow,
|
||||
|
|
@ -253,7 +297,8 @@ static void set_title_height(void)
|
|||
rc.title_height = font_height(buf);
|
||||
}
|
||||
|
||||
static void post_processing(void)
|
||||
static void
|
||||
post_processing(void)
|
||||
{
|
||||
if (!wl_list_length(&rc.keybinds)) {
|
||||
info("loading default key bindings");
|
||||
|
|
@ -263,22 +308,26 @@ static void post_processing(void)
|
|||
bind("A-F3", "Execute", "dmenu_run");
|
||||
}
|
||||
|
||||
if (!rc.theme_name)
|
||||
if (!rc.theme_name) {
|
||||
rc.theme_name = strdup("Clearlooks");
|
||||
if (!rc.font_name_activewindow)
|
||||
}
|
||||
if (!rc.font_name_activewindow) {
|
||||
rc.font_name_activewindow = strdup("sans");
|
||||
|
||||
}
|
||||
set_title_height();
|
||||
}
|
||||
|
||||
static void rcxml_path(char *buf, size_t len)
|
||||
static void
|
||||
rcxml_path(char *buf, size_t len)
|
||||
{
|
||||
if (!strlen(config_dir()))
|
||||
if (!strlen(config_dir())) {
|
||||
return;
|
||||
}
|
||||
snprintf(buf, len, "%s/rc.xml", config_dir());
|
||||
}
|
||||
|
||||
static void find_config_file(char *buffer, size_t len, const char *filename)
|
||||
static void
|
||||
find_config_file(char *buffer, size_t len, const char *filename)
|
||||
{
|
||||
if (filename) {
|
||||
snprintf(buffer, len, "%s", filename);
|
||||
|
|
@ -287,7 +336,8 @@ static void find_config_file(char *buffer, size_t len, const char *filename)
|
|||
rcxml_path(buffer, len);
|
||||
}
|
||||
|
||||
void rcxml_read(const char *filename)
|
||||
void
|
||||
rcxml_read(const char *filename)
|
||||
{
|
||||
FILE *stream;
|
||||
char *line = NULL;
|
||||
|
|
@ -302,8 +352,9 @@ void rcxml_read(const char *filename)
|
|||
* the first time. The specified 'filename' is only respected the first
|
||||
* time.
|
||||
*/
|
||||
if (rcxml[0] == '\0')
|
||||
if (rcxml[0] == '\0') {
|
||||
find_config_file(rcxml, sizeof(rcxml), filename);
|
||||
}
|
||||
if (rcxml[0] == '\0') {
|
||||
warn("cannot find rc.xml config file");
|
||||
goto no_config;
|
||||
|
|
@ -331,14 +382,17 @@ no_config:
|
|||
post_processing();
|
||||
}
|
||||
|
||||
static void free_safe(const void *p)
|
||||
static void
|
||||
free_safe(const void *p)
|
||||
{
|
||||
if (p)
|
||||
if (p) {
|
||||
free((void *)p);
|
||||
}
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
void rcxml_finish(void)
|
||||
void
|
||||
rcxml_finish(void)
|
||||
{
|
||||
free_safe(rc.font_name_activewindow);
|
||||
free_safe(rc.theme_name);
|
||||
|
|
@ -353,7 +407,8 @@ void rcxml_finish(void)
|
|||
}
|
||||
}
|
||||
|
||||
void rcxml_get_nodenames(struct buf *b)
|
||||
void
|
||||
rcxml_get_nodenames(struct buf *b)
|
||||
{
|
||||
write_to_nodename_buffer = true;
|
||||
nodename_buffer = b;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue