diff --git a/Makefile b/Makefile index ffa69b4..a25ff58 100644 --- a/Makefile +++ b/Makefile @@ -11,16 +11,23 @@ all: dwm .c.o: ${CC} -c ${CFLAGS} $< -${OBJ}: config.h config.mk +${OBJ}: config.h theme_beg.h config.mk -config.h: - cp config.def.h $@ +theme.h: + ./xtheme + +theme_beg.h: + ./themesetup + +config.h: theme.h + cp -n config.def.h $@ dwm: ${OBJ} ${CC} -o $@ ${OBJ} ${LDFLAGS} + rm -f theme_{beg,end}.h clean: - rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz + rm -f dwm ${OBJ} theme_{beg,end}.h dwm-${VERSION}.tar.gz dist: clean mkdir -p dwm-${VERSION} diff --git a/config.def.h b/config.def.h index 9efa774..4a1fda7 100644 --- a/config.def.h +++ b/config.def.h @@ -1,11 +1,15 @@ /* See LICENSE file for copyright and license details. */ +/* theme management */ +# include "theme_beg.h" /* this is a compile-time generated header file */ +# include "theme.h" + /* appearance */ -static const unsigned int borderpx = 1; /* border pixel of windows */ -static const unsigned int snap = 32; /* snap pixel */ -static const int showbar = 1; /* 0 means no bar */ -static const int topbar = 1; /* 0 means bottom bar */ -static const char *fonts[] = { "monospace:size=10" }; +static const unsigned int borderpx = DWM_BORDERPX; /* border pixel of windows */ +static const unsigned int snap = DWM_SNAP; /* snap pixel */ +static const int showbar = DWM_SHOWBAR; /* 0 means no bar */ +static const int topbar = DWM_TOPBAR; /* 0 means bottom bar */ +static const char *fonts[] = DWM_FONT; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; static const char col_gray2[] = "#444444"; @@ -13,9 +17,9 @@ static const char col_gray3[] = "#bbbbbb"; static const char col_gray4[] = "#eeeeee"; static const char col_cyan[] = "#005577"; static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, + /* fg bg border */ + [SchemeNorm] = { DWM_FOREGROUND, DWM_BACKGROUND, DWM_BORDER }, + [SchemeSel] = { DWM_SELFOREGROUND, DWM_SELBACKGROUND, DWM_SELBORDER }, }; /* tagging */ @@ -60,6 +64,9 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; +/* theme management */ +# include "theme_end.h" /* this is a compile-time generated header file */ + static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, diff --git a/themesetup b/themesetup new file mode 100755 index 0000000..e8710c1 --- /dev/null +++ b/themesetup @@ -0,0 +1,5 @@ +#!/bin/sh + +echo \# if $(cat theme.h | cut -d' ' -f3 | sed "s/^/defined /;s/$/ ||/" | tr "\n" " ") 0 > theme_beg.h +echo -e "# error (conflicting macro names)\n# endif" >> theme_beg.h +cat theme.h | cut -d' ' -f3 | sed "s/^/# undef /;" > theme_end.h diff --git a/xtable.md b/xtable.md new file mode 100644 index 0000000..ff87701 --- /dev/null +++ b/xtable.md @@ -0,0 +1,13 @@ +| TYPE | RESOURCE | DEFAULT VALUE | [ALTERNATIVE RESOURCE] | +|:---------:|:-----------------:|:---------------------:|:-------------------------:| +| U | borderpx | 1 | | +| U | snap | 32 | | +| I | showbar | 1 | | +| I | topbar | 1 | | +| SA | font | monospace:size=10 | | +| S | foreground | #93a1a1 | | +| S | background | #002b36 | | +| S | border | #93a1a1 | background | +| S | selforeground | #073642 | background | +| S | selbackground | #2aa198 | foreground | +| S | selborder | #cb4b16 | foreground | diff --git a/xtheme b/xtheme new file mode 100755 index 0000000..b13d10a --- /dev/null +++ b/xtheme @@ -0,0 +1,53 @@ +#!/bin/sh + +prefix=dwm +themeout=theme.h +xtable=xtable.md + +rm -f $themeout + +set_resource () +{ + T=$1 + M=$2 + V=$3 + + case $T in + S) + V=\"$V\" + ;; + SA) + V="{\"$(echo $V | sed 's/, /", "/g')\"}" + esac + + [[ $V == '{""}' ]] && V="{}" + + echo "# define $M $V" >> $themeout +} + +cat "$xtable" | + sed '1,2d;s/\t*|\t*/|/g;s/\(^|\)\|\(|$\)//g' | + while IFS='|' read T R D A + do + m=$(echo "$prefix"'_'"$R" | tr '[:lower:]' '[:upper:]') + + l='' + + for r in "$R" "$A" + do + [[ "$r" == '' ]] && continue + + l=$(xgetres "$prefix.$r") + + if [[ "$l" != '' ]] + then + set_resource $T $m "$l" + break + fi + done + + [[ "$l" == '' ]] && + set_resource $T $m "$D" + done + +exit 0