From 65bcf170ed0ee7462824e403b26da75935c3d6b3 Mon Sep 17 00:00:00 2001 From: Atsutane Date: Fri, 29 May 2009 16:33:48 +0200 Subject: [PATCH] Introduced color setting. --- include/config.h | 15 ++++++++++++ src/config.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++- src/layout.c | 26 ++++++++++----------- 3 files changed, 86 insertions(+), 14 deletions(-) diff --git a/include/config.h b/include/config.h index 59c6866f..33aaeb49 100644 --- a/include/config.h +++ b/include/config.h @@ -7,6 +7,21 @@ extern Config config; struct Config { const char *terminal; const char *font; + + /* Color codes are stored here */ + char *client_focused_background_active; + char *client_focused_background_inactive; + char *client_focused_text; + char *client_focused_border; + char *client_unfocused_background; + char *client_unfocused_text; + char *client_unfocused_border; + char *bar_focused_background; + char *bar_focused_text; + char *bar_focused_border; + char *bar_unfocused_background; + char *bar_unfocused_text; + char *bar_unfocused_border; }; /** diff --git a/src/config.c b/src/config.c index ab9ea9aa..c4d940ae 100644 --- a/src/config.c +++ b/src/config.c @@ -52,6 +52,21 @@ void load_configuration(const char *override_configpath) { if (config.name == NULL) \ die("You did not specify required configuration option " #name "\n"); +#define OPTION_COLOR(opt, name) \ + if (strcasecmp(key, opt) == 0) { \ + config.name = sstrdup(value); \ + continue; \ + } + +#define VERIFY_COLOR(name, def) \ + if (config.name == NULL) { \ + config.name = (char *)malloc(7); \ + memset(config.name, 0, 7); \ + } \ + if ((strlen(config.name) != 7) || (config.name[0] != '#')) { \ + strncpy(config.name, def, 7); \ + } + /* Clear the old config or initialize the data structure */ memset(&config, 0, sizeof(config)); @@ -85,6 +100,34 @@ void load_configuration(const char *override_configpath) { OPTION_STRING(terminal); OPTION_STRING(font); + /* Colors */ + OPTION_COLOR("client.focused.background.active", + client_focused_background_active); + OPTION_COLOR("client.focused.background.inactive", + client_focused_background_inactive); + OPTION_COLOR("client.focused.text", + client_focused_text); + OPTION_COLOR("client.focused.border", + client_focused_border); + OPTION_COLOR("client.unfocused.background", + client_unfocused_background); + OPTION_COLOR("client.unfocused.text", + client_unfocused_text); + OPTION_COLOR("client.unfocused.border", + client_unfocused_border); + OPTION_COLOR("bar.focused.background", + bar_focused_background); + OPTION_COLOR("bar.focused.text", + bar_focused_text); + OPTION_COLOR("bar.focused.border", + bar_focused_border); + OPTION_COLOR("bar.unfocused.background", + bar_unfocused_background); + OPTION_COLOR("bar.unfocused.text", + bar_unfocused_text); + OPTION_COLOR("bar.unfocused.border", + bar_unfocused_border); + /* exec-lines (autostart) */ if (strcasecmp(key, "exec") == 0) { struct Autostart *new = smalloc(sizeof(struct Autostart)); @@ -176,8 +219,22 @@ void load_configuration(const char *override_configpath) { } fclose(handle); + VERIFY_COLOR(client_focused_background_active, "#285577"); + VERIFY_COLOR(client_focused_background_inactive, "#555555"); + VERIFY_COLOR(client_focused_text, "#ffffff"); + VERIFY_COLOR(client_focused_border, "#4c7899"); + VERIFY_COLOR(client_unfocused_background,"#222222"); + VERIFY_COLOR(client_unfocused_text, "#888888"); + VERIFY_COLOR(client_unfocused_border, "#333333"); + VERIFY_COLOR(bar_focused_background, "#285577"); + VERIFY_COLOR(bar_focused_text, "#ffffff"); + VERIFY_COLOR(bar_focused_border, "#4c7899"); + VERIFY_COLOR(bar_unfocused_background, "#222222"); + VERIFY_COLOR(bar_unfocused_text, "#888888"); + VERIFY_COLOR(bar_unfocused_border, "#333333"); + REQUIRED_OPTION(terminal); REQUIRED_OPTION(font); - + return; } diff --git a/src/layout.c b/src/layout.c index 1f0a6d87..32f52134 100644 --- a/src/layout.c +++ b/src/layout.c @@ -112,16 +112,16 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw if (client->floating || client->container->currently_focused == client) { /* Distinguish if the window is currently focused… */ if (client->floating || CUR_CELL->currently_focused == client) - background_color = get_colorpixel(conn, "#285577"); + background_color = get_colorpixel(conn, config.client_focused_background_active); /* …or if it is the focused window in a not focused container */ - else background_color = get_colorpixel(conn, "#555555"); + else background_color = get_colorpixel(conn, config.client_focused_background_inactive); - text_color = get_colorpixel(conn, "#ffffff"); - border_color = get_colorpixel(conn, "#4c7899"); + text_color = get_colorpixel(conn, config.client_focused_text); + border_color = get_colorpixel(conn, config.client_focused_border); } else { - background_color = get_colorpixel(conn, "#222222"); - text_color = get_colorpixel(conn, "#888888"); - border_color = get_colorpixel(conn, "#333333"); + background_color = get_colorpixel(conn, config.client_unfocused_background); + text_color = get_colorpixel(conn, config.client_unfocused_text); + border_color = get_colorpixel(conn, config.client_unfocused_border); } /* Our plan is the following: @@ -409,13 +409,13 @@ static void render_internal_bar(xcb_connection_t *conn, Workspace *r_ws, int wid black = get_colorpixel(conn, "#000000"); - background_color[SET_NORMAL] = get_colorpixel(conn, "#222222"); - text_color[SET_NORMAL] = get_colorpixel(conn, "#888888"); - border_color[SET_NORMAL] = get_colorpixel(conn, "#333333"); + background_color[SET_NORMAL] = get_colorpixel(conn, config.bar_unfocused_background); + text_color[SET_NORMAL] = get_colorpixel(conn, config.bar_unfocused_text); + border_color[SET_NORMAL] = get_colorpixel(conn, config.bar_unfocused_border); - background_color[SET_FOCUSED] = get_colorpixel(conn, "#285577"); - text_color[SET_FOCUSED] = get_colorpixel(conn, "#ffffff"); - border_color[SET_FOCUSED] = get_colorpixel(conn, "#4c7899"); + background_color[SET_FOCUSED] = get_colorpixel(conn, config.bar_focused_background); + text_color[SET_FOCUSED] = get_colorpixel(conn, config.bar_focused_text); + border_color[SET_FOCUSED] = get_colorpixel(conn, config.bar_focused_border); /* Fill the whole bar in black */ xcb_change_gc_single(conn, screen->bargc, XCB_GC_FOREGROUND, black); -- 2.39.5