mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
include/: refactor header files more
This commit is contained in:
parent
53266a0d5a
commit
4d1363dcae
32 changed files with 130 additions and 78 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
10
include/common/spawn.h
Normal file
10
include/common/spawn.h
Normal file
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
18
include/config/keybind.h
Normal file
18
include/config/keybind.h
Normal file
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef SPAWN_H
|
||||
#define SPAWN_H
|
||||
|
||||
void spawn_async_no_shell(char const *command);
|
||||
|
||||
#endif /* SPAWN_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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "labwc.h"
|
||||
#include "spawn.h"
|
||||
#include "common/spawn.h"
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "labwc.h"
|
||||
#include "theme.h"
|
||||
#include "theme/theme.h"
|
||||
|
||||
struct draw_data {
|
||||
struct wlr_renderer *renderer;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "rcxml.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "tap.h"
|
||||
|
||||
struct rcxml rc = { 0 };
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rcxml.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "tap.h"
|
||||
|
||||
struct rcxml rc = { 0 };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
hex-color-average: hex-color-average.o
|
||||
|
||||
clean:
|
||||
rm -f hex-color-average
|
||||
rm -f hex-color-average *.o
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue