]> git.mdlowis.com Git - proto/labwc.git/commitdiff
include/: refactor header files more
authorJohan Malm <jgm323@gmail.com>
Mon, 3 Aug 2020 19:56:38 +0000 (20:56 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 3 Aug 2020 19:56:38 +0000 (20:56 +0100)
32 files changed:
README.md
data/themes/labwc-default/openbox-3/themerc [moved from data/themerc with 100% similarity]
include/common/buf.h
include/common/bug-on.h
include/common/spawn.h [new file with mode: 0644]
include/config/config-dir.h
include/config/keybind.h [new file with mode: 0644]
include/config/rcxml.h [moved from include/rcxml.h with 55% similarity]
include/labwc.h
include/spawn.h [deleted file]
include/theme/theme-dir.h
include/theme/theme.h [moved from include/theme.h with 86% similarity]
include/theme/xbm/parse.h
include/theme/xbm/tokenize.h
include/theme/xbm/xbm.h
src/action.c
src/common/spawn.c
src/config/keybind.c
src/config/rcxml.c
src/debug/dbg.c
src/deco.c
src/main.c
src/output.c
src/theme/theme-dir.c
src/theme/theme.c
src/theme/xbm/xbm.c
tests/t1000-rcxml-simple-parse.c
tests/t1001-rcxml-nodenames-simple.c
tools/hex/Makefile
tools/rcxml/rcxml-print-nodenames.c
tools/theme/Makefile
tools/theme/theme-helper.c

index b6643dbd7ac31667b74707262d3a732479f36f05..8303a278a2334837d91553d7971439a06a0ecb0c 100644 (file)
--- 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:
 
index c718488812990031ca44f21f95087460eb7b8eb7..f732bb5f287ff873a4958d5564725eabefba2836 100644 (file)
@@ -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 <stdio.h>
 #include <stdlib.h>
@@ -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 */
index c9c3be51c0266bf2033a0242d26afd0ac801f82d..aa5f7f3ffdbb5e1f15f1dfeb7709f0a3bad11d60 100644 (file)
@@ -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 (file)
index 0000000..10394a1
--- /dev/null
@@ -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 */
index bf74960f4f2f9cb7175346b7123fd40ee635825d..19ae130390795b71ceaed91df31d6c23d46b2008 100644 (file)
@@ -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 (file)
index 0000000..ce57caf
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __LABWC_KEYBIND_H
+#define __LABWC_KEYBIND_H
+
+#include <wlr/types/wlr_keyboard.h>
+#include <xkbcommon/xkbcommon.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);
+
+#endif /* __LABWC_KEYBIND_H */
similarity index 55%
rename from include/rcxml.h
rename to include/config/rcxml.h
index eda86a13de6fbaf0051ff5b0613c13ccdc056909..0b5484a55db214d3dce7db97e707ebf9702cae98 100644 (file)
@@ -1,25 +1,12 @@
-#ifndef RCXML_H
-#define RCXML_H
+#ifndef __LABWC_RCXML_H
+#define __LABWC_RCXML_H
 
 #include <stdio.h>
 #include <stdbool.h>
-#include <wlr/types/wlr_keyboard.h>
 #include <wayland-server-core.h>
-#include <xkbcommon/xkbcommon.h>
 
 #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 */
index 84d73d3d36f19068f43dab50ec6e47aa29323772..aec9fded0024fcf564590195af73713c4f37a38e 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef LABWC_H
-#define LABWC_H
+#ifndef __LABWC_H
+#define __LABWC_H
 
 #define _POSIX_C_SOURCE 200809L
 #include <getopt.h>
@@ -29,7 +29,8 @@
 #include <wlr/xwayland.h>
 #include <xkbcommon/xkbcommon.h>
 
-#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 (file)
index 730bb08..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef SPAWN_H
-#define SPAWN_H
-
-void spawn_async_no_shell(char const *command);
-
-#endif /* SPAWN_H */
index 87c5c3d01ed3036f3f3a54a0a2ce9725ad2be290..9ebb09af7c7829566551c27ab2bc0669ee5e07f8 100644 (file)
@@ -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 */
similarity index 86%
rename from include/theme.h
rename to include/theme/theme.h
index f22e9527ba36297eaccd551a1c4874bf818183e6..6833c07969ebbae78c7fd94cb6df05440748a0e4 100644 (file)
@@ -4,8 +4,8 @@
  * Copyright Johan Malm 2020
  */
 
-#ifndef THEME_H
-#define THEME_H
+#ifndef __LABWC_THEME_H
+#define __LABWC_THEME_H
 
 #include <stdio.h>
 #include <wlr/render/wlr_renderer.h>
@@ -23,4 +23,4 @@ extern struct theme theme;
 
 void theme_read(const char *theme_name);
 
-#endif /* THEME_H */
+#endif /* __LABWC_THEME_H */
index 213c656731bce2eb7c3416f09eeb85c542e88c05..3af8616e32e3b5eeca60cbcb3afbde3eb7fbb577 100644 (file)
@@ -4,8 +4,8 @@
  * Copyright Johan Malm 2020
  */
 
-#ifndef PARSE_H
-#define PARSE_H
+#ifndef __LABWC_PARSE_H
+#define __LABWC_PARSE_H
 
 #include <stdint.h>
 #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 */
index c0a64b93995e9e0f950f237154110061239f1ffb..38324a597b6e76e261ce693674de6e6f71c3d7ec 100644 (file)
@@ -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 */
index 7e7670ed027429deba62b6085d24b9281b151a5a..47907f246335366a4a2a4644c968433bf79fa47d 100644 (file)
@@ -1,9 +1,8 @@
-#ifndef XBM_H
-#define XBM_H
+#ifndef __LABWC_XBM_H
+#define __LABWC_XBM_H
 
 #include <wlr/render/wlr_renderer.h>
 
-#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 */
index 8bbfb80430116167e8753e959cb5bb360a54f26e..4861de9aa6d881b67e919e92443018248093a2bd 100644 (file)
@@ -1,5 +1,5 @@
 #include "labwc.h"
-#include "spawn.h"
+#include "common/spawn.h"
 
 #include <strings.h>
 
index 62eb80e552372e30033aeb4b48bdbe5c78a6d093..49250fc5037e94b2c272922b45a17dc88e6bef6d 100644 (file)
@@ -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);
index 36c0985a573cacb67181c59fc647a0fc3bdbeb6e..bbb47859c7b88cc9e0e5e6cd2af2c267cade8a68 100644 (file)
@@ -4,7 +4,8 @@
 #include <string.h>
 #include <glib.h>
 
