awful.spawn: Separate rules from callbacks (#1186)
When adding callbacks as a `callback` entry in a property, the callback is run by `awful.rules`, because it does `c.callback = result_of_function`. This is obviously not intended. Also, this causes the callbacks to run twice, because the code already handled this `callback` property specially. Fix this by just not merging callbacks with the normal rules at all. Fixes: https://github.com/awesomeWM/awesome/issues/1159 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
80832601fc
commit
70d4961a3e
|
@ -491,9 +491,8 @@ function rules.execute(c, props, callbacks)
|
|||
end
|
||||
end
|
||||
|
||||
function rules.completed_with_payload_callback(c, props)
|
||||
rules.execute(c, props, type(props.callback) == "function" and
|
||||
{props.callback} or props.callback )
|
||||
function rules.completed_with_payload_callback(c, props, callbacks)
|
||||
rules.execute(c, props, callbacks)
|
||||
end
|
||||
|
||||
client.connect_signal("spawn::completed_with_payload", rules.completed_with_payload_callback)
|
||||
|
|
|
@ -70,9 +70,11 @@ end
|
|||
spawn.snid_buffer = {}
|
||||
|
||||
function spawn.on_snid_callback(c)
|
||||
local props = spawn.snid_buffer[c.startup_id]
|
||||
if props then
|
||||
c:emit_signal("spawn::completed_with_payload", props)
|
||||
local entry = spawn.snid_buffer[c.startup_id]
|
||||
if entry then
|
||||
local props = entry[1]
|
||||
local callback = entry[2]
|
||||
c:emit_signal("spawn::completed_with_payload", props, callback)
|
||||
spawn.snid_buffer[c.startup_id] = nil
|
||||
end
|
||||
end
|
||||
|
@ -102,15 +104,11 @@ function spawn.spawn(cmd, sn_rules, callback)
|
|||
if cmd and cmd ~= "" then
|
||||
local enable_sn = (sn_rules ~= false or callback)
|
||||
enable_sn = not not enable_sn -- Force into a boolean.
|
||||
if not sn_rules and callback then
|
||||
sn_rules = {callback=callback}
|
||||
elseif callback then
|
||||
sn_rules.callback = callback
|
||||
end
|
||||
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
|
||||
spawn.snid_buffer[snid] = sn_rules
|
||||
sn_rules = sn_rules or {}
|
||||
spawn.snid_buffer[snid] = { sn_rules, { callback } }
|
||||
end
|
||||
return pid, snid
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue