From b249c67af958051978b0f2c990970639e8a734d9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 18 Aug 2009 14:13:37 +0200 Subject: [PATCH] strut: move table conversion to luaA_tostrut() Signed-off-by: Julien Danjou --- client.c | 32 ++++---------------------------- strut.c | 16 ++++++++++++++++ strut.h | 1 + 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/client.c b/client.c index 34bdd371..a0ab91aa 100644 --- a/client.c +++ b/client.c @@ -1582,34 +1582,10 @@ luaA_client_struts(lua_State *L) if(lua_gettop(L) == 2) { - strut_t struts; - area_t screen_area = display_area_get(c->phys_screen); - - struts.left = luaA_getopt_number(L, 2, "left", c->strut.left); - struts.right = luaA_getopt_number(L, 2, "right", c->strut.right); - struts.top = luaA_getopt_number(L, 2, "top", c->strut.top); - struts.bottom = luaA_getopt_number(L, 2, "bottom", c->strut.bottom); - - if(struts.left != c->strut.left || struts.right != c->strut.right || - struts.top != c->strut.top || struts.bottom != c->strut.bottom) { - /* Struts are not so well defined in the context of xinerama. So we just - * give the entire root window and let the window manager decide. */ - struts.left_start_y = 0; - struts.left_end_y = !struts.left ? 0 : screen_area.height; - struts.right_start_y = 0; - struts.right_end_y = !struts.right ? 0 : screen_area.height; - struts.top_start_x = 0; - struts.top_end_x = !struts.top ? 0 : screen_area.width; - struts.bottom_start_x = 0; - struts.bottom_end_x = !struts.bottom ? 0 : screen_area.width; - - c->strut = struts; - - ewmh_update_strut(c->window, &c->strut); - - hook_property(c, "struts"); - luaA_object_emit_signal(L, 1, "property::struts", 0); - } + luaA_tostrut(L, 2, &c->strut); + ewmh_update_strut(c->window, &c->strut); + hook_property(c, "struts"); + luaA_object_emit_signal(L, 1, "property::struts", 0); } return luaA_pushstrut(L, c->strut); diff --git a/strut.c b/strut.c index 710556ac..bdc8b853 100644 --- a/strut.c +++ b/strut.c @@ -20,6 +20,7 @@ */ #include "strut.h" +#include "luaa.h" /** Push a strut type to a table on stack. * \param L The Lua VM state. @@ -41,4 +42,19 @@ luaA_pushstrut(lua_State *L, strut_t strut) return 1; } +/** Convert a table to a strut_t structure. + * \param L The Lua VM state. + * \param idx The index of the table on the stack. + * \param struts The strut to fill. Current values will be used as default. + */ +void +luaA_tostrut(lua_State *L, int idx, strut_t *strut) +{ + luaA_checktable(L, idx); + strut->left = luaA_getopt_number(L, idx, "left", strut->left); + strut->right = luaA_getopt_number(L, idx, "right", strut->right); + strut->top = luaA_getopt_number(L, idx, "top", strut->top); + strut->bottom = luaA_getopt_number(L, idx, "bottom", strut->bottom); +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/strut.h b/strut.h index a2cd85b1..8b5a9fed 100644 --- a/strut.h +++ b/strut.h @@ -36,6 +36,7 @@ typedef struct } strut_t; int luaA_pushstrut(lua_State *, strut_t); +void luaA_tostrut(lua_State *, int, strut_t *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80