2014-10-04 08:53:01 +02:00
|
|
|
-- This helper module help retro-generate the clients layout from awful
|
|
|
|
-- this is a giant hack and doesn't even always work and require upstream
|
|
|
|
-- patches
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local ipairs,math = ipairs,math
|
|
|
|
local awful = require("awful")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local color = require( "gears.color")
|
|
|
|
local util = require( "collision.util" )
|
2016-02-09 06:10:11 +01:00
|
|
|
local shape = require( "gears.shape" )
|
2014-10-04 08:53:01 +02:00
|
|
|
local capi = { screen = screen, client=client }
|
|
|
|
|
|
|
|
local module = {}
|
|
|
|
local margin = 2
|
|
|
|
local radius = 4
|
|
|
|
|
|
|
|
-- Emulate a client using meta table magic
|
|
|
|
local function gen_cls(c,results)
|
|
|
|
local ret = setmetatable({},{__index = function(t,i)
|
|
|
|
local ret2 = c[i]
|
|
|
|
if type(ret2) == "function" then
|
|
|
|
if i == "geometry" then
|
|
|
|
return function(self,...)
|
|
|
|
if #{...} > 0 then
|
|
|
|
local geom = ({...})[1]
|
|
|
|
-- Make a copy as the original will be changed
|
|
|
|
results[c] = awful.util.table.join(({...})[1],{})
|
|
|
|
return geom
|
|
|
|
end
|
|
|
|
return c:geometry()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return function(self,...) return ret2(c,...) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return ret2
|
|
|
|
end})
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function module.get_geometry(tag)
|
2014-10-05 05:19:04 +02:00
|
|
|
local cls,results,flt = {},setmetatable({},{__mode="k"}),{}
|
2016-06-13 05:31:36 +02:00
|
|
|
local s = tag.screen
|
2014-10-05 05:19:04 +02:00
|
|
|
local l = awful.tag.getproperty(tag,"layout")
|
2014-10-04 08:53:01 +02:00
|
|
|
local focus,focus_wrap = capi.client.focus,nil
|
2014-10-05 05:19:04 +02:00
|
|
|
for k,c in ipairs (tag:clients()) do
|
|
|
|
-- Handle floating client separately
|
2014-10-16 05:50:58 +02:00
|
|
|
if not c.minimized then
|
2016-06-13 05:31:36 +02:00
|
|
|
local floating = c.floating
|
2014-10-16 05:50:58 +02:00
|
|
|
if (not floating) and (not l == awful.layout.suit.floating) then
|
|
|
|
cls[#cls+1] = gen_cls(c,results)
|
|
|
|
if c == focus then
|
|
|
|
focus_wrap = cls[#cls]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
flt[#flt+1] = c:geometry()
|
2014-10-05 05:19:04 +02:00
|
|
|
end
|
2014-10-04 08:53:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- The magnifier layout require a focussed client
|
|
|
|
-- there wont be any as that layout is not selected
|
|
|
|
-- take one at random or (TODO) use stack data
|
|
|
|
if not focus_wrap then
|
|
|
|
focus_wrap = cls[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
local param = {
|
|
|
|
tag = tag,
|
|
|
|
screen = 1,
|
|
|
|
clients = cls,
|
|
|
|
focus = focus_wrap,
|
|
|
|
workarea = capi.screen[s or 1].workarea
|
|
|
|
}
|
|
|
|
|
|
|
|
l.arrange(param)
|
|
|
|
|
2014-10-05 05:19:04 +02:00
|
|
|
return results,flt
|
2014-10-04 08:53:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function module.draw(tag,cr,width,height)
|
|
|
|
local worked = false
|
2014-10-05 05:19:04 +02:00
|
|
|
local l,l2 = module.get_geometry(tag)
|
2016-06-13 05:31:36 +02:00
|
|
|
local s = tag.screen
|
2014-10-04 08:53:01 +02:00
|
|
|
local scr_geo = capi.screen[s or 1].workarea
|
|
|
|
local ratio = height/scr_geo.height
|
|
|
|
local w_stretch = width/(scr_geo.width*ratio)
|
|
|
|
local r,g,b = util.get_rgb()
|
|
|
|
cr:set_line_width(3)
|
2014-10-05 05:19:04 +02:00
|
|
|
for c,ll in ipairs({l,l2}) do
|
|
|
|
for c,geom in pairs(ll) do
|
2016-02-09 06:10:11 +01:00
|
|
|
shape.transform(shape.rounded_rect)
|
|
|
|
: translate(geom.x*ratio*w_stretch+margin, geom.y*ratio+margin) (
|
|
|
|
cr,
|
|
|
|
geom.width*ratio*w_stretch-margin*2,
|
|
|
|
geom.height*ratio-margin*2,
|
|
|
|
radius
|
|
|
|
)
|
2014-10-05 05:19:04 +02:00
|
|
|
cr:close_path()
|
|
|
|
cr:set_source_rgba(r,g,b,0.7)
|
|
|
|
cr:stroke_preserve()
|
|
|
|
cr:set_source_rgba(r,g,b,0.2)
|
|
|
|
cr:fill()
|
|
|
|
|
|
|
|
-- Draw an icon in the region
|
|
|
|
--TODO
|
|
|
|
|
|
|
|
worked = true
|
|
|
|
end
|
2014-10-04 08:53:01 +02:00
|
|
|
end
|
|
|
|
--TODO floating clients
|
|
|
|
return worked
|
|
|
|
end
|
|
|
|
|
|
|
|
return module
|
2016-06-13 05:31:36 +02:00
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|