From 4d1363dcae3a1ac1f38876ba3693dcdb7d43415e Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 3 Aug 2020 20:56:38 +0100 Subject: [PATCH] include/: refactor header files more --- README.md | 4 ++-- .../labwc-default/openbox-3}/themerc | 0 include/common/buf.h | 19 +++++++++++++++---- include/common/bug-on.h | 7 +++++-- include/common/spawn.h | 10 ++++++++++ include/config/config-dir.h | 6 +++--- include/config/keybind.h | 18 ++++++++++++++++++ include/{ => config}/rcxml.h | 19 +++---------------- include/labwc.h | 9 +++++---- include/spawn.h | 6 ------ include/theme/theme-dir.h | 6 +++--- include/{ => theme}/theme.h | 6 +++--- include/theme/xbm/parse.h | 6 +++--- include/theme/xbm/tokenize.h | 6 +++--- include/theme/xbm/xbm.h | 7 +++---- src/action.c | 2 +- src/common/spawn.c | 4 ++-- src/config/keybind.c | 4 ++-- src/config/rcxml.c | 3 ++- src/debug/dbg.c | 3 ++- src/deco.c | 2 +- src/main.c | 4 ++-- src/output.c | 2 +- src/theme/theme-dir.c | 4 ++-- src/theme/theme.c | 2 +- src/theme/xbm/xbm.c | 8 +++++--- tests/t1000-rcxml-simple-parse.c | 2 +- tests/t1001-rcxml-nodenames-simple.c | 2 +- tools/hex/Makefile | 2 +- tools/rcxml/rcxml-print-nodenames.c | 2 +- tools/theme/Makefile | 17 ++++++++++++++++- tools/theme/theme-helper.c | 16 +++++++++++++--- 32 files changed, 130 insertions(+), 78 deletions(-) rename data/{ => themes/labwc-default/openbox-3}/themerc (100%) create mode 100644 include/common/spawn.h create mode 100644 include/config/keybind.h rename include/{ => config}/rcxml.h (55%) delete mode 100644 include/spawn.h rename include/{ => theme}/theme.h (86%) diff --git a/README.md b/README.md index b6643dbd..8303a278 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ libxml2, glib-2.0, cairo and pango. - [x] Support xwayland - [x] Parse [rc.xml](data/rc.xml) -- [x] Parse [themerc](data/themerc) +- [x] Parse [themerc](data/themes/labwc-default/openbox-3/themerc) - [x] Read xbm icons - [x] Show maximize, minimize, close buttons - [ ] Give actions to maximize, minimize, close buttons @@ -55,7 +55,7 @@ The following were considered before choosing wlroots: [QtWayland](https://githu ## Configuration -See [rc.xml](data/rc.xml) and [themerc](data/themerc) comments for details including keybinds. +See [rc.xml](data/rc.xml) and [themerc](data/themes/labwc-default/openbox-3/themerc) comments for details including keybinds. Suggest either copying data/rc.xml to ~/.config/labwc/running, or running with: diff --git a/data/themerc b/data/themes/labwc-default/openbox-3/themerc similarity index 100% rename from data/themerc rename to data/themes/labwc-default/openbox-3/themerc diff --git a/include/common/buf.h b/include/common/buf.h index c7184888..f732bb5f 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -1,11 +1,11 @@ /* - * Very simple C buffer implementation + * Very simple C string buffer implementation * * Copyright Johan Malm 2020 */ -#ifndef BUF_H -#define BUF_H +#ifndef __LABWC_BUF_H +#define __LABWC_BUF_H #include #include @@ -17,7 +17,18 @@ struct buf { int len; }; +/* + * buf_init - allocate NULL-terminated C string buffer + * @s - buffer + * Note: use free(s->buf) to free it. + */ void buf_init(struct buf *s); + +/* + * buf_add - add data to C string buffer + * @s - buffer + * @data - data to be added + */ void buf_add(struct buf *s, const char *data); -#endif /* BUF_H */ +#endif /* __LABWC_BUF_H */ diff --git a/include/common/bug-on.h b/include/common/bug-on.h index c9c3be51..aa5f7f3f 100644 --- a/include/common/bug-on.h +++ b/include/common/bug-on.h @@ -1,6 +1,10 @@ #ifndef __LABWC_BUG_ON_H #define __LABWC_BUG_ON_H +/* + * BUG_ON - assert() without abort() + * @condition - expression to be evaluated + */ #define BUG_ON(condition) \ do { \ if ((condition) != 0) { \ @@ -9,5 +13,4 @@ } \ } while (0) -#endif /* __LABWC_BUT_ON_H */ - +#endif /* __LABWC_BUG_ON_H */ diff --git a/include/common/spawn.h b/include/common/spawn.h new file mode 100644 index 00000000..10394a1b --- /dev/null +++ b/include/common/spawn.h @@ -0,0 +1,10 @@ +#ifndef __LABWC_SPAWN_H +#define __LABWC_SPAWN_H + +/** + * spawn_async_no_shell - execute asyncronously + * @command: command to be executed + */ +void spawn_async_no_shell(char const *command); + +#endif /* __LABWC_SPAWN_H */ diff --git a/include/config/config-dir.h b/include/config/config-dir.h index bf74960f..19ae1303 100644 --- a/include/config/config-dir.h +++ b/include/config/config-dir.h @@ -1,6 +1,6 @@ -#ifndef CONFIG_DIR_H -#define CONFIG_DIR_H +#ifndef __LABWC_CONFIG_DIR_H +#define __LABWC_CONFIG_DIR_H char *config_dir(void); -#endif /* CONFIG_DIR_H */ +#endif /* __LABWC_CONFIG_DIR_H */ diff --git a/include/config/keybind.h b/include/config/keybind.h new file mode 100644 index 00000000..ce57caf7 --- /dev/null +++ b/include/config/keybind.h @@ -0,0 +1,18 @@ +#ifndef __LABWC_KEYBIND_H +#define __LABWC_KEYBIND_H + +#include +#include + +struct keybind { + uint32_t modifiers; + xkb_keysym_t *keysyms; + size_t keysyms_len; + char *action; + char *command; + struct wl_list link; +}; + +struct keybind *keybind_add(const char *keybind); + +#endif /* __LABWC_KEYBIND_H */ diff --git a/include/rcxml.h b/include/config/rcxml.h similarity index 55% rename from include/rcxml.h rename to include/config/rcxml.h index eda86a13..0b5484a5 100644 --- a/include/rcxml.h +++ b/include/config/rcxml.h @@ -1,25 +1,12 @@ -#ifndef RCXML_H -#define RCXML_H +#ifndef __LABWC_RCXML_H +#define __LABWC_RCXML_H #include #include -#include #include -#include #include "common/buf.h" -struct keybind { - uint32_t modifiers; - xkb_keysym_t *keysyms; - size_t keysyms_len; - char *action; - char *command; - struct wl_list link; -}; - -struct keybind *keybind_add(const char *keybind); - struct rcxml { bool client_side_decorations; char *theme_name; @@ -34,4 +21,4 @@ void rcxml_parse_xml(struct buf *b); void rcxml_read(const char *filename); void rcxml_get_nodenames(struct buf *b); -#endif /* RCXML_H */ +#endif /* __LABWC_RCXML_H */ diff --git a/include/labwc.h b/include/labwc.h index 84d73d3d..aec9fded 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -1,5 +1,5 @@ -#ifndef LABWC_H -#define LABWC_H +#ifndef __LABWC_H +#define __LABWC_H #define _POSIX_C_SOURCE 200809L #include @@ -29,7 +29,8 @@ #include #include -#include "rcxml.h" +#include "config/rcxml.h" +#include "config/keybind.h" #define XCURSOR_DEFAULT "left_ptr" #define XCURSOR_SIZE 24 @@ -185,4 +186,4 @@ void dbg_show_one_view(struct view *view); void dbg_show_views(struct server *server); void dbg_show_keybinds(); -#endif /* LABWC_H */ +#endif /* __LABWC_H */ diff --git a/include/spawn.h b/include/spawn.h deleted file mode 100644 index 730bb08c..00000000 --- a/include/spawn.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef SPAWN_H -#define SPAWN_H - -void spawn_async_no_shell(char const *command); - -#endif /* SPAWN_H */ diff --git a/include/theme/theme-dir.h b/include/theme/theme-dir.h index 87c5c3d0..9ebb09af 100644 --- a/include/theme/theme-dir.h +++ b/include/theme/theme-dir.h @@ -1,6 +1,6 @@ -#ifndef THEME_DIR_H -#define THEME_DIR_H +#ifndef __LABWC_THEME_DIR_H +#define __LABWC_THEME_DIR_H char *theme_dir(const char *theme_name); -#endif /* THEME_DIR_H */ +#endif /* __LABWC_THEME_DIR_H */ diff --git a/include/theme.h b/include/theme/theme.h similarity index 86% rename from include/theme.h rename to include/theme/theme.h index f22e9527..6833c079 100644 --- a/include/theme.h +++ b/include/theme/theme.h @@ -4,8 +4,8 @@ * Copyright Johan Malm 2020 */ -#ifndef THEME_H -#define THEME_H +#ifndef __LABWC_THEME_H +#define __LABWC_THEME_H #include #include @@ -23,4 +23,4 @@ extern struct theme theme; void theme_read(const char *theme_name); -#endif /* THEME_H */ +#endif /* __LABWC_THEME_H */ diff --git a/include/theme/xbm/parse.h b/include/theme/xbm/parse.h index 213c6567..3af8616e 100644 --- a/include/theme/xbm/parse.h +++ b/include/theme/xbm/parse.h @@ -4,8 +4,8 @@ * Copyright Johan Malm 2020 */ -#ifndef PARSE_H -#define PARSE_H +#ifndef __LABWC_PARSE_H +#define __LABWC_PARSE_H #include #include "theme/xbm/tokenize.h" @@ -24,4 +24,4 @@ struct pixmap xbm_create_pixmap(struct token *tokens); struct pixmap xbm_create_pixmap_builtin(const char *button); -#endif /* PARSE_H */ +#endif /* __LABWC_PARSE_H */ diff --git a/include/theme/xbm/tokenize.h b/include/theme/xbm/tokenize.h index c0a64b93..38324a59 100644 --- a/include/theme/xbm/tokenize.h +++ b/include/theme/xbm/tokenize.h @@ -4,8 +4,8 @@ * Copyright Johan Malm 2020 */ -#ifndef TOKENIZE_H -#define TOKENIZE_H +#ifndef __LABWC_TOKENIZE_H +#define __LABWC_TOKENIZE_H enum token_type { TOKEN_NONE = 0, @@ -37,4 +37,4 @@ struct token *xbm_tokenize(char *buffer); */ char *xbm_read_file(const char *filename); -#endif /* TOKENIZE_H */ +#endif /* __LABWC_TOKENIZE_H */ diff --git a/include/theme/xbm/xbm.h b/include/theme/xbm/xbm.h index 7e7670ed..47907f24 100644 --- a/include/theme/xbm/xbm.h +++ b/include/theme/xbm/xbm.h @@ -1,9 +1,8 @@ -#ifndef XBM_H -#define XBM_H +#ifndef __LABWC_XBM_H +#define __LABWC_XBM_H #include -#include "theme.h" #include "theme/xbm/parse.h" /** @@ -11,4 +10,4 @@ */ void xbm_load(struct wlr_renderer *renderer); -#endif /* XBM_H */ +#endif /* __LABWC_XBM_H */ diff --git a/src/action.c b/src/action.c index 8bbfb804..4861de9a 100644 --- a/src/action.c +++ b/src/action.c @@ -1,5 +1,5 @@ #include "labwc.h" -#include "spawn.h" +#include "common/spawn.h" #include diff --git a/src/common/spawn.c b/src/common/spawn.c index 62eb80e5..49250fc5 100644 --- a/src/common/spawn.c +++ b/src/common/spawn.c @@ -12,8 +12,8 @@ void spawn_async_no_shell(char const *command) return; } g_spawn_async(NULL, argv, NULL, - G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, NULL, &err); + G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, + NULL, NULL, &err); if (err) { g_message("%s", err->message); g_error_free(err); diff --git a/src/config/keybind.c b/src/config/keybind.c index 36c0985a..bbb47859 100644 --- a/src/config/keybind.c +++ b/src/config/keybind.c @@ -4,7 +4,8 @@ #include #include -#include "rcxml.h" +#include "config/keybind.h" +#include "config/rcxml.h" static uint32_t parse_modifier(const char *symname) { @@ -52,4 +53,3 @@ struct keybind *keybind_add(const char *keybind) memcpy(k->keysyms, keysyms, k->keysyms_len * sizeof(xkb_keysym_t)); return k; } - diff --git a/src/config/rcxml.c b/src/config/rcxml.c index dbdf9f84..8f25bf3c 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -10,7 +10,8 @@ #include #include -#include "rcxml.h" +#include "config/rcxml.h" +#include "config/keybind.h" #include "config/config-dir.h" #include "common/bug-on.h" diff --git a/src/debug/dbg.c b/src/debug/dbg.c index 0da3ffd9..817a4354 100644 --- a/src/debug/dbg.c +++ b/src/debug/dbg.c @@ -1,5 +1,6 @@ #include "labwc.h" -#include "rcxml.h" +#include "config/rcxml.h" +#include "config/keybind.h" static void show_one_xdg_view(struct view *view) { diff --git a/src/deco.c b/src/deco.c index 2b471d8c..d5a64ad6 100644 --- a/src/deco.c +++ b/src/deco.c @@ -5,7 +5,7 @@ */ #include "labwc.h" -#include "theme.h" +#include "theme/theme.h" /* Based on expected font height of Sans 8 */ #define TITLE_HEIGHT (14) diff --git a/src/main.c b/src/main.c index 2e8c39a0..1b0cefe5 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ #include "labwc.h" -#include "theme.h" -#include "spawn.h" +#include "theme/theme.h" #include "theme/xbm/xbm.h" +#include "common/spawn.h" struct server server = { 0 }; struct rcxml rc = { 0 }; diff --git a/src/output.c b/src/output.c index 895f93ef..dc0faf93 100644 --- a/src/output.c +++ b/src/output.c @@ -1,5 +1,5 @@ #include "labwc.h" -#include "theme.h" +#include "theme/theme.h" struct draw_data { struct wlr_renderer *renderer; diff --git a/src/theme/theme-dir.c b/src/theme/theme-dir.c index d2d90426..a78c5699 100644 --- a/src/theme/theme-dir.c +++ b/src/theme/theme-dir.c @@ -40,8 +40,8 @@ char *theme_dir(const char *theme_name) prefix = getenv(d.prefix); if (!prefix) continue; - snprintf(buf, sizeof(buf), "%s/%s/%s/openbox-3", - prefix, d.path, theme_name); + snprintf(buf, sizeof(buf), "%s/%s/%s/openbox-3", prefix, + d.path, theme_name); } else { snprintf(buf, sizeof(buf), "%s/%s/openbox-3", d.path, theme_name); diff --git a/src/theme/theme.c b/src/theme/theme.c index e972a107..8175482d 100644 --- a/src/theme/theme.c +++ b/src/theme/theme.c @@ -6,7 +6,7 @@ #include #include -#include "theme.h" +#include "theme/theme.h" #include "theme/theme-dir.h" static int hex_to_dec(char c) diff --git a/src/theme/xbm/xbm.c b/src/theme/xbm/xbm.c index 937a18f8..6f37462b 100644 --- a/src/theme/xbm/xbm.c +++ b/src/theme/xbm/xbm.c @@ -7,10 +7,11 @@ #include #include +#include "theme/theme.h" #include "theme/xbm/xbm.h" #include "theme/xbm/parse.h" #include "theme/theme-dir.h" -#include "rcxml.h" +#include "config/rcxml.h" /* built-in 6x6 buttons */ char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 }; @@ -29,7 +30,7 @@ static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer, } static struct wlr_texture *texture_from_builtin(struct wlr_renderer *renderer, - const char *button) + const char *button) { struct pixmap pixmap = xbm_create_pixmap_builtin(button); struct wlr_texture *texture = texture_from_pixmap(renderer, &pixmap); @@ -70,5 +71,6 @@ void xbm_load(struct wlr_renderer *r) { load_button(r, "close.xbm", &theme.xbm_close, close_button_normal); load_button(r, "max.xbm", &theme.xbm_maximize, max_button_normal); - load_button(r, "iconify.xbm", &theme.xbm_iconify, iconify_button_normal); + load_button(r, "iconify.xbm", &theme.xbm_iconify, + iconify_button_normal); } diff --git a/tests/t1000-rcxml-simple-parse.c b/tests/t1000-rcxml-simple-parse.c index e54fd2b2..5fcdda63 100644 --- a/tests/t1000-rcxml-simple-parse.c +++ b/tests/t1000-rcxml-simple-parse.c @@ -4,7 +4,7 @@ #include #include -#include "rcxml.h" +#include "config/rcxml.h" #include "tap.h" struct rcxml rc = { 0 }; diff --git a/tests/t1001-rcxml-nodenames-simple.c b/tests/t1001-rcxml-nodenames-simple.c index b90155bd..d371ddee 100644 --- a/tests/t1001-rcxml-nodenames-simple.c +++ b/tests/t1001-rcxml-nodenames-simple.c @@ -5,7 +5,7 @@ #include #include -#include "rcxml.h" +#include "config/rcxml.h" #include "tap.h" struct rcxml rc = { 0 }; diff --git a/tools/hex/Makefile b/tools/hex/Makefile index e62fee0a..bd60aae2 100644 --- a/tools/hex/Makefile +++ b/tools/hex/Makefile @@ -1,4 +1,4 @@ hex-color-average: hex-color-average.o clean: - rm -f hex-color-average + rm -f hex-color-average *.o diff --git a/tools/rcxml/rcxml-print-nodenames.c b/tools/rcxml/rcxml-print-nodenames.c index d5df9f38..6fd3c5e6 100644 --- a/tools/rcxml/rcxml-print-nodenames.c +++ b/tools/rcxml/rcxml-print-nodenames.c @@ -2,7 +2,7 @@ #include #include -#include "rcxml.h" +#include "config/rcxml.h" #include "common/buf.h" struct rcxml rc = { 0 }; diff --git a/tools/theme/Makefile b/tools/theme/Makefile index 4e83d616..82492008 100644 --- a/tools/theme/Makefile +++ b/tools/theme/Makefile @@ -1,8 +1,23 @@ CFLAGS = -g -Wall -Wextra -pedantic -std=c11 CFLAGS += -I../../include/ +CFLAGS += `pkg-config --cflags glib-2.0` ASAN_FLAGS = -O0 -fsanitize=address -fno-common -fno-omit-frame-pointer -rdynamic CFLAGS += $(ASAN_FLAGS) LDFLAGS += $(ASAN_FLAGS) -fuse-ld=gold +LDFLAGS += `pkg-config --cflags --libs glib-2.0 wlroots wayland-server` +LDFLAGS += -DWLR_USE_UNSTABLE + +SRCS = \ + theme-helper.c \ + ../../src/theme/theme.c \ + ../../src/theme/theme-dir.c all: - gcc $(CFLAGS) -o theme-helper theme-helper.c ../../src/theme/theme.c $(LDFLAGS) + gcc $(CFLAGS) -o theme-helper $(SRCS) $(LDFLAGS) + + +test: + XDG_DATA_HOME=../../data ./theme-helper labwc-default + +clean: + rm -f theme-helper *.o diff --git a/tools/theme/theme-helper.c b/tools/theme/theme-helper.c index 3c917d73..0bf3700d 100644 --- a/tools/theme/theme-helper.c +++ b/tools/theme/theme-helper.c @@ -1,13 +1,23 @@ #include #include -#include "../../include/theme.h" +#include "theme/theme.h" struct theme theme = { 0 }; -int main() +static void usage(const char *application) { - theme_read("../../data/themerc"); + printf("Usage: %s \n", application); + exit(1); +} + +int main(int argc, char **argv) +{ + if (argc < 2) + usage(argv[0]); + theme_read(argv[1]); + + printf("window_active_title_bg_color = "); for (int i=0; i < 4; i++) printf("%.2f; ", theme.window_active_title_bg_color[i]); printf("\n");