awesome/tests/test-geometry.lua
Emmanuel Lepage Vallee 04c757322c client: Turn rc.lua logic into a new request::border signal.
The default `rc.lua` was using the focus/unfocus signals to set
the border color along with `awful.rules`. This logic block was
no longer aligned with the rest of `rc.lua` since it was
the only place where `beautiful` variables where only used by
`rc.lua`.

On top of this, the new request handler also has extra contexts
for the urgent and floating/maximixed use cases. So it can be used
by themes to implement much smarter borders than just focus based
ones. They were previously limited by the fact most of the
(un-monkey-patchable) logic was in `rc.lua`.

Note that this commit also shuffle the awful.rules order between
the titlebar and the border and changes the tests accordignly.
After some consideration, I came to the conclusion the previous
behavior was bogus and the fact that the placement tests required
to know about the titlebar height is simply a proof of that. The
change was required in this commit because since the border is no
longer in the default rules, a new buggy edge case surfaced.
2020-01-11 15:43:11 -08:00

245 lines
6.5 KiB
Lua

--- Tests for drawing geometry
local runner = require( "_runner" )
local awful = require( "awful" )
local wibox = require( "wibox" )
local beautiful = require( "beautiful" )
local w = nil
local w1_draw, w2_draw
-- Disable automatic placement
awful.rules.rules = {
{ rule = { }, properties = {
border_width = 0,
size_hints_honor = false,
x = 0,
y = 0,
width = 100,
height = 100,
border_color = beautiful.border_color_normal
}
}
}
local steps = {
function()
if #client.get() == 0 then
return true
end
for _,c in ipairs(client.get()) do
c:kill()
end
end,
-- border_color should get applied via focus signal for first client on tag.
function(count)
if count == 1 then
awful.spawn("xterm")
else
local c = client.get()[1]
if c then
assert(c.size_hints_honor == false )
assert(c.border_width == 0 )
assert(c:geometry().x == 0 )
assert(c:geometry().y == 0 )
assert(c:geometry().height == 100 )
assert(c:geometry().width == 100 )
c:kill()
return true
end
end
end,
function()
awful.rules.rules = {
-- All clients will match this rule.
{ rule = { },properties = {
titlebars_enabled = true,
border_width = 10,
border_color = "#00ff00",
size_hints_honor = false,
x = 0,
y = 0,
width = 100,
height = 100
}}
}
-- Wait for the previous c:kill() to be done
if #client.get() == 0 then
return true
end
end,
function(count)
if count == 1 then
awful.spawn("xterm")
else
local c = client.get()[1]
if c then
assert(c.border_width == 10 )
assert(c:geometry().x == 0 )
assert(c:geometry().y == 0 )
assert(c:geometry().height == 100 )
assert(c:geometry().width == 100 )
c.border_width = 20
return true
end
end
end,
function()
local c = client.get()[1]
assert(c.border_width == 20 )
assert(c:geometry().x == 0 )
assert(c:geometry().y == 0 )
assert(c:geometry().height == 100 )
assert(c:geometry().width == 100 )
c.border_width = 0
return true
end,
function()
local c = client.get()[1]
assert(not pcall(function() c._border_width = -2000 end))
assert(c.border_width==0)
c.border_width = 125
return true
end,
function()
local c = client.get()[1]
assert(c.border_width == 125 )
assert(c:geometry().x == 0 )
assert(c:geometry().y == 0 )
assert(c:geometry().height == 100 )
assert(c:geometry().width == 100 )
-- So it doesn't hide the other tests
c:kill()
return true
end,
function()
w = wibox {
ontop = true,
border_width = 20,
x = 100,
y = 100,
width = 100,
height = 100,
visible = true,
}
assert(w)
assert(w.border_width == 20 )
assert(w.width == 100 )
assert(w.height == 100 )
assert(w.x == 100 )
assert(w.y == 100 )
w:setup {
fit = function(_, _, _, height)
return height, height -- A square taking the full height
end,
draw = function(_, _, cr, width, height)
assert(width == 100)
assert(height == 100)
w1_draw = true
cr:set_source_rgb(1, 0, 0) -- Red
cr:arc(height/2, height/2, height/2, 0, math.pi*2)
cr:fill()
end,
layout = wibox.widget.base.make_widget,
}
return true
end,
function()
w.border_width = 0
assert(w1_draw)
return true
end,
function()
assert(w.border_width == 0 )
assert(w.width == 100 )
assert(w.height == 100 )
assert(w.x == 100 )
assert(w.y == 100 )
w:setup {
fit = function(_, _, _, height)
return height, height -- A square taking the full height
end,
draw = function(_, _, cr, width, height)
assert(width == 100)
assert(height == 100)
w2_draw = true
cr:set_source_rgb(1, 0, 0) -- Red
cr:arc(height/2, height/2, height/2, 0, math.pi*2)
cr:fill()
end,
layout = wibox.widget.base.make_widget,
}
w.visible = false
return true
end,
function()
-- Remove the widget before the size change to avoid the asserts
w:setup {
fit = function(_, _, _, height)
return height, height -- A square taking the full height
end,
draw = function(_, _, cr, _, height)
cr:set_source_rgb(1, 0, 1) -- Purple
cr:arc(height/2, height/2, height/2, 0, math.pi*2)
cr:fill()
end,
layout = wibox.widget.base.make_widget,
}
w.visible = true
assert(w2_draw)
assert(w.border_width == 0 )
assert(w.width == 100 )
assert(w.height == 100 )
assert(w.x == 100 )
assert(w.y == 100 )
w.border_width = 5
w:geometry {
x = 200,
y = 200,
width = 200,
height = 200,
}
return true
end,
function()
assert(w.border_width == 5 )
assert(w.width == 200 )
assert(w.height == 200 )
assert(w.x == 200 )
assert(w.y == 200 )
return true
end
}
runner.run_steps(steps)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80