draw: make xcolor_init() asynchronous.

This commit is contained in:
Arnaud Fontaine 2008-08-12 14:53:57 +02:00
parent 5c1c038bc9
commit 193a73c5d9
9 changed files with 253 additions and 97 deletions

View file

@ -277,7 +277,8 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *confpath = NULL; const char *confpath = NULL;
int xfd, i, screen_nbr, opt; int xfd, i, screen_nbr, opt, colors_nbr;
xcolor_init_request_t colors_reqs[2];
ssize_t cmdlen = 1; ssize_t cmdlen = 1;
client_t *c; client_t *c;
static struct option long_options[] = static struct option long_options[] =
@ -406,9 +407,15 @@ main(int argc, char **argv)
} }
/* init default font and colors */ /* init default font and colors */
colors_reqs[0] = xcolor_init_unchecked(globalconf.connection, &globalconf.colors.fg,
globalconf.default_screen, "black",
sizeof("black")-1);
colors_reqs[1] = xcolor_init_unchecked(globalconf.connection, &globalconf.colors.bg,
globalconf.default_screen, "white",
sizeof("white")-1);
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", sizeof("black")-1);
xcolor_init(&globalconf.colors.bg, globalconf.connection, globalconf.default_screen, "white", sizeof("white")-1);
/* init cursors */ /* init cursors */
globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_LEFT_PTR); globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_LEFT_PTR);
@ -421,6 +428,9 @@ main(int argc, char **argv)
globalconf.cursor[CurBotRight] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_RIGHT_CORNER); globalconf.cursor[CurBotRight] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_RIGHT_CORNER);
globalconf.cursor[CurBotLeft] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_LEFT_CORNER); globalconf.cursor[CurBotLeft] = xutil_cursor_new(globalconf.connection, XUTIL_CURSOR_BOTTOM_LEFT_CORNER);
for(colors_nbr = 0; colors_nbr < 2; colors_nbr++)
xcolor_init_reply(globalconf.connection, colors_reqs[colors_nbr]);
/* init lua */ /* init lua */
luaA_init(); luaA_init();

View file

