2016-01-24 13:38:48 +01:00
|
|
|
-- Some memory leak checks involving clients as integration tests.
|
2016-03-06 10:20:45 +01:00
|
|
|
local runner = require("_runner")
|
2016-01-24 13:38:48 +01:00
|
|
|
local awful = require("awful")
|
|
|
|
local wibox = require("wibox")
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2016-01-24 13:38:48 +01:00
|
|
|
|
2019-07-22 14:24:36 +02:00
|
|
|
-- Create a titlebar and return a table with references to its member widgets.
|
|
|
|
local function create_titlebar(c)
|
|
|
|
local parts = {}
|
2017-03-08 21:18:33 +01:00
|
|
|
local buttons = gtable.join(
|
2016-12-27 21:39:08 +01:00
|
|
|
awful.button({ }, 1, function()
|
|
|
|
client.focus = c
|
|
|
|
c:raise()
|
|
|
|
awful.mouse.client.move(c)
|
|
|
|
end),
|
|
|
|
awful.button({ }, 3, function()
|
|
|
|
client.focus = c
|
|
|
|
c:raise()
|
|
|
|
awful.mouse.client.resize(c)
|
|
|
|
end)
|
|
|
|
)
|
2016-01-24 13:38:48 +01:00
|
|
|
|
|
|
|
-- Widgets that are aligned to the left
|
2019-07-22 14:24:36 +02:00
|
|
|
parts.icon = awful.titlebar.widget.iconwidget(c)
|
|
|
|
local left_layout = wibox.layout.fixed.horizontal(parts.icon)
|
2016-01-24 13:38:48 +01:00
|
|
|
left_layout:buttons(buttons)
|
|
|
|
|
|
|
|
-- The title goes in the middle
|
2019-07-22 14:24:36 +02:00
|
|
|
parts.title = awful.titlebar.widget.titlewidget(c)
|
|
|
|
parts.title:set_align("center")
|
|
|
|
local middle_layout = wibox.layout.flex.horizontal(parts.title)
|
2016-01-24 13:38:48 +01:00
|
|
|
middle_layout:buttons(buttons)
|
|
|
|
|
2019-07-22 14:24:36 +02:00
|
|
|
parts.floating_button = awful.titlebar.widget.floatingbutton(c)
|
|
|
|
parts.maximized_button = awful.titlebar.widget.maximizedbutton(c)
|
|
|
|
parts.sticky_button = awful.titlebar.widget.stickybutton(c)
|
|
|
|
parts.ontop_button = awful.titlebar.widget.ontopbutton(c)
|
|
|
|
parts.close_button = awful.titlebar.widget.closebutton(c)
|
|
|
|
|
2016-01-24 13:38:48 +01:00
|
|
|
awful.titlebar(c):set_widget(wibox.layout.align.horizontal(
|
|
|
|
left_layout,
|
|
|
|
middle_layout,
|
|
|
|
wibox.layout.fixed.horizontal(
|
2019-07-22 14:24:36 +02:00
|
|
|
parts.floating_button,
|
|
|
|
parts.maximized_button,
|
|
|
|
parts.sticky_button,
|
|
|
|
parts.ontop_button,
|
|
|
|
parts.close_button
|
2016-12-27 21:39:08 +01:00
|
|
|
)), { position = "bottom"})
|
2019-07-22 14:24:36 +02:00
|
|
|
|
|
|
|
return parts
|
|
|
|
end
|
|
|
|
|
|
|
|
-- "Enable" titlebars (so that the titlebar can prevent garbage collection)
|
|
|
|
client.connect_signal("manage", function (c)
|
|
|
|
create_titlebar(c)
|
2016-01-24 13:38:48 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- We tell the garbage collector when to work, disable it
|
|
|
|
collectgarbage("stop")
|
|
|
|
|
|
|
|
-- We try to get a client representing an already-closed client.
|
|
|
|
-- The first iteration starts xterm, the second keeps a weak reference to it and
|
|
|
|
-- closes it and the last one checks that the client object is GC'able.
|
|
|
|
local objs = nil
|
2016-02-12 09:23:41 +01:00
|
|
|
local second_call = false
|
2019-07-22 14:24:36 +02:00
|
|
|
local state
|
2016-01-24 13:38:48 +01:00
|
|
|
local steps = {
|
|
|
|
function(count)
|
|
|
|
if count == 1 then
|
|
|
|
awful.spawn("xterm")
|
|
|
|
elseif not objs then
|
|
|
|
local c = client.get()[1]
|
|
|
|
if c then
|
|
|
|
objs = setmetatable({ c }, { __mode = "v" })
|
|
|
|
c:kill()
|
|
|
|
end
|
2016-02-12 09:23:41 +01:00
|
|
|
elseif not second_call then
|
|
|
|
-- Wait for one iteration so that gears.timer handles other delayed
|
|
|
|
-- calls (= the tasklist updates)
|
|
|
|
second_call = true
|
2017-01-01 14:30:17 +01:00
|
|
|
elseif #client.get() == 0 then
|
2016-01-24 13:38:48 +01:00
|
|
|
assert(#objs == 1)
|
|
|
|
|
|
|
|
-- Test that we have a client and that it's invalid (tostring()
|
|
|
|
-- causes an "invalid object" error)
|
|
|
|
local success, msg = pcall(function() tostring(objs[1]) end)
|
|
|
|
assert(not success)
|
|
|
|
assert(msg:find("invalid object"), msg)
|
|
|
|
|
|
|
|
-- Check that it is garbage-collectable
|
|
|
|
collectgarbage("collect")
|
|
|
|
assert(#objs == 0)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end,
|
2019-07-22 14:24:36 +02:00
|
|
|
|
|
|
|
-- Test that titlebar widgets are GC'able even when the corresponding client
|
|
|
|
-- still exists.
|
|
|
|
function(count)
|
|
|
|
if count == 1 then
|
|
|
|
awful.spawn("xterm")
|
|
|
|
state = 1
|
|
|
|
elseif state == 1 then
|
|
|
|
local c = client.get()[1]
|
|
|
|
if c then
|
|
|
|
-- Create the titlebar and store references to its widgets in a
|
|
|
|
-- weak table.
|
|
|
|
objs = setmetatable({}, { __mode = "v" })
|
|
|
|
gtable.crush(objs, create_titlebar(c))
|
|
|
|
state = 2
|
|
|
|
end
|
|
|
|
elseif state == 2 then
|
|
|
|
local c = client.get()[1]
|
|
|
|
|
|
|
|
-- Recreate the titlebar; at this point old titlebar widgets should
|
|
|
|
-- become unreferenced, except for some delayed calls.
|
|
|
|
create_titlebar(c)
|
|
|
|
|
|
|
|
-- Wait for one iteration so that delayed calls would complete and
|
|
|
|
-- release remaining references to widgets.
|
|
|
|
state = 3
|
|
|
|
elseif state == 3 then
|
|
|
|
-- Check that old titlebar widgets have been destroyed.
|
|
|
|
for _ = 1, 10 do
|
|
|
|
collectgarbage("collect")
|
|
|
|
end
|
|
|
|
local num_objs = 0
|
|
|
|
for k in pairs(objs) do
|
|
|
|
if num_objs == 0 then
|
|
|
|
print("Error: titlebar widgets remaining after GC:")
|
|
|
|
end
|
|
|
|
num_objs = num_objs + 1
|
|
|
|
print(k)
|
|
|
|
end
|
|
|
|
assert(num_objs == 0)
|
|
|
|
|
|
|
|
client.get()[1]:kill()
|
|
|
|
state = 4
|
|
|
|
elseif state == 4 then
|
|
|
|
if #client.get() == 0 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
2016-01-24 13:38:48 +01:00
|
|
|
}
|
|
|
|
|
2016-03-06 10:20:45 +01:00
|
|
|
runner.run_steps(steps)
|
2016-01-24 13:38:48 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|