From f9cdc98c73632c69c6c06159a8b45097f8efc88c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 28 Nov 2016 20:58:28 +0100 Subject: [PATCH 1/2] Fix spawn callbacks Spawn callbacks were never invoked when no startup-notification-rules were given. This commit fixes the code so that "startup done" callbacks are also called when no rules were given. Fixes: https://github.com/awesomeWM/awesome/issues/1218 Signed-off-by: Uli Schlachter --- lib/awful/spawn.lua | 4 ++-- tests/_client.lua | 10 +++++----- tests/test-spawn-snid.lua | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) 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..af664b65 100644 --- a/tests/_client.lua +++ b/tests/_client.lua @@ -79,25 +79,25 @@ 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 true, (sn_rules or callback) and snid or nil 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..37da3b09 100644 --- a/tests/test-spawn-snid.lua +++ b/tests/test-spawn-snid.lua @@ -12,8 +12,13 @@ client.connect_signal("manage", function(c) tostring(c.machine) .. " ~= " .. tostring(awesome.hostname)) end) - local ret, snid +local num_callbacks = 0 +local function callback(c) + assert(c.startup_id == snid) + num_callbacks = num_callbacks + 1 +end + local steps = { function(count) if count == 1 then @@ -38,7 +43,20 @@ local steps = { assert(c_snid == nil, "c.startup_snid should be nil!") return true end - end + end, + + function(count) + if count == 1 then + manage_called = false + ret, snid = test_client("baz", "barz", false, callback) + elseif manage_called then + assert(ret) + assert(snid) + assert(snid == c_snid) + assert(num_callbacks == 1, num_callbacks) + return true + end + end, } runner.run_steps(steps) From 3a7e14e5d73c406eeb84b2fa131882a560c6f4af Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 28 Nov 2016 21:02:27 +0100 Subject: [PATCH 2/2] Improve API of test/_client.lua The first return value was always true. How useless... Signed-off-by: Uli Schlachter --- tests/_client.lua | 3 +-- tests/test-spawn-snid.lua | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/_client.lua b/tests/_client.lua index af664b65..440af23c 100644 --- a/tests/_client.lua +++ b/tests/_client.lua @@ -96,8 +96,7 @@ return function(class, title, sn_rules, callback) local success, msg = pipe:write_all(data) assert(success, msg) - -- TODO: Fix the API of this function - return true, (sn_rules or callback) 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 37da3b09..83890661 100644 --- a/tests/test-spawn-snid.lua +++ b/tests/test-spawn-snid.lua @@ -12,7 +12,7 @@ client.connect_signal("manage", function(c) tostring(c.machine) .. " ~= " .. tostring(awesome.hostname)) end) -local ret, snid +local snid local num_callbacks = 0 local function callback(c) assert(c.startup_id == snid) @@ -22,9 +22,8 @@ end 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 @@ -36,10 +35,8 @@ 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 @@ -48,9 +45,8 @@ local steps = { function(count) if count == 1 then manage_called = false - ret, snid = test_client("baz", "barz", false, callback) + snid = test_client("baz", "barz", false, callback) elseif manage_called then - assert(ret) assert(snid) assert(snid == c_snid) assert(num_callbacks == 1, num_callbacks)