Refactor keybinding code
This commit is contained in:
parent
1dfd3fd43b
commit
97b844e6fd
81
bindings.lua
81
bindings.lua
|
@ -7,75 +7,69 @@ local scratch = require("scratch")
|
||||||
local modkey = conf.modkey or "Mod4"
|
local modkey = conf.modkey or "Mod4"
|
||||||
local mb = require("modalbind")
|
local mb = require("modalbind")
|
||||||
|
|
||||||
local bindings = {mb = mb}
|
local bindings = {modalbind = mb}
|
||||||
|
|
||||||
-- {{{ Mouse bindings
|
-- {{{ Mouse bindings
|
||||||
root.buttons(awful.util.table.join(
|
root.buttons(awful.util.table.join(
|
||||||
awful.button({ }, 4, awful.tag.viewnext),
|
awful.button({ }, 4, awful.tag.viewnext),
|
||||||
awful.button({ }, 5, awful.tag.viewprev)
|
awful.button({ }, 5, awful.tag.viewprev)
|
||||||
))
|
))
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
local function spawnf(cmd) return function() awful.util.spawn(cmd) end end
|
local function spawnf(cmd) return function() awful.util.spawn(cmd) end end
|
||||||
|
bindings.spawnf = spawnf
|
||||||
|
|
||||||
conf.cmd.run = conf.cmd.run or spawnf("dmenu_run")
|
conf.cmd.run = conf.cmd.run or spawnf("dmenu_run")
|
||||||
|
|
||||||
mpdmap = {
|
mpdmap = {
|
||||||
name = "MPD",
|
m = { func = mpd.ctrl.toggle, desc = "Toggle" },
|
||||||
m = mpd.ctrl.toggle,
|
n = { func = mpd.ctrl.next, desc = "Next" },
|
||||||
n = mpd.ctrl.next,
|
N = { func = mpd.ctrl.prev, desc = "Prev" },
|
||||||
N = mpd.ctrl.prev,
|
s = { func = spawnf("mpd"), desc = "start MPD" },
|
||||||
s = spawnf("mpd"),
|
S = { func = spawnf("mpd --kill"), desc = "kill MPD" },
|
||||||
S = spawnf("mpd --kill"),
|
g = { func = spawnf(conf.cmd.mpd_client), desc = "Gmpc" }
|
||||||
g = spawnf(conf.cmd.mpd_client)
|
|
||||||
}
|
}
|
||||||
mpdpromts = {
|
mpdpromts = {
|
||||||
name = "MPD PROMPTS",
|
a = { func = mpd.prompt.artist, desc = "artist" },
|
||||||
a = mpd.prompt.artist,
|
b = { func = mpd.prompt.album, desc = "album" },
|
||||||
b = mpd.prompt.album,
|
t = { func = mpd.prompt.title, desc = "title" },
|
||||||
t = mpd.prompt.title,
|
r = { func = mpd.prompt.toggle_replace_on_search, desc = "toggle replacing" }
|
||||||
r = mpd.prompt.toggle_replace_on_search
|
|
||||||
}
|
}
|
||||||
|
|
||||||
progmap = {
|
progmap = {
|
||||||
name = "PROGRAMS",
|
f = { func = spawnf(conf.cmd.browser), desc = "Browser" },
|
||||||
f = spawnf(conf.cmd.browser),
|
i = { func = spawnf(conf.cmd.im_client), desc = "IM Client" },
|
||||||
i = spawnf(conf.cmd.im_client),
|
I = { func = spawnf(conf.cmd.irc_client), desc = "IRC" },
|
||||||
I = spawnf(conf.cmd.irc_client),
|
m = { func = spawnf(conf.cmd.mail_client), desc = "Mail" }
|
||||||
m = spawnf(conf.cmd.mail_client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
docmap = {
|
docmap = {
|
||||||
name = "DOCUMENTS",
|
u = { func = spawnf("docopen ~/uni pdf"), desc = "Uni-Dokumente" },
|
||||||
u = spawnf("docopen ~/uni pdf"),
|
b = { func = spawnf("docopen ~/books pdf epub mobi txt lit html htm"), desc = "Bücher" }
|
||||||
b = spawnf("docopen ~/books pdf epub mobi txt lit html htm"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapters = { u = "wwan", w = "wlan", b = "bluetooth" }
|
adapters = { u = "wwan", w = "wlan", b = "bluetooth" }
|
||||||
function rfkill(cmd)
|
local function rfkill(cmd)
|
||||||
map={ name = string.upper(cmd) }
|
map = {}
|
||||||
for key, adapter in pairs(adapters) do
|
for key, adapter in pairs(adapters) do
|
||||||
map[key] = spawnf("sudo rfkill "..cmd.." "..adapter)
|
map[key] = { func = spawnf("sudo rfkill "..cmd.." "..adapter), desc = adapter }
|
||||||
end
|
end
|
||||||
return map
|
return map
|
||||||
end
|
end
|
||||||
|
|
||||||
connectmap = {
|
connectmap = {
|
||||||
name = "CONNECT",
|
u = { func = spawnf("umts"), desc = "umts" },
|
||||||
u = spawnf("umts"),
|
w = { func = spawnf("wlanacpi"), desc = "wlan" }
|
||||||
w = spawnf("wlanacpi")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wirelessmap = {
|
wirelessmap = {
|
||||||
name = "WIRELESS",
|
b = { func = mb.grabf(rfkill("block"),"Block"), desc = "block" },
|
||||||
b = mb.grabf(rfkill("block")),
|
u = { func = mb.grabf(rfkill("unblock"),"Unblock"), desc = "unblock" },
|
||||||
u = mb.grabf(rfkill("unblock")),
|
c = { func = mb.grabf(connectmap, "Connect"), desc = "connect" }
|
||||||
c = mb.grabf(connectmap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindings.extend_and_register_key_table(globalkeys)
|
function bindings.extend_key_table(globalkeys)
|
||||||
local totalkeys = globalkeys or {}
|
return awful.util.table.join(globalkeys or {},
|
||||||
totalkeys = awful.util.table.join(totalkeys,
|
|
||||||
awful.key({ }, "Menu", spawnf('wmselect')),
|
awful.key({ }, "Menu", spawnf('wmselect')),
|
||||||
|
|
||||||
awful.key({ modkey, "Control" }, "r", awesome.restart),
|
awful.key({ modkey, "Control" }, "r", awesome.restart),
|
||||||
|
@ -84,11 +78,11 @@ function bindings.extend_and_register_key_table(globalkeys)
|
||||||
|
|
||||||
--{{{ Modal mappings
|
--{{{ Modal mappings
|
||||||
|
|
||||||
awful.key({ modkey }, "m", mb.grabf(mpdmap, true)),
|
awful.key({ modkey }, "m", mb.grabf(mpdmap, "MPD", true)),
|
||||||
awful.key({ modkey, "Shift" }, "m", mb.grabf(mpdpromts)),
|
awful.key({ modkey, "Shift" }, "m", mb.grabf(mpdpromts, "MPD - Search for")),
|
||||||
awful.key({ modkey }, "c", mb.grabf(progmap)),
|
awful.key({ modkey }, "c", mb.grabf(progmap, "Commands")),
|
||||||
awful.key({ modkey }, "w", mb.grabf(wirelessmap)),
|
awful.key({ modkey }, "w", mb.grabf(wirelessmap, "Wifi")),
|
||||||
awful.key({ modkey }, "d", mb.grabf(docmap)),
|
awful.key({ modkey }, "d", mb.grabf(docmap, "Documents")),
|
||||||
--}}}
|
--}}}
|
||||||
|
|
||||||
--{{{ Audio control
|
--{{{ Audio control
|
||||||
|
@ -130,13 +124,10 @@ function bindings.extend_and_register_key_table(globalkeys)
|
||||||
)
|
)
|
||||||
|
|
||||||
--}}}
|
--}}}
|
||||||
|
|
||||||
-- Set keys
|
|
||||||
root.keys(totalkeys)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function client_opacity_set(c, default, max, step)
|
local function client_opacity_set(c, default, max, step)
|
||||||
if c.opacity < 0 or c.opacity > 1 then
|
if c.opacity < 0 or c.opacity > 1 then
|
||||||
c.opacity = default
|
c.opacity = default
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,6 @@ function layouts.extend_key_table(globalkeys)
|
||||||
end),
|
end),
|
||||||
|
|
||||||
-- Layout manipulation
|
-- Layout manipulation
|
||||||
awful.key({ modkey }, "u", awful.client.urgent.jumpto),
|
|
||||||
awful.key({ modkey }, "Tab", function ()
|
awful.key({ modkey }, "Tab", function ()
|
||||||
awful.client.focus.history.previous()
|
awful.client.focus.history.previous()
|
||||||
if client.focus then
|
if client.focus then
|
||||||
|
@ -78,10 +77,7 @@ function layouts.extend_key_table(globalkeys)
|
||||||
end),
|
end),
|
||||||
awful.key({ modkey, "Control" }, "k", function ()
|
awful.key({ modkey, "Control" }, "k", function ()
|
||||||
awful.screen.focus_relative(-1)
|
awful.screen.focus_relative(-1)
|
||||||
end),
|
end)
|
||||||
awful.key({ modkey }, "Left", awful.tag.viewprev ),
|
|
||||||
awful.key({ modkey }, "Right", awful.tag.viewnext ),
|
|
||||||
awful.key({ modkey }, "Escape", awful.tag.history.restore)
|
|
||||||
);
|
);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ local function set_default(s)
|
||||||
modewibox[s].x = settings.x_offset < 0 and
|
modewibox[s].x = settings.x_offset < 0 and
|
||||||
screen[s].geometry.x - width + settings.x_offset or
|
screen[s].geometry.x - width + settings.x_offset or
|
||||||
settings.x_offset
|
settings.x_offset
|
||||||
modewibox[s].y = screen[s].geometry.height - settings.height
|
modewibox[s].y = screen[s].geometry.height - modewibox[s].height
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ensure_init()
|
local function ensure_init()
|
||||||
|
@ -115,7 +115,7 @@ local function ensure_init()
|
||||||
inited = true
|
inited = true
|
||||||
for s = 1, screen.count() do
|
for s = 1, screen.count() do
|
||||||
modewidget[s] = wibox.widget.textbox()
|
modewidget[s] = wibox.widget.textbox()
|
||||||
modewidget[s]:set_align("center")
|
modewidget[s]:set_align("left")
|
||||||
|
|
||||||
modewibox[s] = wibox({
|
modewibox[s] = wibox({
|
||||||
fg = beautiful.fg_normal,
|
fg = beautiful.fg_normal,
|
||||||
|
@ -141,16 +141,19 @@ local function ensure_init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function show_box(s, map)
|
local function show_box(s, map, name)
|
||||||
ensure_init()
|
ensure_init()
|
||||||
modewibox.screen = s
|
modewibox.screen = s
|
||||||
local label = " -- " .. map.name .. " -- "
|
local label = "<b>" .. name .. "</b>"
|
||||||
if settings.show_options then
|
if settings.show_options then
|
||||||
for key in pairs(map) do
|
for key, mapping in pairs(map) do
|
||||||
if key ~= "name" then label = label .. " " .. key end
|
label = label .. "\n<b>" .. key .. "</b>"
|
||||||
|
if type(mapping) == "table" then
|
||||||
|
label = label .. "\t" .. (mapping.desc or "???")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
modewidget[s]:set_text(label)
|
end
|
||||||
|
modewidget[s]:set_markup(label)
|
||||||
modewibox[s].visible = true
|
modewibox[s].visible = true
|
||||||
set_default(s)
|
set_default(s)
|
||||||
end
|
end
|
||||||
|
@ -160,9 +163,9 @@ local function hide_box()
|
||||||
if s ~= -1 then modewibox[s].visible = false end
|
if s ~= -1 then modewibox[s].visible = false end
|
||||||
end
|
end
|
||||||
|
|
||||||
function grab(keymap, stay_in_mode)
|
function grab(keymap, name, stay_in_mode)
|
||||||
if keymap.name then
|
if name then
|
||||||
show_box(mouse.screen, keymap)
|
show_box(mouse.screen, keymap, name)
|
||||||
nesting = nesting + 1
|
nesting = nesting + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -178,7 +181,11 @@ function grab(keymap, stay_in_mode)
|
||||||
|
|
||||||
if keymap[key] then
|
if keymap[key] then
|
||||||
keygrabber.stop()
|
keygrabber.stop()
|
||||||
|
if type(keymap[key]) == "table" then
|
||||||
|
keymap[key].func()
|
||||||
|
else
|
||||||
keymap[key]()
|
keymap[key]()
|
||||||
|
end
|
||||||
if stay_in_mode then
|
if stay_in_mode then
|
||||||
grab(keymap, true)
|
grab(keymap, true)
|
||||||
else
|
else
|
||||||
|
@ -193,8 +200,8 @@ function grab(keymap, stay_in_mode)
|
||||||
end
|
end
|
||||||
modalbind.grab = grab
|
modalbind.grab = grab
|
||||||
|
|
||||||
function grabf(keymap, stay_in_mode)
|
function grabf(keymap, name, stay_in_mode)
|
||||||
return function() grab(keymap, stay_in_mode) end
|
return function() grab(keymap, name, stay_in_mode) end
|
||||||
end
|
end
|
||||||
modalbind.grabf = grabf
|
modalbind.grabf = grabf
|
||||||
|
|
||||||
|
|
6
rc.lua
6
rc.lua
|
@ -64,8 +64,10 @@ globalkeys = layouts.extend_key_table(globalkeys);
|
||||||
globalkeys = tags.extend_key_table(globalkeys);
|
globalkeys = tags.extend_key_table(globalkeys);
|
||||||
|
|
||||||
bindings = require("bindings")
|
bindings = require("bindings")
|
||||||
bindings.extend_and_register_key_table(globalkeys)
|
bindings.modalbind.set_x_offset(18)
|
||||||
bindings.mb.set_x_offset(18)
|
globalkeys = bindings.extend_key_table(globalkeys)
|
||||||
|
|
||||||
|
root.keys(globalkeys)
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
-- {{{ rules
|
-- {{{ rules
|
||||||
|
|
26
tags.lua
26
tags.lua
|
@ -1,4 +1,4 @@
|
||||||
-- tags and layouts
|
-- tags
|
||||||
local awful = awful
|
local awful = awful
|
||||||
local conf = conf
|
local conf = conf
|
||||||
local modkey = conf.modkey or "Mod4"
|
local modkey = conf.modkey or "Mod4"
|
||||||
|
@ -6,7 +6,7 @@ local modkey = conf.modkey or "Mod4"
|
||||||
local tags={ mt={} }
|
local tags={ mt={} }
|
||||||
local layouts = layouts
|
local layouts = layouts
|
||||||
|
|
||||||
local function funcViewOnly(i)
|
local function getfunc_viewonly(i)
|
||||||
return function ()
|
return function ()
|
||||||
local screen = mouse.screen
|
local screen = mouse.screen
|
||||||
if tags[screen][i] then
|
if tags[screen][i] then
|
||||||
|
@ -15,7 +15,7 @@ local function funcViewOnly(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function funcViewToggle(i)
|
local function getfunc_viewtoggle(i)
|
||||||
return function ()
|
return function ()
|
||||||
local screen = mouse.screen
|
local screen = mouse.screen
|
||||||
if tags[screen][i] then
|
if tags[screen][i] then
|
||||||
|
@ -24,7 +24,7 @@ local function funcViewToggle(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function funcMoveTo(i)
|
local function getfunc_moveto(i)
|
||||||
return function ()
|
return function ()
|
||||||
if client.focus and tags[client.focus.screen][i] then
|
if client.focus and tags[client.focus.screen][i] then
|
||||||
awful.client.movetotag(tags[client.focus.screen][i])
|
awful.client.movetotag(tags[client.focus.screen][i])
|
||||||
|
@ -32,7 +32,7 @@ local function funcMoveTo(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function funcToggle(i)
|
local function getfunc_clienttoggle(i)
|
||||||
return function ()
|
return function ()
|
||||||
if client.focus and tags[client.focus.screen][i] then
|
if client.focus and tags[client.focus.screen][i] then
|
||||||
awful.client.toggletag(tags[client.focus.screen][i])
|
awful.client.toggletag(tags[client.focus.screen][i])
|
||||||
|
@ -104,12 +104,20 @@ function tags.extend_key_table(globalkeys)
|
||||||
k = "F" .. i - 10 -- F keys
|
k = "F" .. i - 10 -- F keys
|
||||||
end
|
end
|
||||||
tagkeys = awful.util.table.join(tagkeys,
|
tagkeys = awful.util.table.join(tagkeys,
|
||||||
awful.key( { modkey }, k, funcViewOnly(i)),
|
awful.key( { modkey }, k, getfunc_viewonly(i)),
|
||||||
awful.key( { modkey, "Control" }, k, funcViewToggle(i)),
|
awful.key( { modkey, "Control" }, k, getfunc_viewtoggle(i)),
|
||||||
awful.key( { modkey, "Shift" }, k, funcMoveTo(i)),
|
awful.key( { modkey, "Shift" }, k, getfunc_moveto(i)),
|
||||||
awful.key( { modkey, "Control", "Shift" }, k, funcToggle(i))
|
awful.key( { modkey, "Control", "Shift" }, k, getfunc_clienttoggle(i))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- keys for all tags
|
||||||
|
tagkeys = awful.util.table.join(tagkeys,
|
||||||
|
awful.key({ modkey }, "u", awful.client.urgent.jumpto),
|
||||||
|
awful.key({ modkey }, "Left", awful.tag.viewprev ),
|
||||||
|
awful.key({ modkey }, "Right", awful.tag.viewnext ),
|
||||||
|
awful.key({ modkey }, "Escape", awful.tag.history.restore)
|
||||||
|
)
|
||||||
return tagkeys;
|
return tagkeys;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue