From 46ea7c45aa0ea9804729ca536caabd5543d92f92 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 2 Jul 2008 11:04:17 +0200 Subject: [PATCH] Get rid of the color name, and generate a #RGBA value on the fly if needed. Signed-off-by: Pierre Habouzit Signed-off-by: Julien Danjou --- client.c | 2 +- common/draw.c | 8 ++++---- common/draw.h | 3 +-- lua.c | 10 ++++++++++ lua.h | 2 ++ statusbar.c | 4 ++-- titlebar.c | 6 +++--- widgets/graph.c | 4 ++-- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/client.c b/client.c index 1c767bba..12e03fa5 100644 --- a/client.c +++ b/client.c @@ -1280,7 +1280,7 @@ luaA_client_index(lua_State *L) lua_pushnumber(L, (*c)->border); break; case A_TK_BORDER_COLOR: - lua_pushstring(L, (*c)->border_color.name); + luaA_pushcolor(L, &(*c)->border_color); break; case A_TK_COORDS: lua_newtable(L); diff --git a/common/draw.c b/common/draw.c index 712d211f..263858cc 100644 --- a/common/draw.c +++ b/common/draw.c @@ -427,8 +427,8 @@ draw_setup_cairo_color_source(draw_context_t *ctx, area_t rect, const xcolor_t *pcolor_end) { cairo_pattern_t *pat = NULL; - bool has_center = pcolor_center->name[0] != '\0'; - bool has_end = pcolor_end->name[0] != '\0'; + bool has_center = pcolor_center->initialized; + bool has_end = pcolor_end->initialized; /* no need for a real pattern: */ if(!has_end && !has_center) @@ -1151,7 +1151,7 @@ xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen, color->green = hexa_color->green; color->blue = hexa_color->blue; color->alpha = alpha; - a_strcpy(color->name, sizeof(color->name), colstr); + color->initialized = true; p_delete(&hexa_color); return true; } @@ -1173,7 +1173,7 @@ xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen, color->blue = named_color->visual_blue; color->alpha = 0xffff; color->alpha = alpha; - a_strcpy(color->name, sizeof(color->name), colstr); + color->initialized = true; p_delete(&named_color); return true; } diff --git a/common/draw.h b/common/draw.h index 802f016e..4f0d2bd1 100644 --- a/common/draw.h +++ b/common/draw.h @@ -33,8 +33,7 @@ typedef struct { - /** Color name */ - char name[32]; + unsigned initialized : 1; uint32_t pixel; uint16_t red; uint16_t green; diff --git a/lua.c b/lua.c index f235dd6f..1d0a2fa7 100644 --- a/lua.c +++ b/lua.c @@ -653,3 +653,13 @@ luaA_on_timer(EV_P_ ev_timer *w, int revents) { luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0); } + +void +luaA_pushcolor(lua_State *L, const xcolor_t *c) +{ + uint8_t r = (unsigned)c->red * 0xff / 0xffff; + uint8_t g = (unsigned)c->green * 0xff / 0xffff; + uint8_t b = (unsigned)c->blue * 0xff / 0xffff; + uint8_t a = (unsigned)c->alpha * 0xff / 0xffff; + lua_pushfstring(L, "#%02x%02x%02x%02x", r, g, b, a); +} diff --git a/lua.h b/lua.h index 60b2ea1a..b268af5b 100644 --- a/lua.h +++ b/lua.h @@ -27,6 +27,7 @@ #include #include "common/util.h" +#include "common/draw.h" /** Object types */ typedef enum @@ -194,6 +195,7 @@ void luaA_pushpointer(lua_State *, void *, awesome_type_t); void luaA_cs_init(void); void luaA_cs_cleanup(void); void luaA_on_timer(EV_P_ ev_timer *w, int revents); +void luaA_pushcolor(lua_State *, const xcolor_t *c); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/statusbar.c b/statusbar.c index c956b6bd..3e83055e 100644 --- a/statusbar.c +++ b/statusbar.c @@ -516,10 +516,10 @@ luaA_statusbar_index(lua_State *L) lua_pushstring(L, draw_align_tostr((*statusbar)->align)); break; case A_TK_FG: - lua_pushstring(L, (*statusbar)->colors.fg.name); + luaA_pushcolor(L, &(*statusbar)->colors.fg); break; case A_TK_BG: - lua_pushstring(L, (*statusbar)->colors.bg.name); + luaA_pushcolor(L, &(*statusbar)->colors.bg); break; case A_TK_POSITION: lua_pushstring(L, position_tostr((*statusbar)->position)); diff --git a/titlebar.c b/titlebar.c index eb038942..9e14849c 100644 --- a/titlebar.c +++ b/titlebar.c @@ -538,13 +538,13 @@ luaA_titlebar_index(lua_State *L) lua_pushnumber(L, (*titlebar)->border.width); break; case A_TK_BORDER_COLOR: - lua_pushstring(L, (*titlebar)->border.color.name); + luaA_pushcolor(L, &(*titlebar)->border.color); break; case A_TK_FG: - lua_pushstring(L, (*titlebar)->colors.fg.name); + luaA_pushcolor(L, &(*titlebar)->colors.fg); break; case A_TK_BG: - lua_pushstring(L, (*titlebar)->colors.bg.name); + luaA_pushcolor(L, &(*titlebar)->colors.bg); break; default: return 0; diff --git a/widgets/graph.c b/widgets/graph.c index ba104eab..3dbc9734 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -443,10 +443,10 @@ luaA_graph_index(lua_State *L, awesome_token_t token) lua_pushnumber(L, d->width); break; case A_TK_BORDER_COLOR: - lua_pushstring(L, d->border_color.name); + luaA_pushcolor(L, &d->border_color); break; case A_TK_BG: - lua_pushstring(L, d->bg.name); + luaA_pushcolor(L, &d->bg); break; case A_TK_GROW: switch(d->grow)