screen: modularize padding handling

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-12-02 18:02:47 +01:00
parent 1d7d3309de
commit f099e7de27
2 changed files with 43 additions and 20 deletions

41
luaa.h
View File

@ -355,6 +355,47 @@ luaA_otable_new(lua_State *L)
return luaA_settype(L, "otable");
}
/** Get an optional padding table from a Lua table.
* \param L The Lua VM state.
* \param idx The table index on the stack.
* \param dpadding The default padding value to use.
*/
static inline padding_t
luaA_getopt_padding(lua_State *L, int idx, padding_t *dpadding)
{
padding_t padding;
luaA_checktable(L, 2);
padding.right = luaA_getopt_number(L, 2, "right", dpadding->right);
padding.left = luaA_getopt_number(L, 2, "left", dpadding->left);
padding.top = luaA_getopt_number(L, 2, "top", dpadding->top);
padding.bottom = luaA_getopt_number(L, 2, "bottom", dpadding->bottom);
return padding;
}
/** Push a padding structure into a table on the Lua stack.
* \param L The Lua VM state.
* \param padding The padding struct pointer.
* \return The number of elements pushed on stack.
*/
static inline int
luaA_pushpadding(lua_State *L, padding_t *padding)
{
lua_newtable(L);
lua_pushnumber(L, padding->right);
lua_setfield(L, -2, "right");
lua_pushnumber(L, padding->left);
lua_setfield(L, -2, "left");
lua_pushnumber(L, padding->top);
lua_setfield(L, -2, "top");
lua_pushnumber(L, padding->bottom);
lua_setfield(L, -2, "bottom");
return 1;
}
void luaA_init(void);
bool luaA_parserc(const char *, bool);
void luaA_cs_init(void);

View File

@ -528,12 +528,7 @@ luaA_screen_padding(lua_State *L)
if(lua_gettop(L) == 2)
{
luaA_checktable(L, 2);
s->padding.right = luaA_getopt_number(L, 2, "right", 0);
s->padding.left = luaA_getopt_number(L, 2, "left", 0);
s->padding.top = luaA_getopt_number(L, 2, "top", 0);
s->padding.bottom = luaA_getopt_number(L, 2, "bottom", 0);
s->padding = luaA_getopt_padding(L, 2, &s->padding);
s->need_arrange = true;
@ -543,20 +538,7 @@ luaA_screen_padding(lua_State *L)
ewmh_update_workarea(screen_virttophys(s->index));
}
else
{
lua_newtable(L);
lua_pushnumber(L, s->padding.right);
lua_setfield(L, -2, "right");
lua_pushnumber(L, s->padding.left);
lua_setfield(L, -2, "left");
lua_pushnumber(L, s->padding.top);
lua_setfield(L, -2, "top");
lua_pushnumber(L, s->padding.bottom);
lua_setfield(L, -2, "bottom");
}
return 1;
return luaA_pushpadding(L, &s->padding);
}
/** Get the screen count.