diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/sxwm.c | 31 | ||||
-rw-r--r-- | src/usercfg.h | 6 |
3 files changed, 34 insertions, 5 deletions
@@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -Wall -Wextra -O2 -g -Isrc +CFLAGS = -Wall -Wextra -O3 -g -Isrc LDFLAGS = -lX11 SRC_DIR = src @@ -31,6 +31,7 @@ static void hdl_map_req(XEvent *xev); static void hdl_unmap_ntf(XEvent *xev); static void other_wm(void); static int other_wm_err(Display *dpy, XErrorEvent *ee); +static unsigned long parse_col(const char *hex); static void quit(void); static void run(void); static void setup(void); @@ -43,6 +44,10 @@ static EventHandler evtable[LASTEvent]; static Display *dpy; static Window root; +static unsigned long border_foc_col; +static unsigned long border_ufoc_col; + + #include "usercfg.h" static void @@ -100,8 +105,8 @@ static void hdl_map_req(XEvent *xev) { XMapRequestEvent ev = xev->xmaprequest; - XSetWindowBorder(dpy, ev.window, WhitePixel(dpy, DefaultScreen(dpy))); - XSetWindowBorderWidth(dpy, ev.window, BORDERWIDTH); + XSetWindowBorder(dpy, ev.window, border_foc_col); + XSetWindowBorderWidth(dpy, ev.window, BORDER_WIDTH); XMapWindow(dpy, ev.window); XWindowAttributes wa; @@ -138,6 +143,25 @@ other_wm_err(Display *dpy, XErrorEvent *ee) if (dpy && ee) return 0; } +static unsigned long +parse_col(const char *hex) +{ + XColor col; + Colormap cmap = DefaultColormap(dpy, DefaultScreen(dpy)); + + if (!XParseColor(dpy, cmap, hex, &col)) { + fprintf(stderr, "sxwm: cannot parse color %s\n", hex); + return WhitePixel(dpy, DefaultScreen(dpy)); + } + + if (!XAllocColor(dpy, cmap, &col)) { + fprintf(stderr, "sxwm: cannot allocate color %s\n", hex); + return WhitePixel(dpy, DefaultScreen(dpy)); + } + + return col.pixel; +} + static void quit(void) { @@ -175,6 +199,9 @@ setup(void) evtable[KeyPress] = hdl_keypress; evtable[MapRequest] = hdl_map_req; evtable[UnmapNotify] = hdl_unmap_ntf; + + border_foc_col = parse_col(BORDER_FOC_COL); + border_ufoc_col = parse_col(BORDER_UFOC_COL); } static void diff --git a/src/usercfg.h b/src/usercfg.h index 24ba909..ea39c8e 100644 --- a/src/usercfg.h +++ b/src/usercfg.h @@ -4,11 +4,13 @@ #include <X11/keysym.h> #include "defs.h" -#define MOD ALT -#define BORDERWIDTH 2 +#define BORDER_WIDTH 2 +#define BORDER_FOC_COL "#00FF00" +#define BORDER_UFOC_COL "#FF0000" static const char *termcmd[] = {"st", NULL}; +#define MOD ALT static const Binding binds[] = { BIND(MOD, Return, termcmd), CALL(MOD|SHIFT, q, quit), |