diff --git a/Makefile b/Makefile index 77bcbc0..fadb218 100644 --- a/Makefile +++ b/Makefile @@ -17,16 +17,23 @@ options: .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 a2ac963..daf66b3 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 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 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/xresources.defaults b/xresources.defaults new file mode 100644 index 0000000..7f1d86a --- /dev/null +++ b/xresources.defaults @@ -0,0 +1,7 @@ +# define DWM_FONT "monospace" +# define DWM_FOREGROUND "#93a1a1" +# define DWM_BACKGROUND "#002b36" +# define DWM_BORDER "#93a1a1" +# define DWM_SELFOREGROUND "#073642" +# define DWM_SELBACKGROUND "#2aa198" +# define DWM_SELBORDER "#cb4b16" diff --git a/xresources.list b/xresources.list new file mode 100644 index 0000000..2b8421f --- /dev/null +++ b/xresources.list @@ -0,0 +1,7 @@ +S font +S foreground +S background +S border background +S selforeground background +S selbackground foreground +S selborder foreground diff --git a/xtheme b/xtheme new file mode 100755 index 0000000..8fa5f08 --- /dev/null +++ b/xtheme @@ -0,0 +1,49 @@ +#!/bin/sh + +prefix=dwm +resfile=xresources.list +themeout=theme.h +# themedefaults=themes/$prefix-defaults.h +themedefaults=xresources.defaults + +rm -f $themeout + +cat "$resfile" | while read T R A +do + m=$(echo "$prefix"'_'"$R" | tr '[:lower:]' '[:upper:]') + + s='' + [[ "$T" == "S" ]] && s=\" + + l='' + + for r in "$R" "$A" + do + [[ "$r" == '' ]] && continue + + e=0 + + for p in "$prefix" '' + do + l="$( \ + xrdb -query \ + | grep -P "^$p\*?\.?$r:\s*\S*$" -m 1 \ + | sed "s/^$p\*\?\.\?$r:\s*\(\S*\)$/# define $m $s\1$s/" \ + )" + + if [[ "$l" != '' ]] + then + e=1 + echo "$l" >> $themeout + break + fi + done + + [[ $e == 1 ]] && break + done + + if [[ "$l" == '' ]] + then + cat "$themedefaults" | grep -P "^# define $m " -m 1 >> $themeout + fi +done