From 7bf1a276eff2c29f01669692d474b0db4f085ce9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 4 Mar 2019 16:56:15 -0500 Subject: [PATCH] naughty: Use cleaner code to update the legacy actions. The old code surprisingly worked, but reading this again, better make some changes. --- lib/naughty/notification.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index d7f2a77c..2e0b34cd 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -380,16 +380,18 @@ local function convert_actions(actions) local naction = require("naughty.action") + local new_actions = {} + -- Does not attempt to handle when there is a mix of strings and objects for idx, name in pairs(actions) do - local cb = nil + local cb, old_idx = nil, idx if type(name) == "function" then cb = name end if type(idx) == "string" then - name, idx = idx, nil + name, idx = idx, #actions+1 end local a = naction { @@ -401,9 +403,14 @@ local function convert_actions(actions) a:connect_signal("invoked", cb) end - -- Yes, it modifies `args`, this is legacy code, cloning the args - -- just for this isn't worth it. - actions[idx] = a + new_actions[old_idx] = a + end + + -- Yes, it modifies `args`, this is legacy code, cloning the args + -- just for this isn't worth it. + for old_idx, a in pairs(new_actions) do + actions[a.position] = a + actions[ old_idx ] = nil end end @@ -497,7 +504,7 @@ local function create(args) rawget(n, "preset") or {} )) - if is_old_action then + if is_old_action then convert_actions(args.actions) end