rc.lua: Add root keys and buttons instead of setting the list.

As visible in various modules and even built-in components like
`awful.keygrabber`, it was previously necessary to work around the
fact that keybindings could not be added later without using some
low level API hacks.

From now on, `rc.lua` will be a good citizen and use the same APIs as
the module to manage keybindings.
This commit is contained in:
Emmanuel Lepage Vallee 2018-12-28 21:18:25 -05:00
parent 4501f0e768
commit 3b5db8a9be
1 changed files with 75 additions and 70 deletions

View File

@ -219,25 +219,56 @@ end)
-- {{{ Mouse bindings
-- @DOC_ROOT_BUTTONS@
root.buttons = {
awful.mouse.append_global_mousebindings({
awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev),
}
})
-- }}}
-- {{{ Key bindings
-- @DOC_GLOBAL_KEYBINDINGS@
globalkeys = {
-- General Awesome keys
awful.keyboard.append_global_keybindings({
awful.key({ modkey, }, "s", hotkeys_popup.show_help,
{description="show help", group="awesome"}),
awful.key({ modkey, }, "w", function () mymainmenu:show() end,
{description = "show main menu", group = "awesome"}),
awful.key({ modkey, "Control" }, "r", awesome.restart,
{description = "reload awesome", group = "awesome"}),
awful.key({ modkey, "Shift" }, "q", awesome.quit,
{description = "quit awesome", group = "awesome"}),
awful.key({ modkey }, "x",
function ()
awful.prompt.run {
prompt = "Run Lua code: ",
textbox = awful.screen.focused().mypromptbox.widget,
exe_callback = awful.util.eval,
history_path = awful.util.get_cache_dir() .. "/history_eval"
}
end,
{description = "lua execute prompt", group = "awesome"}),
awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end,
{description = "open a terminal", group = "launcher"}),
awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end,
{description = "run prompt", group = "launcher"}),
awful.key({ modkey }, "p", function() menubar.show() end,
{description = "show the menubar", group = "launcher"}),
})
-- Tags related keybindings
awful.keyboard.append_global_keybindings({
awful.key({ modkey, }, "Left", awful.tag.viewprev,
{description = "view previous", group = "tag"}),
awful.key({ modkey, }, "Right", awful.tag.viewnext,
{description = "view next", group = "tag"}),
awful.key({ modkey, }, "Escape", awful.tag.history.restore,
{description = "go back", group = "tag"}),
})
-- Focus related keybindings
awful.keyboard.append_global_keybindings({
awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
@ -250,20 +281,6 @@ globalkeys = {
end,
{description = "focus previous by index", group = "client"}
),
awful.key({ modkey, }, "w", function () mymainmenu:show() end,
{description = "show main menu", group = "awesome"}),
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end,
{description = "swap with next client by index", group = "client"}),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end,
{description = "swap with previous client by index", group = "client"}),
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
{description = "focus the next screen", group = "screen"}),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
{description = "focus the previous screen", group = "screen"}),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto,
{description = "jump to urgent client", group = "client"}),
awful.key({ modkey, }, "Tab",
function ()
awful.client.focus.history.previous()
@ -272,15 +289,31 @@ globalkeys = {
end
end,
{description = "go back", group = "client"}),
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
{description = "focus the next screen", group = "screen"}),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
{description = "focus the previous screen", group = "screen"}),
awful.key({ modkey, "Control" }, "n",
function ()
local c = awful.client.restore()
-- Focus restored client
if c then
c:emit_signal(
"request::activate", "key.unminimize", {raise = true}
)
end
end,
{description = "restore minimized", group = "client"}),
})
-- Standard program
awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end,
{description = "open a terminal", group = "launcher"}),
awful.key({ modkey, "Control" }, "r", awesome.restart,
{description = "reload awesome", group = "awesome"}),
awful.key({ modkey, "Shift" }, "q", awesome.quit,
{description = "quit awesome", group = "awesome"}),
-- Layout related keybindings
awful.keyboard.append_global_keybindings({
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end,
{description = "swap with next client by index", group = "client"}),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end,
{description = "swap with previous client by index", group = "client"}),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto,
{description = "jump to urgent client", group = "client"}),
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end,
{description = "increase master width factor", group = "layout"}),
awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end,
@ -297,37 +330,7 @@ globalkeys = {
{description = "select next", group = "layout"}),
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(-1) end,
{description = "select previous", group = "layout"}),
awful.key({ modkey, "Control" }, "n",
function ()
local c = awful.client.restore()
-- Focus restored client
if c then
c:emit_signal(
"request::activate", "key.unminimize", {raise = true}
)
end
end,
{description = "restore minimized", group = "client"}),
-- Prompt
awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end,
{description = "run prompt", group = "launcher"}),
awful.key({ modkey }, "x",
function ()
awful.prompt.run {
prompt = "Run Lua code: ",
textbox = awful.screen.focused().mypromptbox.widget,
exe_callback = awful.util.eval,
history_path = awful.util.get_cache_dir() .. "/history_eval"
}
end,
{description = "lua execute prompt", group = "awesome"}),
-- Menubar
awful.key({ modkey }, "p", function() menubar.show() end,
{description = "show the menubar", group = "launcher"}),
}
})
-- @DOC_CLIENT_KEYBINDINGS@
clientkeys = {
@ -380,7 +383,8 @@ clientkeys = {
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do
-- View tag only.
table.insert(globalkeys, awful.key({ modkey }, "#" .. i + 9,
awful.keyboard.append_global_keybinding(awful.key(
{ modkey }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
@ -388,11 +392,12 @@ for i = 1, 9 do
tag:view_only()
end
end,
{description = "view tag #"..i, group = "tag"})
)
{description = "view tag #"..i, group = "tag"}
))
-- Toggle tag display.
table.insert(globalkeys, awful.key({ modkey, "Control" }, "#" .. i + 9,
awful.keyboard.append_global_keybinding(awful.key(
{ modkey, "Control" }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
@ -400,11 +405,12 @@ for i = 1, 9 do
awful.tag.viewtoggle(tag)
end
end,
{description = "toggle tag #" .. i, group = "tag"})
)
{description = "toggle tag #" .. i, group = "tag"}
))
-- Move client to tag.
table.insert(globalkeys, awful.key({ modkey, "Shift" }, "#" .. i + 9,
awful.keyboard.append_global_keybinding(awful.key(
{ modkey, "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = client.focus.screen.tags[i]
@ -413,11 +419,12 @@ for i = 1, 9 do
end
end
end,
{description = "move focused client to tag #"..i, group = "tag"})
)
{description = "move focused client to tag #"..i, group = "tag"}
))
-- Toggle tag on focused client.
table.insert(globalkeys, awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
awful.keyboard.append_global_keybinding(awful.key(
{ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
if client.focus then
local tag = client.focus.screen.tags[i]
@ -426,8 +433,8 @@ for i = 1, 9 do
end
end
end,
{description = "toggle focused client on tag #" .. i, group = "tag"})
)
{description = "toggle focused client on tag #" .. i, group = "tag"}
))
end
-- @DOC_CLIENT_BUTTONS@
@ -445,8 +452,6 @@ clientbuttons = {
end),
}
-- Set keys
root.keys = globalkeys
-- }}}
-- {{{ Rules