Cannot get binds inside a function to work in lua #14282
-
|
Hi, I migrated my config to lua and hoped to get rid of my plugins. I ended up writing this to get per-monitor workspaces (ignore the indentation), but the keybinds don't do anything: local wsKeys = {
[1] = 'ampersand',
[2] = 'eacute',
[3] = 'quotedbl',
[4] = 'apostrophe',
[5] = 'parenleft',
[6] = 'minus',
[7] = 'egrave',
[8] = 'underscore',
[9] = 'ccedilla',
[10] = 'agrave',
}
local function mod(key)
return 'SUPER + ' .. key
end
local function modShift(key)
return mod('SHIFT + ' .. key)
end
local function wsId(ws)
local mon = hl.get_active_monitor()
return ws + 10 * mon.id
end
for ws, key in pairs(wsKeys) do
hl.bind(mod(key), function()
return hl.dsp.focus({ workspace = wsId(ws) })
end)
hl.bind(modShift(key), function()
return hl.dsp.window.move({ workspace = wsId(ws) })
end)
end
I debugged with notifications inside the keybind callback, and The docs seems to say that it is possible to call functions inside binds (for multiple dispatchers), am I misunderstanding something ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
you dont need return in there |
Beta Was this translation helpful? Give feedback.
-
for ws, key in pairs(wsKeys) do
hl.bind(mod(key), function()
return hl.dsp.focus({ workspace = wsId(ws) })
end)
hl.bind(modShift(key), function()
return hl.dsp.window.move({ workspace = wsId(ws) })
end)
end
I think you simply want |
Beta Was this translation helpful? Give feedback.
hl.dsp.functions return an object, they don't invoke any operation. What you are essentially doing is attaching a lua fn which does nothing, to a keybind.I think you simply want
hl.dispatch()instead ofreturn.