Mirror of Awesome WM window manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strut.c 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * strut.c - strut management
  3. *
  4. * Copyright © 2009 Julien Danjou <julien@danjou.info>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. */
  21. #include "strut.h"
  22. #include "luaa.h"
  23. #include "math.h"
  24. /** Push a strut type to a table on stack.
  25. * \param L The Lua VM state.
  26. * \param strut The strut to push.
  27. * \return The number of elements pushed on stack.
  28. */
  29. int
  30. luaA_pushstrut(lua_State *L, strut_t strut)
  31. {
  32. lua_createtable(L, 4, 0);
  33. lua_pushinteger(L, strut.left);
  34. lua_setfield(L, -2, "left");
  35. lua_pushinteger(L, strut.right);
  36. lua_setfield(L, -2, "right");
  37. lua_pushinteger(L, strut.top);
  38. lua_setfield(L, -2, "top");
  39. lua_pushinteger(L, strut.bottom);
  40. lua_setfield(L, -2, "bottom");
  41. return 1;
  42. }
  43. /** Convert a table to a strut_t structure.
  44. * \param L The Lua VM state.
  45. * \param idx The index of the table on the stack.
  46. * \param strut The strut to fill. Current values will be used as default.
  47. */
  48. void
  49. luaA_tostrut(lua_State *L, int idx, strut_t *strut)
  50. {
  51. luaA_checktable(L, idx);
  52. strut->left = ceil(luaA_getopt_number_range(L, idx, "left", strut->left, 0, UINT16_MAX));
  53. strut->right = ceil(luaA_getopt_number_range(L, idx, "right", strut->right, 0, UINT16_MAX));
  54. strut->top = ceil(luaA_getopt_number_range(L, idx, "top", strut->top, 0, UINT16_MAX));
  55. strut->bottom = ceil(luaA_getopt_number_range(L, idx, "bottom", strut->bottom, 0, UINT16_MAX));
  56. }
  57. // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80