From ee142957105c28641604c89278c2cf37fc87636c Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Sun, 18 Jan 2009 23:53:03 +0000 Subject: [PATCH] Unscrew colors on machines that use 16 bit color. I am talking to you zaurus and sparc! from dwc --- scrotwm.c | 41 ++++++++++++++++++++++++++++++++++++----- scrotwm.conf | 10 +++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/scrotwm.c b/scrotwm.c index 29f4694..6ee2f9e 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -210,6 +210,30 @@ union arg { char **argv; }; +unsigned long +name_to_color(char *colorname) +{ + Colormap cmap; + Status r; + XColor screen_def, exact_def; + unsigned long result = 0; + char cname[32] = "#"; + + cmap = DefaultColormap(display, screen); + r = XAllocNamedColor(display, cmap, colorname, &screen_def, &exact_def); + if (!r) { + strlcat(cname, colorname + 2, sizeof cname - 1); + r = XAllocNamedColor(display, cmap, cname, &screen_def, + &exact_def); + } + if (r) + result = screen_def.pixel; + else + fprintf(stderr, "color '%s' not found.\n", colorname); + + return (result); +} + /* conf file stuff */ #define SWM_CONF_WS "\n= \t" #define SWM_CONF_FILE "scrotwm.conf" @@ -252,13 +276,13 @@ conf_load(char *filename) bar_enabled = atoi(val); else if (!strncmp(var, "bar_border", strlen("bar_border"))) - bar_border = strtol(val, NULL, 16); + bar_border = name_to_color(val); else if (!strncmp(var, "bar_color", strlen("bar_color"))) - bar_color = strtol(val, NULL, 16); + bar_color = name_to_color(val); else if (!strncmp(var, "bar_font_color", strlen("bar_font_color"))) - bar_font_color = strtol(val, NULL, 16); + bar_font_color = name_to_color(val); else if (!strncmp(var, "bar_font", strlen("bar_font"))) asprintf(&bar_fonts[0], "%s", val); else @@ -267,10 +291,10 @@ conf_load(char *filename) case 'c': if (!strncmp(var, "color_focus", strlen("color_focus"))) - color_focus = strtol(val, NULL, 16); + color_focus = name_to_color(val); else if (!strncmp(var, "color_unfocus", strlen("color_unfocus"))) - color_unfocus = strtol(val, NULL, 16); + color_unfocus = name_to_color(val); else goto bad; break; @@ -1458,6 +1482,13 @@ main(int argc, char *argv[]) root = RootWindow(display, screen); astate = XInternAtom(display, "WM_STATE", False); + /* set default colors */ + color_focus = name_to_color("red"); + color_unfocus = name_to_color("rgb:88/88/88"); + bar_border = name_to_color("rgb:00/80/80"); + bar_color = name_to_color("black"); + bar_font_color = name_to_color("rgb:a0/a0/a0"); + /* look for local and global conf file */ pwd = getpwuid(getuid()); if (pwd == NULL) diff --git a/scrotwm.conf b/scrotwm.conf index 8b11ae0..83f0bd5 100644 --- a/scrotwm.conf +++ b/scrotwm.conf @@ -1,12 +1,12 @@ # colors for focussed and unfocussed window borders -color_focus = 0xff0000 -color_unfocus = 0x888888 +color_focus = red +color_unfocus = rgb:88/88/88 # bar settings bar_enabled = 1 -bar_border = 0x008080 -bar_color = 0x000000 -bar_font_color = 0xa0a0a0 +bar_border = rgb:00/80/80 +bar_color = black +bar_font_color = rgb:a0/a0/a0 bar_font = -*-terminus-*-*-*-*-*-*-*-*-*-*-*-* # spawn app -- 1.7.10.4