@ -1128,7 +1128,11 @@ luaA_client_newindex(lua_State *L)
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len)) if((buf = luaL_checklstring(L, 3, &len))
&& xcolor_init(&(*c)->border_color, globalconf.connection, (*c)->phys_screen, buf, len)) && xcolor_init_reply(globalconf.connection,
xcolor_init_unchecked(globalconf.connection,
&(*c)->border_color,
(*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);
break; break;

View file

@ -219,6 +219,9 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
{ {
draw_parser_data_t *data = p->priv; draw_parser_data_t *data = p->priv;
xcolor_init_request_t reqs[3];
int8_t i, bg_color_nbr = -1, reqs_nbr = -1;
/* hack: markup.c validates tags so we can avoid strcmps here */ /* hack: markup.c validates tags so we can avoid strcmps here */
switch (*elem) { switch (*elem) {
case 'b': case 'b':
@ -227,11 +230,13 @@ 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, reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection,
data->connection, &data->bg_color,
data->phys_screen, data->phys_screen,
*values, *values,
a_strlen(*values)); a_strlen(*values));
bg_color_nbr = reqs_nbr;
break; break;
case A_TK_IMAGE: case A_TK_IMAGE:
if(data->bg_image) if(data->bg_image)
@ -251,8 +256,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:
xcolor_init(&data->border.color, data->connection, reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection,
data->phys_screen, *values, a_strlen(*values)); &data->border.color,
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);
@ -269,8 +277,11 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
data->align = draw_align_fromstr(*values, -1); data->align = draw_align_fromstr(*values, -1);
break; break;
case A_TK_SHADOW: case A_TK_SHADOW:
xcolor_init(&data->shadow.color, data->connection, reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection,
data->phys_screen, *values, a_strlen(*values)); &data->shadow.color,
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);
@ -294,6 +305,12 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
} }
break; break;
} }
for(i = 0; i <= reqs_nbr; i++)
if(i == bg_color_nbr)
data->has_bg_color = xcolor_init_reply(data->connection, reqs[i]);
else
xcolor_init_reply(data->connection, reqs[i]);
} }
bool bool
@ -1084,29 +1101,36 @@ draw_align_tostr(alignment_t a)
#define RGB_COLOR_8_TO_16(i) (65535 * ((i) & 0xff) / 255) #define RGB_COLOR_8_TO_16(i) (65535 * ((i) & 0xff) / 255)
/** Initialize an X color. /** Send a request to initialize a X color.
* \param color xcolor_t struct to store color into.
* \param conn Connection ref. * \param conn Connection ref.
* \param color xcolor_t struct to store color into.
* \param phys_screen Physical screen number. * \param phys_screen Physical screen number.
* \param colstr Color specification. * \param colstr Color specification.
* \return True if color allocation was successfull. * \return request informations.
*/ */
bool xcolor_init_request_t
xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen, xcolor_init_unchecked(xcb_connection_t *conn, xcolor_t *color, int phys_screen,
const char *colstr, ssize_t len) 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);
xcolor_init_request_t req;
unsigned long colnum; unsigned long colnum;
uint16_t red, green, blue, alpha = 0xffff; uint16_t red, green, blue;
p_clear(&req, 1);
if(!len) if(!len)
return false; {
req.has_error = true;
return req;
}
req.alpha = 0xffff;
req.color = color;
/* The color is given in RGB value */ /* The color is given in RGB value */
if(colstr[0] == '#') if(colstr[0] == '#')
{ {
xcb_alloc_color_cookie_t cookie;
xcb_alloc_color_reply_t *hexa_color;
char *p; char *p;
if(len == 7) if(len == 7)
@ -1121,60 +1145,84 @@ xcolor_init(xcolor_t *color, xcb_connection_t *conn, int phys_screen,
colnum = strtoul(colstr + 1, &p, 16); colnum = strtoul(colstr + 1, &p, 16);
if(p - colstr != 9) if(p - colstr != 9)
goto invalid; goto invalid;
alpha = RGB_COLOR_8_TO_16(colnum); req.alpha = RGB_COLOR_8_TO_16(colnum);
colnum >>= 8; colnum >>= 8;
} }
else else
{ {
invalid: invalid:
warn("awesome: error, invalid color '%s'", colstr); warn("awesome: error, invalid color '%s'", colstr);
return false; req.has_error = true;
return req;
} }
red = RGB_COLOR_8_TO_16(colnum >> 16); red = RGB_COLOR_8_TO_16(colnum >> 16);
green = RGB_COLOR_8_TO_16(colnum >> 8); green = RGB_COLOR_8_TO_16(colnum >> 8);
blue = RGB_COLOR_8_TO_16(colnum); blue = RGB_COLOR_8_TO_16(colnum);
cookie = xcb_alloc_color_unchecked(conn, s->default_colormap, req.is_hexa = true;
red, green, blue), req.cookie_hexa = xcb_alloc_color_unchecked(conn, s->default_colormap,
hexa_color = xcb_alloc_color_reply(conn, cookie, NULL); red, green, blue);
}
else
{
req.is_hexa = false;
req.cookie_named = xcb_alloc_named_color_unchecked(conn, s->default_colormap, len,
colstr);
}
if(hexa_color) req.has_error = false;
req.colstr = colstr;
return req;
}
/** Initialize a X color.
* \param conn Connection ref.
* \param req xcolor_init request.
* \return True if color allocation was successfull.
*/
bool
xcolor_init_reply(xcb_connection_t *conn,
xcolor_init_request_t req)
{
if(req.has_error)
return false;
if(req.is_hexa)
{
xcb_alloc_color_reply_t *hexa_color;
if((hexa_color = xcb_alloc_color_reply(conn, req.cookie_hexa, NULL)))
{ {
color->pixel = hexa_color->pixel; req.color->pixel = hexa_color->pixel;
color->red = hexa_color->red; req.color->red = hexa_color->red;
color->green = hexa_color->green; req.color->green = hexa_color->green;
color->blue = hexa_color->blue; req.color->blue = hexa_color->blue;
color->alpha = alpha; req.color->alpha = req.alpha;
color->initialized = true; req.color->initialized = true;
p_delete(&hexa_color); p_delete(&hexa_color);
return true; return true;
} }
} }
else else
{ {
xcb_alloc_named_color_reply_t *named_color = NULL; xcb_alloc_named_color_reply_t *named_color;
xcb_alloc_named_color_cookie_t cookie;
cookie = xcb_alloc_named_color_unchecked(conn, s->default_colormap, len, if((named_color = xcb_alloc_named_color_reply(conn, req.cookie_named, NULL)))
colstr),
named_color = xcb_alloc_named_color_reply(conn, cookie, NULL);
if(named_color)
{ {
color->pixel = named_color->pixel; req.color->pixel = named_color->pixel;
color->red = named_color->visual_red; req.color->red = named_color->visual_red;
color->green = named_color->visual_green; req.color->green = named_color->visual_green;
color->blue = named_color->visual_blue; req.color->blue = named_color->visual_blue;
color->alpha = 0xffff; req.color->alpha = req.alpha;
color->alpha = alpha; req.color->initialized = true;
color->initialized = true;
p_delete(&named_color); p_delete(&named_color);
return true; return true;
} }
} }
warn("awesome: error, cannot allocate color '%s'", colstr); warn("awesome: error, cannot allocate color '%s'", req.colstr);
return false; return false;
} }

View file

