diff --git a/lib/awful/spawn.lua b/lib/awful/spawn.lua index 6b99c4cd..339049fd 100644 --- a/lib/awful/spawn.lua +++ b/lib/awful/spawn.lua @@ -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 diff --git a/tests/_client.lua b/tests/_client.lua index e9f586b8..440af23c 100644 --- a/tests/_client.lua +++ b/tests/_client.lua @@ -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 diff --git a/tests/test-spawn-snid.lua b/tests/test-spawn-snid.lua index 06adc968..83890661 100644 --- a/tests/test-spawn-snid.lua +++ b/tests/test-spawn-snid.lua @@ -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 + 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)