Merge pull request #1240 from psychon/fix-sn-callbacks

Fix spawn callbacks
This commit is contained in:
Daniel Hahler 2016-12-01 18:13:20 +01:00 committed by GitHub
commit 1d5f70e40d
3 changed files with 28 additions and 15 deletions

View File

@ -106,8 +106,8 @@ function spawn.spawn(cmd, sn_rules, callback)
enable_sn = not not enable_sn -- Force into a boolean.
local pid, snid = capi.awesome.spawn(cmd, enable_sn)
-- The snid will be nil in case of failure
if snid and type(sn_rules) == "table" then
sn_rules = sn_rules or {}
if snid then
sn_rules = type(sn_rules) ~= "boolean" and sn_rules or {}
spawn.snid_buffer[snid] = { sn_rules, { callback } }
end
return pid, snid

View File

@ -79,25 +79,24 @@ local function init()
end
-- Hack needed for awesome's Startup Notification machinery
local function get_snid(sn_rules)
local success, snid = spawn({ "/bin/true" }, sn_rules)
local function get_snid(sn_rules, callback)
local success, snid = spawn({ "/bin/true" }, sn_rules, callback)
assert(success)
assert(snid)
return snid
end
return function(class, title, sn_rules)
return function(class, title, sn_rules, callback)
class = class or "test_app"
title = title or "Awesome test client"
init()
local snid = sn_rules and get_snid(sn_rules) or ""
local snid = (sn_rules or callback) and get_snid(sn_rules, callback) or ""
local data = class .. "\n" .. title .. "\n" .. snid .. "\n"
local success, msg = pipe:write_all(data)
assert(success, msg)
-- TODO: Fix the API of this function
return true, sn_rules and snid or nil
return snid
end
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -12,14 +12,18 @@ client.connect_signal("manage", function(c)
tostring(c.machine) .. " ~= " .. tostring(awesome.hostname))
end)
local snid
local num_callbacks = 0
local function callback(c)
assert(c.startup_id == snid)
num_callbacks = num_callbacks + 1
end
local ret, snid
local steps = {
function(count)
if count == 1 then
ret, snid = test_client("foo", "bar", true)
snid = test_client("foo", "bar", true)
elseif manage_called then
assert(ret)
assert(snid)
assert(snid == c_snid)
return true
@ -31,14 +35,24 @@ local steps = {
function(count)
if count == 1 then
manage_called = false
ret, snid = test_client("bar", "foo", false)
test_client("bar", "foo", false)
elseif manage_called then
assert(ret)
assert(snid == nil)
assert(c_snid == nil, "c.startup_snid should be nil!")
return true
end
end,
function(count)
if count == 1 then
manage_called = false
snid = test_client("baz", "barz", false, callback)
elseif manage_called then
assert(snid)
assert(snid == c_snid)
assert(num_callbacks == 1, num_callbacks)
return true
end
end,
}
runner.run_steps(steps)