From 244932749b6a4b37645aba2b4b20a0c7cc530e8b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 3 Mar 2019 08:52:31 +0100 Subject: [PATCH] awful.spawn: Make rules optional in once / single_instance There is not much good reason why this should be required and making it optional is almost trivial, as this patch shows. Signed-off-by: Uli Schlachter --- lib/awful/rules.lua | 4 +++- lib/awful/spawn.lua | 4 ++-- tests/test-spawn.lua | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index fdc18554c..9780c63cd 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -388,7 +388,9 @@ local function apply_singleton_rules(c, props, callbacks) if info then c.single_instance_id = info.hash - gtable.crush(props, info.rules) + if info.rules then + gtable.crush(props, info.rules) + end table.insert(callbacks, info.callback) table.insert(info.instances, c) diff --git a/lib/awful/spawn.lua b/lib/awful/spawn.lua index 6474d6286..ae18af8de 100644 --- a/lib/awful/spawn.lua +++ b/lib/awful/spawn.lua @@ -637,7 +637,7 @@ end -- Note that this also wont work with shell or terminal commands. -- -- @tparam string|table cmd The command. --- @tparam table rules The properties that need to be applied to the client. +-- @tparam[opt] table rules The properties that need to be applied to the client. -- @tparam[opt] function matcher A matching function to find the instance -- among running clients. -- @tparam[opt] string unique_id A string to identify the client so it isn't executed @@ -669,7 +669,7 @@ end -- faster than the client has time to start. -- -- @tparam string|table cmd The command. --- @tparam table rules The properties that need to be applied to the client. +-- @tparam[opt] table rules The properties that need to be applied to the client. -- @tparam[opt] function matcher A matching function to find the instance -- among running clients. -- @tparam[opt] string unique_id A string to identify the client so it isn't executed diff --git a/tests/test-spawn.lua b/tests/test-spawn.lua index 2af097490..538c9cdcc 100644 --- a/tests/test-spawn.lua +++ b/tests/test-spawn.lua @@ -334,6 +334,20 @@ local steps = { function() if #client.get() ~= 1 then return end assert(matcher_called) + client.get()[1]:kill() + return true + end, + -- Test that rules are optional + function() + if #client.get() ~= 0 then return end + + spawn.single_instance(tiny_client("client4")) + spawn.once(tiny_client("client5")) + + return true + end, + function() + if #client.get() ~= 2 then return end return true end, }