screen: modularize padding handling
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
1d7d3309de
commit
f099e7de27
41
luaa.h
41
luaa.h
|
@ -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);
|
||||
|
|
22
screen.c
22
screen.c
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue