From 9a0ae64840c381958314bc8f474df4199e631fc2 Mon Sep 17 00:00:00 2001 From: Cedric GESTES Date: Sun, 13 Sep 2009 14:50:53 +0200 Subject: [PATCH] placement: import center_horizontal and center_vertical Signed-off-by: Cedric GESTES Signed-off-by: Julien Danjou --- lib/awful/placement.lua.in | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/awful/placement.lua.in b/lib/awful/placement.lua.in index 8d1ef193..8fa5a05d 100644 --- a/lib/awful/placement.lua.in +++ b/lib/awful/placement.lua.in @@ -192,4 +192,37 @@ function centered(c, p) y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) end +--- Place the client centered on the horizontal axis with respect to a parent or the clients screen. +-- @param c The client. +-- @param p The parent (optional, nil for screen centering). +-- @return The new client geometry. +function center_horizontal(c, p) + local c = c or capi.client.focus + local c_geometry = c:geometry() + local s_geometry + if p then + s_geometry = p:geometry() + else + s_geometry = capi.screen[c.screen].geometry + end + return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 }) +end + +--- Place the client centered on the vertical axis with respect to a parent or the clients screen. +-- @param c The client. +-- @param p The parent (optional, nil for screen centering). +-- @return The new client geometry. +function center_vertical(c, p) + local c = c or capi.client.focus + local c_geometry = c:geometry() + local s_geometry + if p then + s_geometry = p:geometry() + else + s_geometry = capi.screen[c.screen].geometry + end + return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) +end + + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80