client: make coords a method

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-20 12:00:22 +02:00
parent d261f9a3cc
commit e02fc5aacb
4 changed files with 53 additions and 33 deletions

View File

@ -407,7 +407,7 @@ function hook_arrange(screen)
--[[
local sel = client.focus
if sel then
local c_c = sel.coords
local c_c = sel:coords()
local m_c = mouse.coords
if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or

View File

@ -1100,6 +1100,29 @@ luaA_client_unmanage(lua_State *L)
return 0;
}
static int
luaA_client_coords(lua_State *L)
{
client_t **c = luaA_checkudata(L, 1, "client");
if(lua_gettop(L) == 2)
{
if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
{
area_t geometry;
luaA_checktable(L, 2);
geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
client_resize(*c, geometry, false);
}
}
return luaA_pusharea(L, (*c)->geometry);
}
/** Client newindex.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
@ -1185,18 +1208,6 @@ luaA_client_newindex(lua_State *L)
xcb_change_window_attributes(globalconf.connection, (*c)->win,
XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
break;
case A_TK_COORDS:
if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
{
area_t geometry;
luaA_checktable(L, 3);
geometry.x = luaA_getopt_number(L, 3, "x", (*c)->geometry.x);
geometry.y = luaA_getopt_number(L, 3, "y", (*c)->geometry.y);
geometry.width = luaA_getopt_number(L, 3, "width", (*c)->geometry.width);
geometry.height = luaA_getopt_number(L, 3, "height", (*c)->geometry.height);
client_resize(*c, geometry, false);
}
break;
case A_TK_TITLEBAR:
if(!lua_isnil(L, 3))
{
@ -1247,7 +1258,6 @@ luaA_client_newindex(lua_State *L)
* \lfield honorsizehints Honor size hints, i.e. respect size ratio.
* \lfield border_width The client border width.
* \lfield border_color The client border color.
* \lfield coords The client coordinates.
* \lfield titlebar The client titlebar.
* \lfield urgent The client urgent state.
* \lfield focus The focused client.
@ -1347,17 +1357,6 @@ luaA_client_index(lua_State *L)
case A_TK_BORDER_COLOR:
luaA_pushcolor(L, &(*c)->border_color);
break;
case A_TK_COORDS:
lua_newtable(L);
lua_pushnumber(L, (*c)->geometry.width);
lua_setfield(L, -2, "width");
lua_pushnumber(L, (*c)->geometry.height);
lua_setfield(L, -2, "height");
lua_pushnumber(L, (*c)->geometry.x);
lua_setfield(L, -2, "x");
lua_pushnumber(L, (*c)->geometry.y);
lua_setfield(L, -2, "y");
break;
case A_TK_TITLEBAR:
if((*c)->titlebar)
return luaA_titlebar_userdata_new(globalconf.L, (*c)->titlebar);
@ -1432,6 +1431,7 @@ const struct luaL_reg awesome_client_methods[] =
};
const struct luaL_reg awesome_client_meta[] =
{
{ "coords", luaA_client_coords },
{ "tags", luaA_client_tags },
{ "kill", luaA_client_kill },
{ "swap", luaA_client_swap },

View File

@ -263,7 +263,7 @@ end
function client.focusbydirection(dir, c)
local sel = c or capi.client.focus
if sel then
local coords = sel.coords
local coords = sel:coords()
local dist, dist_min
local target = nil
local cls = capi.client.visible_get(sel.screen)
@ -271,10 +271,10 @@ function client.focusbydirection(dir, c)
-- We check each client.
for i, c in ipairs(cls) do
-- Check coords to see if client is located in the right direction.
if is_in_direction(dir, coords, c.coords) then
if is_in_direction(dir, coords, c:coords()) then
-- Calculate distance between focused client and checked client.
dist = calculate_distance(dir, coords, c.coords)
dist = calculate_distance(dir, coords, c:coords())
-- If distance is shorter then keep the client.
if not target or dist < dist_min then
@ -328,12 +328,12 @@ end
-- @param c The optional client, otherwise focused one is used.
function client.moveresize(x, y, w, h, c)
local sel = c or capi.client.focus
local coords = sel.coords
local coords = sel:coords()
coords['x'] = coords['x'] + x
coords['y'] = coords['y'] + y
coords['width'] = coords['width'] + w
coords['height'] = coords['height'] + h
sel.coords = coords
sel:coords(coords)
end
--- Maximize a client to use the full workarea.
@ -347,13 +347,13 @@ function client.maximize(c)
if sel.floating and client.data.maximize[sel] then
sel.floating = client.data.maximize[sel].floating
if sel.floating then
sel.coords = client.data.maximize[sel].coords
sel:coords(client.data.maximize[sel].coords)
end
client.data.maximize[sel] = nil
else
client.data.maximize[sel] = { coords = sel.coords, floating = sel.floating }
client.data.maximize[sel] = { coords = sel:coords(), floating = sel.floating }
sel.floating = true
sel.coords = ws
sel:coords(ws)
end
end
end

20
lua.h
View File

@ -164,6 +164,26 @@ luaA_settype(lua_State *L, const char *type)
return 1;
}
/** Push a area type to a table on stack.
* \param L The Lua VM state.
* \param geometry The area geometry to push.
* \return The number of elements pushed on stack.
*/
static inline int
luaA_pusharea(lua_State *L, area_t geometry)
{
lua_newtable(L);
lua_pushnumber(L, geometry.x);
lua_setfield(L, -2, "x");
lua_pushnumber(L, geometry.y);
lua_setfield(L, -2, "y");
lua_pushnumber(L, geometry.width);
lua_setfield(L, -2, "width");
lua_pushnumber(L, geometry.height);
lua_setfield(L, -2, "height");
return 1;
}
static inline int
luaA_usemetatable(lua_State *L, int idxobj, int idxfield)
{