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 <anurag08priyam@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Anurag Priyam 2012-01-15 16:27:47 +05:30 committed by Uli Schlachter
parent 7f8ef18cd8
commit c6e92081e2
1 changed files with 13 additions and 7 deletions

View File

@ -17,6 +17,7 @@ local capi =
} }
local client = require("awful.client") local client = require("awful.client")
local layout = require("awful.layout") local layout = require("awful.layout")
local a_screen = require("awful.screen")
--- Places client according to special criteria. --- Places client according to special criteria.
module("awful.placement") module("awful.placement")
@ -105,8 +106,9 @@ end
function no_offscreen(c) function no_offscreen(c)
local c = c or capi.client.focus local c = c or capi.client.focus
local geometry = c:geometry() local geometry = c:geometry()
local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y)
local border = c.border_width 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 if geometry.x + geometry.width + 2*border > screen_geometry.x + screen_geometry.width then
geometry.x = screen_geometry.x + screen_geometry.width - geometry.width 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. --- Place the client where there's place available with minimum overlap.
-- @param c The client. -- @param c The client.
function no_overlap(c) 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 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 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 if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then
areas = area_remove(areas, cl:geometry()) areas = area_remove(areas, cl:geometry())
@ -192,11 +195,12 @@ end
function centered(c, p) function centered(c, p)
local c = c or capi.client.focus local c = c or capi.client.focus
local c_geometry = c:geometry() local c_geometry = c:geometry()
local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)
local s_geometry local s_geometry
if p then if p then
s_geometry = p:geometry() s_geometry = p:geometry()
else else
s_geometry = capi.screen[c.screen].geometry s_geometry = capi.screen[screen].geometry
end end
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2, 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 }) y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
@ -209,11 +213,12 @@ end
function center_horizontal(c, p) function center_horizontal(c, p)
local c = c or capi.client.focus local c = c or capi.client.focus
local c_geometry = c:geometry() local c_geometry = c:geometry()
local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)
local s_geometry local s_geometry
if p then if p then
s_geometry = p:geometry() s_geometry = p:geometry()
else else
s_geometry = capi.screen[c.screen].geometry s_geometry = capi.screen[screen].geometry
end end
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 }) return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 })
end end
@ -225,11 +230,12 @@ end
function center_vertical(c, p) function center_vertical(c, p)
local c = c or capi.client.focus local c = c or capi.client.focus
local c_geometry = c:geometry() local c_geometry = c:geometry()
local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)
local s_geometry local s_geometry
if p then if p then
s_geometry = p:geometry() s_geometry = p:geometry()
else else
s_geometry = capi.screen[c.screen].geometry s_geometry = capi.screen[screen].geometry
end end
return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
end end