From c6e92081e28188b5fa940fe5ab335227bcd433d5 Mon Sep 17 00:00:00 2001 From: Anurag Priyam Date: Sun, 15 Jan 2012 16:27:47 +0530 Subject: [PATCH] awful.placement: can now operate on any object with a set geometry So the utility of `awful.placement` is not merely limited to client objects, but also to wiboxes. [us: use appropriate naming convention; catch misplaced statement] Signed-off-by: Anurag Priyam Signed-off-by: Uli Schlachter --- lib/awful/placement.lua.in | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/awful/placement.lua.in b/lib/awful/placement.lua.in index fa3d37bd..9520faa8 100644 --- a/lib/awful/placement.lua.in +++ b/lib/awful/placement.lua.in @@ -17,6 +17,7 @@ local capi = } local client = require("awful.client") local layout = require("awful.layout") +local a_screen = require("awful.screen") --- Places client according to special criteria. module("awful.placement") @@ -105,8 +106,9 @@ end function no_offscreen(c) local c = c or capi.client.focus local geometry = c:geometry() + local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y) local border = c.border_width - local screen_geometry = capi.screen[c.screen].workarea + local screen_geometry = capi.screen[screen].workarea if geometry.x + geometry.width + 2*border > screen_geometry.x + screen_geometry.width then geometry.x = screen_geometry.x + screen_geometry.width - geometry.width @@ -126,10 +128,11 @@ end --- Place the client where there's place available with minimum overlap. -- @param c The client. function no_overlap(c) - local cls = client.visible(c.screen) - local curlay = layout.get() - local areas = { capi.screen[c.screen].workarea } local geometry = c:geometry() + local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y) + local cls = client.visible(screen) + local curlay = layout.get() + local areas = { capi.screen[screen].workarea } for i, cl in pairs(cls) do if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then areas = area_remove(areas, cl:geometry()) @@ -192,11 +195,12 @@ end function centered(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() + local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry if p then s_geometry = p:geometry() else - s_geometry = capi.screen[c.screen].geometry + s_geometry = capi.screen[screen].geometry end return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2, y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) @@ -209,11 +213,12 @@ end function center_horizontal(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() + local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry if p then s_geometry = p:geometry() else - s_geometry = capi.screen[c.screen].geometry + s_geometry = capi.screen[screen].geometry end return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 }) end @@ -225,11 +230,12 @@ end function center_vertical(c, p) local c = c or capi.client.focus local c_geometry = c:geometry() + local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry if p then s_geometry = p:geometry() else - s_geometry = capi.screen[c.screen].geometry + s_geometry = capi.screen[screen].geometry end return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) end