tests: Improve the awful example template

* Support async operations
 * Support `awful.popup`
 * Support minimized clients
This commit is contained in:
Emmanuel Lepage Vallee 2017-08-10 00:27:09 -04:00
parent 90342b62c6
commit c3302c4bbe
1 changed files with 84 additions and 61 deletions

View File

@ -11,6 +11,11 @@ local wibox = require( "wibox" )
-- Run the test -- Run the test
local args = loadfile(file_path)() or {} local args = loadfile(file_path)() or {}
-- Emulate the event loop for 5 iterations
for _ = 1, 5 do
awesome.emit_signal("refresh")
end
-- Draw the result -- Draw the result
local img = cairo.SvgSurface.create(image_path..".svg", screen._get_extents() ) local img = cairo.SvgSurface.create(image_path..".svg", screen._get_extents() )
@ -30,26 +35,28 @@ local function draw_mouse(x, y)
end end
-- Print an outline for the screens -- Print an outline for the screens
for _, s in ipairs(screen) do if not screen.no_outline then
cr:save() for _, s in ipairs(screen) do
-- Draw the screen outline cr:save()
cr:set_source(color("#00000044")) -- Draw the screen outline
cr:set_line_width(1.5) cr:set_source(color("#00000044"))
cr:set_dash({10,4},1) cr:set_line_width(1.5)
cr:rectangle(s.geometry.x+0.75,s.geometry.y+0.75,s.geometry.width-1.5,s.geometry.height-1.5) cr:set_dash({10,4},1)
cr:stroke() cr:rectangle(s.geometry.x+0.75,s.geometry.y+0.75,s.geometry.width-1.5,s.geometry.height-1.5)
cr:stroke()
-- Draw the workarea outline -- Draw the workarea outline
cr:set_source(color("#00000033")) cr:set_source(color("#00000033"))
cr:rectangle(s.workarea.x,s.workarea.y,s.workarea.width,s.workarea.height) cr:rectangle(s.workarea.x,s.workarea.y,s.workarea.width,s.workarea.height)
cr:stroke() cr:stroke()
-- Draw the padding outline -- Draw the padding outline
--TODO --TODO
cr:restore() cr:restore()
end
end end
cr:set_line_width(beautiful.border_width) cr:set_line_width(beautiful.border_width/2)
cr:set_source(color(beautiful.border_color)) cr:set_source(color(beautiful.border_color))
@ -125,11 +132,7 @@ local function client_widget(c, col, label)
return wibox.widget { return wibox.widget {
{ {
{ l,
l,
margins = bw + 1, -- +1 because the the SVG AA
layout = wibox.container.margin
},
{ {
text = label or "", text = label or "",
align = "center", align = "center",
@ -138,22 +141,40 @@ local function client_widget(c, col, label)
}, },
layout = wibox.layout.stack layout = wibox.layout.stack
}, },
shape_border_width = bw*2, shape_border_width = bw,
shape_border_color = beautiful.border_color, shape_border_color = beautiful.border_color,
shape_clip = true, shape_clip = true,
fg = beautiful.fg_normal or "#000000", fg = beautiful.fg_normal or "#000000",
bg = col, bg = col,
forced_width = geo.width + 2*bw,
forced_height = geo.height + 2*bw,
shape = function(cr2, w, h) shape = function(cr2, w, h)
return shape.rounded_rect(cr2, w, h, args.radius or 5) return shape.rounded_rect(cr2, w, h, args.radius or 5)
end, end,
widget = wibox.container.background, forced_width = geo.width + 2*bw,
forced_height = geo.height + 2*bw,
widget = wibox.container.background,
} }
end end
-- Add all wiboxes -- Add all wiboxes
-- Fix the wibox geometries that have a dependency on their content
for _, d in ipairs(drawin.get()) do
local w = d.get_wibox and d:get_wibox() or nil
if w then
-- Force a full layout first as widgets with as the awful.popup have
-- interdependencies between the content and the container
if w._apply_size_now then
w:_apply_size_now()
end
end
end
-- Emulate the event loop for another 5 iterations
for _ = 1, 5 do
awesome.emit_signal("refresh")
end
for _, d in ipairs(drawin.get()) do for _, d in ipairs(drawin.get()) do
local w = d.get_wibox and d:get_wibox() or nil local w = d.get_wibox and d:get_wibox() or nil
if w then if w then
@ -164,43 +185,45 @@ end
-- Loop each clients geometry history and paint it -- Loop each clients geometry history and paint it
for _, c in ipairs(client.get()) do for _, c in ipairs(client.get()) do
local pgeo = nil if not c.minimized then
for _, geo in ipairs(c._old_geo) do local pgeo = nil
if not geo._hide then for _, geo in ipairs(c._old_geo) do
total_area:add_at( if not geo._hide then
client_widget(c, c.color or geo._color or beautiful.bg_normal, geo._label), total_area:add_at(
{x=geo.x, y=geo.y} client_widget(c, c.color or geo._color or beautiful.bg_normal, geo._label),
) {x=geo.x, y=geo.y}
)
end
-- Draw lines between the old and new corners
if pgeo and not args.hide_lines then
cr:save()
cr:set_source_rgba(0,0,0,.1)
-- Top left
cr:move_to(pgeo.x, pgeo.y)
cr:line_to(geo.x, geo.y)
cr:stroke()
-- Top right
cr:move_to(pgeo.x+pgeo.width, pgeo.y)
cr:line_to(geo.x+pgeo.width, geo.y)
-- Bottom left
cr:move_to(pgeo.x, pgeo.y+pgeo.height)
cr:line_to(geo.x, geo.y+geo.height)
cr:stroke()
-- Bottom right
cr:move_to(pgeo.x+pgeo.width, pgeo.y+pgeo.height)
cr:line_to(geo.x+pgeo.width, geo.y+geo.height)
cr:stroke()
cr:restore()
end
pgeo = geo
end end
-- Draw lines between the old and new corners
if pgeo and not args.hide_lines then
cr:save()
cr:set_source_rgba(0,0,0,.1)
-- Top left
cr:move_to(pgeo.x, pgeo.y)
cr:line_to(geo.x, geo.y)
cr:stroke()
-- Top right
cr:move_to(pgeo.x+pgeo.width, pgeo.y)
cr:line_to(geo.x+pgeo.width, geo.y)
-- Bottom left
cr:move_to(pgeo.x, pgeo.y+pgeo.height)
cr:line_to(geo.x, geo.y+geo.height)
cr:stroke()
-- Bottom right
cr:move_to(pgeo.x+pgeo.width, pgeo.y+pgeo.height)
cr:line_to(geo.x+pgeo.width, geo.y+geo.height)
cr:stroke()
cr:restore()
end
pgeo = geo
end end
end end