widgets: don't tokenize twice
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
b72d5c7951
commit
5bb431fc4a
|
@ -100,9 +100,9 @@ struct widget_t
|
||||||
/** Draw function */
|
/** Draw function */
|
||||||
int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *);
|
int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *);
|
||||||
/** Index function */
|
/** Index function */
|
||||||
int (*index)(lua_State *);
|
int (*index)(lua_State *, awesome_token_t);
|
||||||
/** Newindex function */
|
/** Newindex function */
|
||||||
int (*newindex)(lua_State *);
|
int (*newindex)(lua_State *, awesome_token_t);
|
||||||
/** ButtonPressedEvent handler */
|
/** ButtonPressedEvent handler */
|
||||||
void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *, awesome_type_t);
|
void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *, awesome_type_t);
|
||||||
/** Alignement */
|
/** Alignement */
|
||||||
|
|
10
widget.c
10
widget.c
|
@ -383,6 +383,7 @@ luaA_widget_index(lua_State *L)
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *buf = luaL_checklstring(L, 2, &len);
|
const char *buf = luaL_checklstring(L, 2, &len);
|
||||||
|
awesome_token_t token;
|
||||||
|
|
||||||
lua_getmetatable(L, 1);
|
lua_getmetatable(L, 1);
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
|
@ -394,7 +395,7 @@ luaA_widget_index(lua_State *L)
|
||||||
}
|
}
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
|
|
||||||
switch(a_tokenize(buf, len))
|
switch((token = a_tokenize(buf, len)))
|
||||||
{
|
{
|
||||||
case A_TK_VISIBLE:
|
case A_TK_VISIBLE:
|
||||||
lua_pushboolean(L, (*widget)->isvisible);
|
lua_pushboolean(L, (*widget)->isvisible);
|
||||||
|
@ -403,7 +404,7 @@ luaA_widget_index(lua_State *L)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*widget)->index ? (*widget)->index(L) : 0;
|
return (*widget)->index ? (*widget)->index(L, token) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generic widget newindex.
|
/** Generic widget newindex.
|
||||||
|
@ -416,8 +417,9 @@ luaA_widget_newindex(lua_State *L)
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *buf = luaL_checklstring(L, 2, &len);
|
const char *buf = luaL_checklstring(L, 2, &len);
|
||||||
|
awesome_token_t token;
|
||||||
|
|
||||||
switch(a_tokenize(buf, len))
|
switch((token = a_tokenize(buf, len)))
|
||||||
{
|
{
|
||||||
case A_TK_VISIBLE:
|
case A_TK_VISIBLE:
|
||||||
(*widget)->isvisible = luaA_checkboolean(L, 3);
|
(*widget)->isvisible = luaA_checkboolean(L, 3);
|
||||||
|
@ -426,7 +428,7 @@ luaA_widget_newindex(lua_State *L)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*widget)->newindex ? (*widget)->newindex(L) : 0;
|
return (*widget)->newindex ? (*widget)->newindex(L, token) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct luaL_reg awesome_widget_methods[] =
|
const struct luaL_reg awesome_widget_methods[] =
|
||||||
|
|
|
@ -425,17 +425,16 @@ luaA_graph_plot_data_add(lua_State *L)
|
||||||
|
|
||||||
/** Index function for graph widget.
|
/** Index function for graph widget.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_graph_index(lua_State *L)
|
luaA_graph_index(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
graph_data_t *d = (*widget)->data;
|
graph_data_t *d = (*widget)->data;
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_PLOT_PROPERTIES_SET:
|
case A_TK_PLOT_PROPERTIES_SET:
|
||||||
lua_pushcfunction(L, luaA_graph_plot_properties_set);
|
lua_pushcfunction(L, luaA_graph_plot_properties_set);
|
||||||
|
@ -477,21 +476,22 @@ luaA_graph_index(lua_State *L)
|
||||||
|
|
||||||
/** Newindex function for graph widget.
|
/** Newindex function for graph widget.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_graph_newindex(lua_State *L)
|
luaA_graph_newindex(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
graph_data_t *d = (*widget)->data;
|
graph_data_t *d = (*widget)->data;
|
||||||
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
const char *buf;
|
||||||
int width;
|
int width;
|
||||||
plot_t *plot;
|
plot_t *plot;
|
||||||
position_t pos;
|
position_t pos;
|
||||||
xcolor_t color;
|
xcolor_t color;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_HEIGHT:
|
case A_TK_HEIGHT:
|
||||||
d->height = luaL_checknumber(L, 3);
|
d->height = luaL_checknumber(L, 3);
|
||||||
|
|
|
@ -519,17 +519,16 @@ luaA_progressbar_bar_data_add(lua_State *L)
|
||||||
|
|
||||||
/** Index function for progressbar.
|
/** Index function for progressbar.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on the stack.
|
* \return The number of elements pushed on the stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_progressbar_index(lua_State *L)
|
luaA_progressbar_index(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
progressbar_data_t *d = (*widget)->data;
|
progressbar_data_t *d = (*widget)->data;
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_BAR_PROPERTIES_SET:
|
case A_TK_BAR_PROPERTIES_SET:
|
||||||
lua_pushcfunction(L, luaA_progressbar_bar_properties_set);
|
lua_pushcfunction(L, luaA_progressbar_bar_properties_set);
|
||||||
|
@ -570,17 +569,16 @@ luaA_progressbar_index(lua_State *L)
|
||||||
|
|
||||||
/** Newindex function for progressbar.
|
/** Newindex function for progressbar.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on the stack.
|
* \return The number of elements pushed on the stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_progressbar_newindex(lua_State *L)
|
luaA_progressbar_newindex(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
progressbar_data_t *d = (*widget)->data;
|
progressbar_data_t *d = (*widget)->data;
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_GAP:
|
case A_TK_GAP:
|
||||||
d->gap = luaL_checknumber(L, 3);
|
d->gap = luaL_checknumber(L, 3);
|
||||||
|
|
|
@ -291,17 +291,16 @@ taglist_button_press(widget_node_t *w,
|
||||||
|
|
||||||
/** Index function for taglist.
|
/** Index function for taglist.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_taglist_index(lua_State *L)
|
luaA_taglist_index(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
taglist_data_t *d = (*widget)->data;
|
taglist_data_t *d = (*widget)->data;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT_NORMAL:
|
case A_TK_TEXT_NORMAL:
|
||||||
lua_pushstring(L, d->text_normal);
|
lua_pushstring(L, d->text_normal);
|
||||||
|
@ -322,17 +321,17 @@ luaA_taglist_index(lua_State *L)
|
||||||
|
|
||||||
/** Newindex function for taglist.
|
/** Newindex function for taglist.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_taglist_newindex(lua_State *L)
|
luaA_taglist_newindex(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
const char *buf;
|
||||||
taglist_data_t *d = (*widget)->data;
|
taglist_data_t *d = (*widget)->data;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT_NORMAL:
|
case A_TK_TEXT_NORMAL:
|
||||||
if((buf = luaL_checkstring(L, 3)))
|
if((buf = luaL_checkstring(L, 3)))
|
||||||
|
|
|
@ -276,18 +276,17 @@ tasklist_button_press(widget_node_t *w,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Index function for tasklist widget.
|
/** Index function for tasklist widget.
|
||||||
* \lparam L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_tasklist_index(lua_State *L)
|
luaA_tasklist_index(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
tasklist_data_t *d = (*widget)->data;
|
tasklist_data_t *d = (*widget)->data;
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT_NORMAL:
|
case A_TK_TEXT_NORMAL:
|
||||||
lua_pushstring(L, d->text_normal);
|
lua_pushstring(L, d->text_normal);
|
||||||
|
@ -323,18 +322,19 @@ luaA_tasklist_index(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Newindex function for tasklist widget.
|
/** Newindex function for tasklist widget.
|
||||||
* \lparam L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_tasklist_newindex(lua_State *L)
|
luaA_tasklist_newindex(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
tasklist_data_t *d = (*widget)->data;
|
tasklist_data_t *d = (*widget)->data;
|
||||||
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
const char *buf;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT_NORMAL:
|
case A_TK_TEXT_NORMAL:
|
||||||
if((buf = luaL_checkstring(L, 3)))
|
if((buf = luaL_checkstring(L, 3)))
|
||||||
|
|
|
@ -96,17 +96,16 @@ textbox_destructor(widget_t *w)
|
||||||
|
|
||||||
/** The __index method for a textbox object.
|
/** The __index method for a textbox object.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key token.
|
||||||
* \return The number of elements pushed on stack.
|
* \return The number of elements pushed on stack.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_textbox_index(lua_State *L)
|
luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *attr = luaL_checklstring(L, 2, &len);
|
|
||||||
textbox_data_t *d = (*widget)->data;
|
textbox_data_t *d = (*widget)->data;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT:
|
case A_TK_TEXT:
|
||||||
lua_pushstring(L, d->text);
|
lua_pushstring(L, d->text);
|
||||||
|
@ -123,17 +122,18 @@ luaA_textbox_index(lua_State *L)
|
||||||
|
|
||||||
/** The __newindex method for a textbox object.
|
/** The __newindex method for a textbox object.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
|
* \param token The key 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)
|
luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||||
const char *buf, *attr = luaL_checklstring(L, 2, &len);
|
const char *buf;
|
||||||
textbox_data_t *d = (*widget)->data;
|
textbox_data_t *d = (*widget)->data;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(token)
|
||||||
{
|
{
|
||||||
case A_TK_TEXT:
|
case A_TK_TEXT:
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
|
|
Loading…
Reference in New Issue