@ -220,7 +220,24 @@ 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 *, ssize_t); typedef struct
{
union
{
xcb_alloc_color_cookie_t cookie_hexa;
xcb_alloc_named_color_cookie_t cookie_named;
};
uint16_t alpha;
xcolor_t *color;
bool is_hexa, has_error;
const char *colstr;
} xcolor_init_request_t;
xcolor_init_request_t xcolor_init_unchecked(xcb_connection_t *, xcolor_t *, int,
const char *, ssize_t);
bool xcolor_init_reply(xcb_connection_t *, xcolor_init_request_t);
void area_array_remove(area_array_t *, area_t); void area_array_remove(area_array_t *, area_t);

18
lua.c
View file

@ -279,16 +279,26 @@ luaA_colors_set(lua_State *L)
{ {
const char *buf; const char *buf;
size_t len; size_t len;
int8_t colors_nbr = -1, i;
xcolor_init_request_t reqs[2];
luaA_checktable(L, 1); luaA_checktable(L, 1);
if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len)))
xcolor_init(&globalconf.colors.fg, globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &globalconf.colors.fg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len)))
xcolor_init(&globalconf.colors.bg, globalconf.connection, reqs[++colors_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &globalconf.colors.bg,
globalconf.default_screen,
buf, len);
for(i = 0; i <= colors_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]);
return 0; return 0;
} }

View file

@ -436,6 +436,8 @@ luaA_statusbar_new(lua_State *L)
statusbar_t *sb; statusbar_t *sb;
const char *buf; const char *buf;
size_t len; size_t len;
xcolor_init_request_t reqs[2];
int8_t i, reqs_nbr = -1;
luaA_checktable(L, 2); luaA_checktable(L, 2);
@ -448,13 +450,17 @@ luaA_statusbar_new(lua_State *L)
sb->colors.fg = globalconf.colors.fg; sb->colors.fg = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
xcolor_init(&sb->colors.fg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &sb->colors.fg,
globalconf.default_screen,
buf, len);
sb->colors.bg = globalconf.colors.bg; sb->colors.bg = globalconf.colors.bg;
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
xcolor_init(&sb->colors.bg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &sb->colors.bg,
globalconf.default_screen,
buf, len);
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);
@ -472,6 +478,9 @@ luaA_statusbar_new(lua_State *L)
sb->screen = SCREEN_UNDEF; sb->screen = SCREEN_UNDEF;
for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]);
return luaA_statusbar_userdata_new(L, sb); return luaA_statusbar_userdata_new(L, sb);
} }
@ -615,8 +624,11 @@ luaA_statusbar_newindex(lua_State *L)
break; break;
case A_TK_FG: case A_TK_FG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init(&(*statusbar)->colors.fg, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&(*statusbar)->colors.fg,
globalconf.default_screen,
buf, len)))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->fg = (*statusbar)->colors.fg; (*statusbar)->ctx->fg = (*statusbar)->colors.fg;
@ -625,8 +637,10 @@ luaA_statusbar_newindex(lua_State *L)
break; break;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init(&(*statusbar)->colors.bg, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&(*statusbar)->colors.bg,
globalconf.default_screen, buf, len)))
{ {
if((*statusbar)->ctx) if((*statusbar)->ctx)
(*statusbar)->ctx->bg = (*statusbar)->colors.bg; (*statusbar)->ctx->bg = (*statusbar)->colors.bg;

View file

@ -312,6 +312,8 @@ luaA_titlebar_new(lua_State *L)
titlebar_t *tb; titlebar_t *tb;
const char *buf; const char *buf;
size_t len; size_t len;
xcolor_init_request_t reqs[3];
int8_t i, reqs_nbr = -1;
luaA_checktable(L, 2); luaA_checktable(L, 2);
@ -331,21 +333,30 @@ luaA_titlebar_new(lua_State *L)
tb->colors.fg = globalconf.colors.fg; tb->colors.fg = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "fg", NULL, &len)))
xcolor_init(&tb->colors.fg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &tb->colors.fg,
globalconf.default_screen,
buf, len);
tb->colors.bg = globalconf.colors.bg; tb->colors.bg = globalconf.colors.bg;
if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "bg", NULL, &len)))
xcolor_init(&tb->colors.bg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &tb->colors.bg,
globalconf.default_screen,
buf, len);
tb->border.color = globalconf.colors.fg; tb->border.color = globalconf.colors.fg;
if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len))) if((buf = luaA_getopt_lstring(L, 2, "border_color", NULL, &len)))
xcolor_init(&tb->border.color, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &tb->border.color,
globalconf.default_screen,
buf, len);
tb->border.width = luaA_getopt_number(L, 2, "border_width", 0); tb->border.width = luaA_getopt_number(L, 2, "border_width", 0);
for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]);
return luaA_titlebar_userdata_new(globalconf.L, tb); return luaA_titlebar_userdata_new(globalconf.L, tb);
} }
@ -411,22 +422,30 @@ luaA_titlebar_newindex(lua_State *L)
break; break;
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init(&(*titlebar)->border.color, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->border.color,
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_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init(&(*titlebar)->colors.fg, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->colors.fg,
globalconf.default_screen,
buf, len)))
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
return 0; return 0;
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
if(xcolor_init(&(*titlebar)->colors.bg, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&(*titlebar)->colors.bg,
globalconf.default_screen,
buf, len)))
(*titlebar)->need_update = true; (*titlebar)->need_update = true;
return 0; return 0;
case A_TK_WIDGETS: case A_TK_WIDGETS:

