2016-04-17 11:15:21 +02:00
|
|
|
--- Tests for drawing geometry
|
|
|
|
|
|
|
|
local runner = require( "_runner" )
|
|
|
|
local awful = require( "awful" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local beautiful = require( "beautiful" )
|
2019-10-07 03:53:08 +02:00
|
|
|
local cruled = require("ruled.client")
|
|
|
|
local gdebug = require("gears.debug")
|
2016-04-17 11:15:21 +02:00
|
|
|
|
|
|
|
local w = nil
|
|
|
|
local w1_draw, w2_draw
|
|
|
|
|
2019-10-07 03:53:08 +02:00
|
|
|
-- Replacing the rules is not supported anymore.
|
|
|
|
local dep = gdebug.deprecate
|
|
|
|
|
|
|
|
local function set_rules(new_rules)
|
|
|
|
gdebug.deprecate = function() end
|
|
|
|
|
|
|
|
cruled.rules = {}
|
|
|
|
|
|
|
|
cruled.append_rules(new_rules)
|
|
|
|
|
|
|
|
gdebug.deprecate = dep
|
|
|
|
end
|
|
|
|
|
2016-04-17 11:15:21 +02:00
|
|
|
-- Disable automatic placement
|
2019-10-07 03:53:08 +02:00
|
|
|
set_rules {
|
|
|
|
{
|
|
|
|
rule = { },
|
|
|
|
properties = {
|
|
|
|
border_width = 0,
|
|
|
|
size_hints_honor = false,
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
width = 100,
|
|
|
|
height = 100,
|
|
|
|
border_color = beautiful.border_color_normal
|
|
|
|
}
|
2016-04-17 11:15:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2019-10-07 03:53:08 +02:00
|
|
|
set_rules {
|
2016-04-17 11:15:21 +02:00
|
|
|
-- All clients will match this rule.
|
|
|
|
{ rule = { },properties = {
|
2017-01-01 14:29:04 +01:00
|
|
|
titlebars_enabled = true,
|
|
|
|
border_width = 10,
|
|
|
|
border_color = "#00ff00",
|
|
|
|
size_hints_honor = false,
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
width = 100,
|
|
|
|
height = 100
|
|
|
|
}}
|
2016-04-17 11:15:21 +02:00
|
|
|
}
|
2017-01-01 14:31:08 +01:00
|
|
|
-- Wait for the previous c:kill() to be done
|
|
|
|
if #client.get() == 0 then
|
|
|
|
return true
|
|
|
|
end
|
2016-04-17 11:15:21 +02:00
|
|
|
end,
|
|
|
|
function(count)
|
|
|
|
if count == 1 then
|
2016-12-27 21:39:08 +01:00
|
|
|
awful.spawn("xterm")
|
2016-04-17 11:15:21 +02:00
|
|
|
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]
|
|
|
|
|
2019-11-11 02:47:43 +01:00
|
|
|
assert(not pcall(function() c._border_width = -2000 end))
|
2016-04-17 11:15:21 +02:00
|
|
|
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
|