Allow reloading of keybindings without restarting awesome

This commit is contained in:
Alexander Gehrke 2020-07-22 14:32:46 +02:00
parent bb4e0cfd29
commit 34f210646e
3 changed files with 88 additions and 64 deletions

View file

@ -133,6 +133,8 @@ local myglobalkeys = awful.util.table.join(
awful.key({ modkey }, "x", binder.spawn("dmxrandr")), awful.key({ modkey }, "x", binder.spawn("dmxrandr")),
awful.key({ modkey, "Shift" }, "x", binder.spawn("xd --dmenu")), awful.key({ modkey, "Shift" }, "x", binder.spawn("xd --dmenu")),
awful.key({ modkey }, "z", binder.spawn("dmumount")), awful.key({ modkey }, "z", binder.spawn("dmumount")),
awful.key({ modkey }, "p", binder.spawn("passmenu --type")),
awful.key({ modkey, "Shift" }, "p", binder.spawn("passmenu")),
--}}} --}}}

5
rc.lua
View file

@ -64,8 +64,9 @@ binder.modal.hide_default_options()
--binder.modal.set_x_offset(18) --binder.modal.set_x_offset(18)
binder.add_default_bindings() binder.add_default_bindings()
binder.add_bindings(tags.create_bindings()) binder.add_reloadable(tags.create_bindings)
binder.add_bindings(require("mybindings")) mybindings = awful.util.getdir("config") .. "/mybindings.lua"
binder.add_reloadable(function() return dofile(mybindings) end)
binder.add_bindings(awful.util.table.join( binder.add_bindings(awful.util.table.join(
awful.key({}, "XF86AudioRaiseVolume", function() audiowheel:up() end), awful.key({}, "XF86AudioRaiseVolume", function() audiowheel:up() end),

View file

@ -7,6 +7,7 @@ local mb = require("modalbind")
mb.init() mb.init()
local globalkeys = {} local globalkeys = {}
local globalkeyfuncs = {}
app_folders = { app_folders = {
"/usr/share/applications", "/usr/share/applications",
@ -86,81 +87,34 @@ function screen_in_wrapdir(dir, _screen)
end end
end end
local default_bindings = awful.util.table.join(
awful.key({ modkey, "Control" }, "r", awesome.restart),
awful.key({ modkey, "Shift" }, "q", awesome.quit),
awful.key({ modkey, }, "Return", spawnf(conf.cmd.terminal)),
--{{{ Layout manipulation and client position
awful.key({ modkey }, "j", function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey }, "k", function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
-- Layout manipulation
awful.key({ modkey }, "Tab", function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
awful.key({ "Mod1", }, "Tab", function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
awful.key({ modkey, "Shift" }, "j", function ()
awful.client.swap.byidx( 1)
end),
awful.key({ modkey, "Shift" }, "k", function ()
awful.client.swap.byidx( -1)
end),
awful.key({ modkey, }, "h", screen_focus_wrapdir("left")),
awful.key({ modkey, }, "l", screen_focus_wrapdir("right")),
--}}}
--{{{ Modal mappings
awful.key({ modkey }, "space", mb.grabf{keymap=layoutmap, name="Layouts"}),
awful.key({ modkey, "Control" }, "space", mb.grabf{keymap=layoutsettings, name="Layout settings", stay_in_mode=true}),
--}}}
--{{{ Audio control
--awful.key({ }, "XF86AudioLowerVolume", spawnf("amixer set Master 2%-")),
--awful.key({ }, "XF86AudioRaiseVolume", spawnf("amixer set Master 2%+")),
--awful.key({ }, "XF86AudioMute", spawnf("amixer set Master toggle")),
--}}}
--{{{ Prompt
awful.key({ modkey }, "r", conf.cmd.run),
awful.key({ modkey, "Shift" }, "r", menubar.show)
--}}}
)
function binder.add_bindings(keys) function binder.add_bindings(keys)
globalkeys = awful.util.table.join(globalkeys, keys); globalkeys = awful.util.table.join(globalkeys, keys);
return binder return binder
end end
function binder.add_default_bindings() function binder.add_reloadable(key_func)
return binder.add_bindings(default_bindings) table.insert(globalkeyfuncs, key_func)
return binder
end end
function binder.clear() function binder.clear()
globalkeys = {} globalkeys = {}
globalkeyfuncs = {}
end end
function binder.apply() function binder.apply()
root.keys(globalkeys) local allkeys = awful.util.table.clone(globalkeys)
inspect=require("lib/inspect")
print(inspect(globalkeyfuncs))
for k,v in pairs(globalkeyfuncs) do
print("k:" .. k)
local loadedkeys = v()
print(inspect(loadedkeys))
allkeys = awful.util.table.join(allkeys, loadedkeys)
end
print(inspect(allkeys))
root.keys(allkeys)
end end
local function client_opacity_set(c, default, max, step) local function client_opacity_set(c, default, max, step)
@ -227,6 +181,73 @@ function binder.client.add_bindings(keys)
clientkeys = awful.util.table.join(clientkeys, keys); clientkeys = awful.util.table.join(clientkeys, keys);
end end
local default_bindings = awful.util.table.join(
awful.key({ modkey, "Control" }, "r", awesome.restart),
awful.key({ modkey, "Shift" }, "q", awesome.quit),
awful.key({ modkey, }, "Return", spawnf(conf.cmd.terminal)),
--{{{ Layout manipulation and client position
awful.key({ modkey }, "j", function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey }, "k", function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
-- Layout manipulation
awful.key({ modkey }, "Tab", function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
awful.key({ "Mod1", }, "Tab", function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
awful.key({ modkey, "Shift" }, "j", function ()
awful.client.swap.byidx( 1)
end),
awful.key({ modkey, "Shift" }, "k", function ()
awful.client.swap.byidx( -1)
end),
awful.key({ modkey, }, "h", screen_focus_wrapdir("left")),
awful.key({ modkey, }, "l", screen_focus_wrapdir("right")),
--}}}
--{{{ Modal mappings
awful.key({ modkey }, "space", mb.grabf{keymap=layoutmap, name="Layouts"}),
awful.key({ modkey, "Control" }, "space", mb.grabf{keymap=layoutsettings, name="Layout settings", stay_in_mode=true}),
--}}}
--{{{ Audio control
--awful.key({ }, "XF86AudioLowerVolume", spawnf("amixer set Master 2%-")),
--awful.key({ }, "XF86AudioRaiseVolume", spawnf("amixer set Master 2%+")),
--awful.key({ }, "XF86AudioMute", spawnf("amixer set Master toggle")),
--}}}
--{{{ Prompt
awful.key({ modkey }, "r", conf.cmd.run),
awful.key({ modkey, "Shift" }, "r", menubar.show),
--}}}
-- reloading
awful.key({ modkey, "Control" }, "b", binder.apply)
)
function binder.add_default_bindings()
return binder.add_bindings(default_bindings)
end
return binder return binder
-- vim: set fenc=utf-8 tw=80 foldmethod=marker : -- vim: set fenc=utf-8 tw=80 foldmethod=marker :