-#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;
 }
-
index dbdf9f841ba1929b2afa0df511120a2b8bac2436..8f25bf3c3fa37618245985e13b43ee30ec942e20 100644 (file)
@@ -10,7 +10,8 @@
 #include <fcntl.h>
 #include <wayland-server-core.h>
 
-#include "rcxml.h"
+#include "config/rcxml.h"
+#include "config/keybind.h"
 #include "config/config-dir.h"
 #include "common/bug-on.h"
 
index 0da3ffd977af99130ba9232e2c9f5f8b92bda594..817a43549196aa32646159e6780827bc52b29177 100644 (file)
@@ -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)
 {
index 2b471d8cda776c76d6281d8bb39354276db01c85..d5a64ad61ff55efa6e57f5253611344e87f9fcf3 100644 (file)
@@ -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)
index 2e8c39a086707b15d3b33f08df6a3bebfa313403..1b0cefe5fc4b2cc20e5835684889f0beab1fa8f5 100644 (file)
@@ -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 };
index 895f93eff1d4a170306877a979e11df83d22a81f..dc0faf9353ac968aa24d2d2006505575caaca147 100644 (file)
@@ -1,5 +1,5 @@
 #include "labwc.h"
-#include "theme.h"
+#include "theme/theme.h"
 
 struct draw_data {
        struct wlr_renderer *renderer;
index d2d90426f493b3fc94188201446bc7f0cde002a6..a78c569913061747c82a1c2a87cd3501cdf22dee 100644 (file)
@@ -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);
index e972a10780429fb1062bf4c244bf53fc404dce88..8175482dddc1681404bd503c0f188acc08bb1d27 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdbool.h>
 #include <glib.h>
 
-#include "theme.h"
+#include "theme/theme.h"
 #include "theme/theme-dir.h"
 
 static int hex_to_dec(char c)
index 937a18f8cee1238a61608131ebf5ef26130a31e3..6f37462b2cde70cb4e58aa3b724c88e098252300 100644 (file)
@@ -7,10 +7,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#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);
 }
index e54fd2b26c91c25a3a663603f408d34dc69f903c..5fcdda63afda7402e81bf854e12bb6bb74c892c7 100644 (file)
@@ -4,7 +4,7 @@
 #include <unistd.h>
 #include <stdbool.h>
 
-#include "rcxml.h"
+#include "config/rcxml.h"
 #include "tap.h"
 
 struct rcxml rc = { 0 };
index b90155bdada953b3740a0e6351c00bff75d389ef..d371ddee4026a8dbb5758f2dbc4f815c66844663 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdbool.h>
 #include <string.h>
 
-#include "rcxml.h"
+#include "config/rcxml.h"
 #include "tap.h"
 
 struct rcxml rc = { 0 };
index e62fee0a15e86f9df78d0db7f4d420a9dfdd36e4..bd60aae227ec6579172f337e3f5696c91fb43195 100644 (file)
@@ -1,4 +1,4 @@
 hex-color-average: hex-color-average.o
 
 clean:
-       rm -f hex-color-average
+       rm -f hex-color-average *.o
index d5df9f38bed9ca558c064357c7a3bf840c066eb3..6fd3c5e6e99045f80327ef1dc7f5e40ad0c1ca26 100644 (file)
@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "rcxml.h"
+#include "config/rcxml.h"
 #include "common/buf.h"
 
 struct rcxml rc = { 0 };
index 4e83d61603d0c5599d829e04cd6d2bcaa6140e56..82492008526ef518b545a94b3998698a3bbb924e 100644 (file)
@@ -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
index 3c917d734f4a688bbd668af9e3701d804e063d7e..0bf3700d4b3f3a821cb7f75e153be0c41941ec26 100644 (file)
@@ -1,13 +1,23 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#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 <theme-name>\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");