draw: add char len as arg of xcolor_init()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-10 15:30:16 +02:00
parent 0e06789714
commit 36fd44d1a0
10 changed files with 108 additions and 122 deletions

View File

@ -400,8 +400,8 @@ main(int argc, char **argv)
/* init default font and colors */ /* init default font and colors */
globalconf.font = draw_font_new(globalconf.connection, globalconf.default_screen, "sans 8"); globalconf.font = draw_font_new(globalconf.connection, globalconf.default_screen, "sans 8");
xcolor_init(&globalconf.colors.fg, globalconf.connection, globalconf.default_screen, "black"); xcolor_init(&globalconf.colors.fg, globalconf.connection, globalconf.default_screen, "black", sizeof("black"));
xcolor_init(&globalconf.colors.bg, globalconf.connection, globalconf.default_screen, "white"); xcolor_init(&globalconf.colors.bg, globalconf.connection, globalconf.default_screen, "white", sizeof("white"));
/* init cursors */ /* init cursors */
globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, CURSOR_LEFT_PTR); globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, CURSOR_LEFT_PTR);

View File

@ -1143,8 +1143,8 @@ luaA_client_newindex(lua_State *L)
client_setborder(*c, luaL_checknumber(L, 3)); client_setborder(*c, luaL_checknumber(L, 3));
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len))
&& xcolor_init(&(*c)->border_color, globalconf.connection, (*c)->phys_screen, buf)) && xcolor_init(&(*c)->border_color, globalconf.connection, (*c)->phys_screen, buf, len))
{ {
xcb_change_window_attributes(globalconf.connection, (*c)->win, xcb_change_window_attributes(globalconf.connection, (*c)->win,
XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel); XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);

View File

@ -222,7 +222,11 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
{ {
case A_TK_COLOR: case A_TK_COLOR:
data->has_bg_color = xcolor_init(&data->bg_color, data->connection, data->phys_screen, *values); data->has_bg_color = xcolor_init(&data->bg_color,
data->connection,
data->phys_screen,
*values,
a_strlen(*values));
break; break;
case A_TK_IMAGE: case A_TK_IMAGE:
if(data->bg_image) if(data->bg_image)
@ -242,7 +246,8 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
{ {
case A_TK_COLOR: case A_TK_COLOR:
xcolor_init(&data->border.color, data->connection, data->phys_screen, *values); xcolor_init(&data->border.color, data->connection,
data->phys_screen, *values, a_strlen(*values));
break; break;
case A_TK_WIDTH: case A_TK_WIDTH:
data->border.width = atoi(*values); data->border.width = atoi(*values);
@ -260,7 +265,7 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
break; break;
case A_TK_SHADOW: case A_TK_SHADOW:
xcolor_init(&data->shadow.color, data->connection, xcolor_init(&data->shadow.color, data->connection,
data->phys_screen, *values); data->phys_screen, *values, a_strlen(*values));
break; break;
case A_TK_SHADOW_OFFSET: case A_TK_SHADOW_OFFSET:
data->shadow.offset = atoi(*values); data->shadow.offset = atoi(*values);
@ -1088,14 +1093,13 @@ draw_align_tostr(alignment_t a)
*/ */
bool bool
xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen, xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen,
const char *colstr) const char *colstr, ssize_t len)
{ {
xcb_screen_t *s = xutil_screen_get(conn, phys_screen); xcb_screen_t *s = xutil_screen_get(conn, phys_screen);
unsigned long colnum; unsigned long colnum;
uint16_t red, green, blue, alpha = 0xffff; uint16_t red, green, blue, alpha = 0xffff;
ssize_t len;
if(!(len = a_strlen(colstr))) if(!len)
return false; return false;
/* The color is given in RGB value */ /* The color is given in RGB value */

View File

@ -218,7 +218,7 @@ area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, ssize_
alignment_t draw_align_fromstr(const char *, ssize_t); alignment_t draw_align_fromstr(const char *, ssize_t);
const char *draw_align_tostr(alignment_t); const char *draw_align_tostr(alignment_t);
bool xcolor_init(xcolor_t *c, xcb_connection_t *, int, const char *); bool xcolor_init(xcolor_t *c, xcb_connection_t *, int, const char *, ssize_t);
void area_array_remove(area_array_t *, area_t); void area_array_remove(area_array_t *, area_t);

9
lua.c
View File

@ -357,16 +357,17 @@ static int
luaA_colors_set(lua_State *L) luaA_colors_set(lua_State *L)
{ {
const char *buf; const char *buf;
size_t len;
luaA_checktable(L, 1); luaA_checktable(L, 1);
if((buf = luaA_getopt_string(L, 1, "fg", NULL))) if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len)))
xcolor_init(&globalconf.colors.fg, globalconf.connection, xcolor_init(&globalconf.colors.fg, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
if((buf = luaA_getopt_string(L, 1, "bg", NULL))) if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len)))
xcolor_init(&globalconf.colors.bg, globalconf.connection, xcolor_init(&globalconf.colors.bg, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
return 0; return 0;
} }

View File

@ -440,18 +440,15 @@ luaA_statusbar_new(lua_State *L)
sb->name = a_strdup(buf); sb->name = a_strdup(buf);
if(!(buf = luaA_getopt_string(L, 2, "fg", NULL)) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
|| !xcolor_init(&sb->colors.fg, globalconf.connection, globalconf.default_screen, buf)) if(xcolor_init(&sb->colors.fg, globalconf.connection,
{ globalconf.default_screen, buf, len))
sb->colors.fg = globalconf.colors.fg; sb->colors.fg = globalconf.colors.fg;
}
if(!(buf = luaA_getopt_string(L, 2, "bg", NULL)) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
|| !xcolor_init(&sb->colors.bg, globalconf.connection, if(xcolor_init(&sb->colors.bg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ sb->colors.bg = globalconf.colors.bg;
sb->colors.bg = globalconf.colors.bg;
}
buf = luaA_getopt_lstring(L, 2, "align", "left", &len); buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
sb->align = draw_align_fromstr(buf, len); sb->align = draw_align_fromstr(buf, len);
@ -556,25 +553,25 @@ luaA_statusbar_newindex(lua_State *L)
statusbar_position_update(*statusbar, (*statusbar)->position); statusbar_position_update(*statusbar, (*statusbar)->position);
break; break;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len)))
&& xcolor_init(&(*statusbar)->colors.fg, globalconf.connection, if(xcolor_init(&(*statusbar)->colors.fg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->fg = (*statusbar)->colors.fg; (*statusbar)->ctx->fg = (*statusbar)->colors.fg;
(*statusbar)->need_update = true; (*statusbar)->need_update = true;
} }
break; break;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len)))
&& xcolor_init(&(*statusbar)->colors.bg, globalconf.connection, if(xcolor_init(&(*statusbar)->colors.bg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->bg = (*statusbar)->colors.bg; (*statusbar)->ctx->bg = (*statusbar)->colors.bg;
(*statusbar)->need_update = true; (*statusbar)->need_update = true;
} }
break; break;
case A_TK_POSITION: case A_TK_POSITION:
buf = luaL_checklstring(L, 3, &len); buf = luaL_checklstring(L, 3, &len);

View File

@ -314,26 +314,20 @@ luaA_titlebar_new(lua_State *L)
buf = luaA_getopt_lstring(L, 2, "position", "top", &len); buf = luaA_getopt_lstring(L, 2, "position", "top", &len);
tb->position = position_fromstr(buf, len); tb->position = position_fromstr(buf, len);
if(!(buf = luaA_getopt_string(L, 2, "fg", NULL)) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
|| !xcolor_init(&tb->colors.fg, globalconf.connection, if(xcolor_init(&tb->colors.fg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ tb->colors.fg = globalconf.colors.fg;
tb->colors.fg = globalconf.colors.fg;
}
if(!(buf = luaA_getopt_string(L, 2, "bg", NULL)) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
|| !xcolor_init(&tb->colors.bg, globalconf.connection, if(xcolor_init(&tb->colors.bg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ tb->colors.bg = globalconf.colors.bg;
tb->colors.bg = globalconf.colors.bg;
}
if(!(buf = luaA_getopt_string(L, 2, "border_color", NULL)) if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len)))
|| !xcolor_init(&tb->border.color, globalconf.connection, if(xcolor_init(&tb->border.color, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ tb->border.color = globalconf.colors.fg;
tb->border.color = globalconf.colors.fg;
}
tb->border.width = luaA_getopt_number(L, 2, "border_width", 0); tb->border.width = luaA_getopt_number(L, 2, "border_width", 0);
@ -480,29 +474,24 @@ luaA_titlebar_newindex(lua_State *L)
return 0; return 0;
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len)))
&& xcolor_init(&(*titlebar)->border.color, globalconf.connection, if(xcolor_init(&(*titlebar)->border.color, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ if((*titlebar)->sw)
if((*titlebar)->sw) xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window,
xcb_change_window_attributes(globalconf.connection, (*titlebar)->sw->window, XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel);
XCB_CW_BORDER_PIXEL, &(*titlebar)->border.color.pixel);
}
return 0; return 0;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len)))
&& xcolor_init(&(*titlebar)->colors.fg, globalconf.connection, if(xcolor_init(&(*titlebar)->colors.fg, globalconf.connection,
globalconf.default_screen, buf)) globalconf.default_screen, buf, len))
{ titlebar_draw(client_getbytitlebar(*titlebar));
titlebar_draw(client_getbytitlebar(*titlebar));
}
return 0; return 0;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checkstring(L, 3)) if((buf = luaL_checklstring(L, 3, &len)))
&& xcolor_init(&(*titlebar)->colors.bg, globalconf.connection, globalconf.default_screen, buf)) if(xcolor_init(&(*titlebar)->colors.bg, globalconf.connection,
{ globalconf.default_screen, buf, len))
titlebar_draw(client_getbytitlebar(*titlebar)); titlebar_draw(client_getbytitlebar(*titlebar));
}
return 0; return 0;
default: default:
return 0; return 0;

View File

@ -296,23 +296,17 @@ luaA_graph_plot_properties_set(lua_State *L)
if(!plot) if(!plot)
plot = graph_plot_add(d, title); plot = graph_plot_add(d, title);
if((buf = luaA_getopt_string(L, 3, "fg", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
{
xcolor_init(&plot->color_start, globalconf.connection, xcolor_init(&plot->color_start, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "fg_center", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
{
xcolor_init(&plot->pcolor_center, globalconf.connection, xcolor_init(&plot->pcolor_center, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "fg_end", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
{
xcolor_init(&plot->pcolor_end, globalconf.connection, xcolor_init(&plot->pcolor_end, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient); plot->vertical_gradient = luaA_getopt_boolean(L, 3, "vertical_gradient", plot->vertical_gradient);
plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale); plot->scale = luaA_getopt_boolean(L, 3, "scale", plot->scale);
@ -484,6 +478,7 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
int width; int width;
plot_t *plot; plot_t *plot;
position_t pos; position_t pos;
xcolor_t color;
switch(token) switch(token)
{ {
@ -511,14 +506,24 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
return 0; return 0;
break; break;
case A_TK_BG: case A_TK_BG:
if (!xcolor_init(&d->bg, globalconf.connection, globalconf.default_screen, if((buf = luaL_checklstring(L, 3, &len)))
luaL_checkstring(L, 3))) {
return 0; if(xcolor_init(&color, globalconf.connection,
globalconf.default_screen, buf, len))
d->bg = color;
else
return 0;
}
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if (!xcolor_init(&d->border_color, globalconf.connection, if((buf = luaL_checklstring(L, 3, &len)))
globalconf.default_screen, luaL_checkstring(L, 3))) {
return 0; if(xcolor_init(&color, globalconf.connection,
globalconf.default_screen, buf, len))
d->border_color = color;
else
return 0;
}
break; break;
case A_TK_GROW: case A_TK_GROW:
buf = luaL_checklstring(L, 3, &len); buf = luaL_checklstring(L, 3, &len);

View File

@ -409,6 +409,7 @@ progressbar_draw(draw_context_t *ctx,
static int static int
luaA_progressbar_bar_properties_set(lua_State *L) luaA_progressbar_bar_properties_set(lua_State *L)
{ {
size_t len;
widget_t **widget = luaA_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
const char *buf, *title = luaL_checkstring(L, 2); const char *buf, *title = luaL_checkstring(L, 2);
bar_t *bar; bar_t *bar;
@ -425,41 +426,29 @@ luaA_progressbar_bar_properties_set(lua_State *L)
if(!bar) if(!bar)
bar = progressbar_bar_add(d, title); bar = progressbar_bar_add(d, title);
if((buf = luaA_getopt_string(L, 3, "fg", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
{
xcolor_init(&bar->fg, globalconf.connection, xcolor_init(&bar->fg, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "fg_off", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len)))
{
xcolor_init(&bar->fg_off, globalconf.connection, xcolor_init(&bar->fg_off, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "bg", NULL))) if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len)))
{
xcolor_init(&bar->bg, globalconf.connection, xcolor_init(&bar->bg, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "border_color", NULL))) if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len)))
{
xcolor_init(&bar->border_color, globalconf.connection, xcolor_init(&bar->border_color, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "fg_center", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
{
xcolor_init(&bar->fg_center, globalconf.connection, xcolor_init(&bar->fg_center, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
if((buf = luaA_getopt_string(L, 3, "fg_end", NULL))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
{
xcolor_init(&bar->fg_end, globalconf.connection, xcolor_init(&bar->fg_end, globalconf.connection,
globalconf.default_screen, buf); globalconf.default_screen, buf, len);
}
bar->min_value = luaA_getopt_number(L, 3, "min_value", bar->min_value); bar->min_value = luaA_getopt_number(L, 3, "min_value", bar->min_value);
/* hack to prevent max_value beeing less than min_value /* hack to prevent max_value beeing less than min_value

View File

@ -91,7 +91,8 @@ tasklist_markup_on_elem(markup_parser_data_t *p, const char *elem,
if(!a_strcmp(*names, "color")) if(!a_strcmp(*names, "color"))
{ {
xcolor_t bg_color; xcolor_t bg_color;
xcolor_init(&bg_color, ctx->connection, ctx->phys_screen, *values); xcolor_init(&bg_color, ctx->connection, ctx->phys_screen,
*values, a_strlen(*values));
draw_rectangle(ctx, *data->area, 1.0, true, &bg_color); draw_rectangle(ctx, *data->area, 1.0, true, &bg_color);
break; break;
} }