View file

@ -288,6 +288,8 @@ luaA_graph_plot_properties_set(lua_State *L)
const char *title, *buf; const char *title, *buf;
size_t len; size_t len;
plot_t *plot; plot_t *plot;
xcolor_init_request_t reqs[3];
int8_t i, reqs_nbr = -1;
title = luaL_checkstring(L, 2); title = luaL_checkstring(L, 2);
luaA_checktable(L, 3); luaA_checktable(L, 3);
@ -300,16 +302,22 @@ luaA_graph_plot_properties_set(lua_State *L)
plot = graph_plot_add(d, title); plot = graph_plot_add(d, title);
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
xcolor_init(&plot->color_start, globalconf.connection, reqs[reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &plot->color_start,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
xcolor_init(&plot->pcolor_center, globalconf.connection, reqs[reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &plot->pcolor_center,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
xcolor_init(&plot->pcolor_end, globalconf.connection, reqs[reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &plot->pcolor_end,
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);
@ -334,6 +342,9 @@ luaA_graph_plot_properties_set(lua_State *L)
break; break;
} }
for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]);
widget_invalidate_bywidget(*widget); widget_invalidate_bywidget(*widget);
return 0; return 0;
@ -511,8 +522,11 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
case A_TK_BG: case A_TK_BG:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
{ {
if(xcolor_init(&color, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&color,
globalconf.default_screen,
buf, len)))
d->bg = color; d->bg = color;
else else
return 0; return 0;
@ -521,8 +535,11 @@ luaA_graph_newindex(lua_State *L, awesome_token_t token)
case A_TK_BORDER_COLOR: case A_TK_BORDER_COLOR:
if((buf = luaL_checklstring(L, 3, &len))) if((buf = luaL_checklstring(L, 3, &len)))
{ {
if(xcolor_init(&color, globalconf.connection, if(xcolor_init_reply(globalconf.connection,
globalconf.default_screen, buf, len)) xcolor_init_unchecked(globalconf.connection,
&color,
globalconf.default_screen,
buf, len)))
d->border_color = color; d->border_color = color;
else else
return 0; return 0;

View file

@ -416,6 +416,8 @@ luaA_progressbar_bar_properties_set(lua_State *L)
const char *buf, *title = luaL_checkstring(L, 2); const char *buf, *title = luaL_checkstring(L, 2);
bar_t *bar; bar_t *bar;
progressbar_data_t *d = (*widget)->data; progressbar_data_t *d = (*widget)->data;
xcolor_init_request_t reqs[6];
int8_t i, reqs_nbr = -1;
luaA_checktable(L, 3); luaA_checktable(L, 3);
@ -429,28 +431,40 @@ luaA_progressbar_bar_properties_set(lua_State *L)
bar = progressbar_bar_add(d, title); bar = progressbar_bar_add(d, title);
if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg", NULL, &len)))
xcolor_init(&bar->fg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->fg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_off", NULL, &len)))
xcolor_init(&bar->fg_off, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->fg_off,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "bg", NULL, &len)))
xcolor_init(&bar->bg, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->bg,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "border_color", NULL, &len)))
xcolor_init(&bar->border_color, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->border_color,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_center", NULL, &len)))
xcolor_init(&bar->fg_center, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->fg_center,
globalconf.default_screen,
buf, len);
if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len))) if((buf = luaA_getopt_lstring(L, 3, "fg_end", NULL, &len)))
xcolor_init(&bar->fg_end, globalconf.connection, reqs[++reqs_nbr] = xcolor_init_unchecked(globalconf.connection,
globalconf.default_screen, buf, len); &bar->fg_end,
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
@ -469,6 +483,9 @@ luaA_progressbar_bar_properties_set(lua_State *L)
bar->reverse = luaA_getopt_boolean(L, 3, "reverse", bar->reverse); bar->reverse = luaA_getopt_boolean(L, 3, "reverse", bar->reverse);
for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(globalconf.connection, reqs[i]);
widget_invalidate_bywidget(*widget); widget_invalidate_bywidget(*widget);
return 0; return 0;