widgets: Use strings instead of tokens
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
dc883f7cef
commit
a440dab39d
|
@ -437,9 +437,7 @@ luaA_widget_buttons(lua_State *L)
|
||||||
static int
|
static int
|
||||||
luaA_widget_index(lua_State *L)
|
luaA_widget_index(lua_State *L)
|
||||||
{
|
{
|
||||||
size_t len;
|
const char *prop = luaL_checkstring(L, 2);
|
||||||
const char *prop = luaL_checklstring(L, 2, &len);
|
|
||||||
awesome_token_t token = a_tokenize(prop, len);
|
|
||||||
|
|
||||||
/* Try standard method */
|
/* Try standard method */
|
||||||
if(luaA_class_index(L))
|
if(luaA_class_index(L))
|
||||||
|
@ -447,7 +445,7 @@ luaA_widget_index(lua_State *L)
|
||||||
|
|
||||||
/* Then call special widget index */
|
/* Then call special widget index */
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
return widget->index ? widget->index(L, token) : 0;
|
return widget->index ? widget->index(L, prop) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generic widget newindex.
|
/** Generic widget newindex.
|
||||||
|
@ -457,16 +455,14 @@ luaA_widget_index(lua_State *L)
|
||||||
static int
|
static int
|
||||||
luaA_widget_newindex(lua_State *L)
|
luaA_widget_newindex(lua_State *L)
|
||||||
{
|
{
|
||||||
size_t len;
|
const char *prop = luaL_checkstring(L, 2);
|
||||||
const char *prop = luaL_checklstring(L, 2, &len);
|
|
||||||
awesome_token_t token = a_tokenize(prop, len);
|
|
||||||
|
|
||||||
/* Try standard method */
|
/* Try standard method */
|
||||||
luaA_class_newindex(L);
|
luaA_class_newindex(L);
|
||||||
|
|
||||||
/* Then call special widget newindex */
|
/* Then call special widget newindex */
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
return widget->newindex ? widget->newindex(L, token) : 0;
|
return widget->newindex ? widget->newindex(L, prop) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -43,9 +43,9 @@ struct widget_t
|
||||||
/** Draw function */
|
/** Draw function */
|
||||||
void (*draw)(widget_t *, draw_context_t *, area_t, wibox_t *);
|
void (*draw)(widget_t *, draw_context_t *, area_t, wibox_t *);
|
||||||
/** Index function */
|
/** Index function */
|
||||||
int (*index)(lua_State *, awesome_token_t);
|
int (*index)(lua_State *, const char *);
|
||||||
/** Newindex function */
|
/** Newindex function */
|
||||||
int (*newindex)(lua_State *, awesome_token_t);
|
int (*newindex)(lua_State *, const char *);
|
||||||
/** Misc private data */
|
/** Misc private data */
|
||||||
void *data;
|
void *data;
|
||||||
/** Button bindings */
|
/** Button bindings */
|
||||||
|
|
|
@ -84,7 +84,7 @@ imagebox_destructor(widget_t *w)
|
||||||
|
|
||||||
/** Imagebox widget.
|
/** Imagebox widget.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \param token The key token.
|
* \param prop The key that is being indexed.
|
||||||
* \param resize Resize image.
|
* \param resize Resize image.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
* \luastack
|
* \luastack
|
||||||
|
@ -92,25 +92,19 @@ imagebox_destructor(widget_t *w)
|
||||||
* \lfield bg The background color to use.
|
* \lfield bg The background color to use.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_imagebox_index(lua_State *L, awesome_token_t token)
|
luaA_imagebox_index(lua_State *L, const char *prop)
|
||||||
{
|
{
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
imagebox_data_t *d = widget->data;
|
imagebox_data_t *d = widget->data;
|
||||||
|
|
||||||
switch(token)
|
if(a_strcmp(prop, "image") == 0)
|
||||||
{
|
|
||||||
case A_TK_IMAGE:
|
|
||||||
luaA_object_push_item(L, 1, d->image);
|
luaA_object_push_item(L, 1, d->image);
|
||||||
break;
|
else if(a_strcmp(prop, "bg") == 0)
|
||||||
case A_TK_BG:
|
|
||||||
luaA_pushcolor(L, &d->bg);
|
luaA_pushcolor(L, &d->bg);
|
||||||
break;
|
else if(a_strcmp(prop, "resize") == 0)
|
||||||
case A_TK_RESIZE:
|
|
||||||
lua_pushboolean(L, d->resize);
|
lua_pushboolean(L, d->resize);
|
||||||
break;
|
else
|
||||||
default:
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -121,33 +115,30 @@ luaA_imagebox_index(lua_State *L, awesome_token_t token)
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_imagebox_newindex(lua_State *L, awesome_token_t token)
|
luaA_imagebox_newindex(lua_State *L, const char *prop)
|
||||||
{
|
{
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
imagebox_data_t *d = widget->data;
|
imagebox_data_t *d = widget->data;
|
||||||
|
|
||||||
switch(token)
|
if(a_strcmp(prop, "image") == 0)
|
||||||
{
|
{
|
||||||
const char *buf;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
case A_TK_IMAGE:
|
|
||||||
luaA_checkudataornil(L, -1, &image_class);
|
luaA_checkudataornil(L, -1, &image_class);
|
||||||
luaA_object_unref_item(L, 1, d->image);
|
luaA_object_unref_item(L, 1, d->image);
|
||||||
d->image = luaA_object_ref_item(L, 1, 3);
|
d->image = luaA_object_ref_item(L, 1, 3);
|
||||||
break;
|
}
|
||||||
case A_TK_BG:
|
else if(a_strcmp(prop, "bg") == 0)
|
||||||
|
{
|
||||||
|
const char *buf;
|
||||||
|
size_t len;
|
||||||
if(lua_isnil(L, 3))
|
if(lua_isnil(L, 3))
|
||||||
p_clear(&d->bg, 1);
|
p_clear(&d->bg, 1);
|
||||||
else if((buf = luaL_checklstring(L, 3, &len)))
|
else if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
color_init_reply(color_init_unchecked(&d->bg, buf, len));
|
color_init_reply(color_init_unchecked(&d->bg, buf, len));
|
||||||
break;
|
|
||||||
case A_TK_RESIZE:
|
|
||||||
d->resize = luaA_checkboolean(L, 3);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
else if(a_strcmp(prop, "resize") == 0)
|
||||||
|
d->resize = luaA_checkboolean(L, 3);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
widget_invalidate_bywidget(widget);
|
widget_invalidate_bywidget(widget);
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,7 @@ luaA_textbox_margin(lua_State *L)
|
||||||
|
|
||||||
/** Textbox widget.
|
/** Textbox widget.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \param token The key token.
|
* \param prop The property's name.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
* \luastack
|
* \luastack
|
||||||
* \lfield text The text to display.
|
* \lfield text The text to display.
|
||||||
|
@ -249,52 +249,43 @@ luaA_textbox_margin(lua_State *L)
|
||||||
* \lfield bg_resize Background resize.
|
* \lfield bg_resize Background resize.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_textbox_index(lua_State *L, awesome_token_t token)
|
luaA_textbox_index(lua_State *L, const char *prop)
|
||||||
{
|
{
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
textbox_data_t *d = widget->data;
|
textbox_data_t *d = widget->data;
|
||||||
|
|
||||||
switch(token)
|
if(a_strcmp(prop, "bg_resize") == 0)
|
||||||
{
|
|
||||||
case A_TK_BG_RESIZE:
|
|
||||||
lua_pushboolean(L, d->bg_resize);
|
lua_pushboolean(L, d->bg_resize);
|
||||||
return 1;
|
else if(a_strcmp(prop, "bg_align") == 0)
|
||||||
case A_TK_BG_ALIGN:
|
|
||||||
lua_pushstring(L, draw_align_tostr(d->bg_align));
|
lua_pushstring(L, draw_align_tostr(d->bg_align));
|
||||||
return 1;
|
else if(a_strcmp(prop, "bg_image") == 0)
|
||||||
case A_TK_BG_IMAGE:
|
|
||||||
return luaA_object_push(L, d->bg_image);
|
return luaA_object_push(L, d->bg_image);
|
||||||
case A_TK_BG:
|
else if(a_strcmp(prop, "bg") == 0)
|
||||||
return luaA_pushcolor(L, &d->bg);
|
return luaA_pushcolor(L, &d->bg);
|
||||||
case A_TK_MARGIN:
|
else if(a_strcmp(prop, "margin") == 0)
|
||||||
lua_pushcfunction(L, luaA_textbox_margin);
|
lua_pushcfunction(L, luaA_textbox_margin);
|
||||||
return 1;
|
else if(a_strcmp(prop, "align") == 0)
|
||||||
case A_TK_ALIGN:
|
|
||||||
lua_pushstring(L, draw_align_tostr(d->align));
|
lua_pushstring(L, draw_align_tostr(d->align));
|
||||||
return 1;
|
else if(a_strcmp(prop, "valign") == 0)
|
||||||
case A_TK_VALIGN:
|
|
||||||
lua_pushstring(L, draw_align_tostr(d->valign));
|
lua_pushstring(L, draw_align_tostr(d->valign));
|
||||||
return 1;
|
else if(a_strcmp(prop, "border_width") == 0)
|
||||||
case A_TK_BORDER_WIDTH:
|
|
||||||
lua_pushnumber(L, d->border.width);
|
lua_pushnumber(L, d->border.width);
|
||||||
return 1;
|
else if(a_strcmp(prop, "border_color") == 0)
|
||||||
case A_TK_BORDER_COLOR:
|
|
||||||
luaA_pushcolor(L, &d->border.color);
|
luaA_pushcolor(L, &d->border.color);
|
||||||
return 1;
|
else if(a_strcmp(prop, "text") == 0)
|
||||||
case A_TK_TEXT:
|
{
|
||||||
if(d->text_len > 0)
|
if(d->text_len > 0)
|
||||||
{
|
{
|
||||||
lua_pushlstring(L, d->text, d->text_len);
|
lua_pushlstring(L, d->text, d->text_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case A_TK_WIDTH:
|
}
|
||||||
|
else if(a_strcmp(prop, "width") == 0)
|
||||||
lua_pushnumber(L, d->width);
|
lua_pushnumber(L, d->width);
|
||||||
return 1;
|
else if(a_strcmp(prop, "height") == 0)
|
||||||
case A_TK_HEIGHT:
|
|
||||||
lua_pushnumber(L, d->height);
|
lua_pushnumber(L, d->height);
|
||||||
return 1;
|
else if(a_strcmp(prop, "wrap") == 0)
|
||||||
case A_TK_WRAP:
|
|
||||||
switch(d->wrap)
|
switch(d->wrap)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
|
@ -307,8 +298,7 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
lua_pushliteral(L, "word_char");
|
lua_pushliteral(L, "word_char");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
else if(a_strcmp(prop, "ellipsize") == 0)
|
||||||
case A_TK_ELLIPSIZE:
|
|
||||||
switch(d->ellip)
|
switch(d->ellip)
|
||||||
{
|
{
|
||||||
case PANGO_ELLIPSIZE_START:
|
case PANGO_ELLIPSIZE_START:
|
||||||
|
@ -321,10 +311,10 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
lua_pushliteral(L, "end");
|
lua_pushliteral(L, "end");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
else
|
||||||
default:
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The __newindex method for a textbox object.
|
/** The __newindex method for a textbox object.
|
||||||
|
@ -333,49 +323,52 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
luaA_textbox_newindex(lua_State *L, const char *prop)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
||||||
const char *buf = NULL;
|
const char *buf = NULL;
|
||||||
textbox_data_t *d = widget->data;
|
textbox_data_t *d = widget->data;
|
||||||
|
|
||||||
switch(token)
|
if(a_strcmp(prop, "bg_align") == 0)
|
||||||
{
|
{
|
||||||
case A_TK_BG_ALIGN:
|
|
||||||
buf = luaL_checklstring(L, 3, &len);
|
buf = luaL_checklstring(L, 3, &len);
|
||||||
d->bg_align = draw_align_fromstr(buf, len);
|
d->bg_align = draw_align_fromstr(buf, len);
|
||||||
break;
|
}
|
||||||
case A_TK_BG_RESIZE:
|
else if(a_strcmp(prop, "bg_resize") == 0)
|
||||||
d->bg_resize = luaA_checkboolean(L, 3);
|
d->bg_resize = luaA_checkboolean(L, 3);
|
||||||
break;
|
else if(a_strcmp(prop, "bg_image") == 0)
|
||||||
case A_TK_BG_IMAGE:
|
{
|
||||||
luaA_checkudataornil(L, -1, &image_class);
|
luaA_checkudataornil(L, -1, &image_class);
|
||||||
luaA_object_unref_item(L, 1, d->bg_image);
|
luaA_object_unref_item(L, 1, d->bg_image);
|
||||||
d->bg_image = luaA_object_ref_item(L, 1, 3);
|
d->bg_image = luaA_object_ref_item(L, 1, 3);
|
||||||
break;
|
}
|
||||||
case A_TK_BG:
|
else if(a_strcmp(prop, "bg") == 0)
|
||||||
|
{
|
||||||
if(lua_isnil(L, 3))
|
if(lua_isnil(L, 3))
|
||||||
p_clear(&d->bg, 1);
|
p_clear(&d->bg, 1);
|
||||||
else if((buf = luaL_checklstring(L, 3, &len)))
|
else if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
color_init_reply(color_init_unchecked(&d->bg, buf, len));
|
color_init_reply(color_init_unchecked(&d->bg, buf, len));
|
||||||
break;
|
}
|
||||||
case A_TK_ALIGN:
|
else if(a_strcmp(prop, "align") == 0)
|
||||||
|
{
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
d->align = draw_align_fromstr(buf, len);
|
d->align = draw_align_fromstr(buf, len);
|
||||||
break;
|
}
|
||||||
case A_TK_VALIGN:
|
else if(a_strcmp(prop, "valign") == 0)
|
||||||
|
{
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
d->valign = draw_align_fromstr(buf, len);
|
d->valign = draw_align_fromstr(buf, len);
|
||||||
break;
|
}
|
||||||
case A_TK_BORDER_COLOR:
|
else if(a_strcmp(prop, "border_color") == 0)
|
||||||
|
{
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
color_init_reply(color_init_unchecked(&d->border.color, buf, len));
|
color_init_reply(color_init_unchecked(&d->border.color, buf, len));
|
||||||
break;
|
}
|
||||||
case A_TK_BORDER_WIDTH:
|
else if(a_strcmp(prop, "border_width") == 0)
|
||||||
d->border.width = luaL_checknumber(L, 3);
|
d->border.width = luaL_checknumber(L, 3);
|
||||||
break;
|
else if(a_strcmp(prop, "text") == 0)
|
||||||
case A_TK_TEXT:
|
{
|
||||||
if(lua_isnil(L, 3)
|
if(lua_isnil(L, 3)
|
||||||
|| (buf = luaL_checklstring(L, 3, &len)))
|
|| (buf = luaL_checklstring(L, 3, &len)))
|
||||||
{
|
{
|
||||||
|
@ -420,14 +413,13 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
else
|
else
|
||||||
p_clear(&d->extents, 1);
|
p_clear(&d->extents, 1);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case A_TK_WIDTH:
|
else if(a_strcmp(prop, "width") == 0)
|
||||||
d->width = luaL_checknumber(L, 3);
|
d->width = luaL_checknumber(L, 3);
|
||||||
break;
|
else if(a_strcmp(prop, "height") == 0)
|
||||||
case A_TK_HEIGHT:
|
|
||||||
d->height = luaL_checknumber(L, 3);
|
d->height = luaL_checknumber(L, 3);
|
||||||
break;
|
else if(a_strcmp(prop, "wrap") == 0)
|
||||||
case A_TK_WRAP:
|
{
|
||||||
if((buf = luaL_checkstring(L, 3)))
|
if((buf = luaL_checkstring(L, 3)))
|
||||||
{
|
{
|
||||||
if(a_strcmp(buf, "word") == 0)
|
if(a_strcmp(buf, "word") == 0)
|
||||||
|
@ -437,8 +429,9 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
else if(a_strcmp(buf, "word_char") == 0)
|
else if(a_strcmp(buf, "word_char") == 0)
|
||||||
d->wrap = PANGO_WRAP_WORD_CHAR;
|
d->wrap = PANGO_WRAP_WORD_CHAR;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case A_TK_ELLIPSIZE:
|
else if(a_strcmp(prop, "ellipsize") == 0)
|
||||||
|
{
|
||||||
if((buf = luaL_checkstring(L, 3)))
|
if((buf = luaL_checkstring(L, 3)))
|
||||||
{
|
{
|
||||||
if(a_strcmp(buf, "start") == 0)
|
if(a_strcmp(buf, "start") == 0)
|
||||||
|
@ -448,10 +441,9 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
else if(a_strcmp(buf, "end") == 0)
|
else if(a_strcmp(buf, "end") == 0)
|
||||||
d->ellip = PANGO_ELLIPSIZE_END;
|
d->ellip = PANGO_ELLIPSIZE_END;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
widget_invalidate_bywidget(widget);
|
widget_invalidate_bywidget(widget);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue