Get rid of the color name, and generate a #RGBA value on the fly if needed.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Pierre Habouzit 2008-07-02 11:04:17 +02:00 committed by Julien Danjou
parent 924078c898
commit 46ea7c45aa
8 changed files with 25 additions and 14 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -33,8 +33,7 @@
typedef struct
{
/** Color name */
char name[32];
unsigned initialized : 1;
uint32_t pixel;
uint16_t red;
uint16_t green;

10
lua.c
View File

@ -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);
}

2
lua.h
View File

@ -27,6 +27,7 @@
#include <lauxlib.h>
#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

View File

@ -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));

View File

@ -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;

View File

@ -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)