2016-04-04 12:54:30 +00:00
|
|
|
-- key bindings
|
|
|
|
local awful = require("awful")
|
2024-02-06 16:25:23 +00:00
|
|
|
local naughty = require("naughty")
|
|
|
|
local conf = require("localconf")
|
2016-04-04 12:54:30 +00:00
|
|
|
local modkey = conf.modkey or "Mod4"
|
2017-09-13 13:52:49 +00:00
|
|
|
local mb = require("modalbind")
|
2018-11-05 12:08:33 +00:00
|
|
|
mb.init()
|
2016-04-04 12:54:30 +00:00
|
|
|
|
|
|
|
local globalkeys = {}
|
2020-07-22 12:32:46 +00:00
|
|
|
local globalkeyfuncs = {}
|
2016-04-04 12:54:30 +00:00
|
|
|
|
2024-02-06 16:25:23 +00:00
|
|
|
local app_folders = {
|
2016-04-04 12:54:30 +00:00
|
|
|
"/usr/share/applications",
|
|
|
|
"/usr/local/share/applications",
|
2018-05-12 16:44:07 +00:00
|
|
|
(os.getenv("XDG_DATA_HOME") or os.getenv("HOME") .. "/.local/share") .. "/applications",
|
2025-02-02 16:05:47 +00:00
|
|
|
os.getenv("HOME") .. "/Desktop",
|
2016-04-04 12:54:30 +00:00
|
|
|
}
|
|
|
|
local menubar = require("menubar")
|
|
|
|
|
|
|
|
menubar.utils.terminal = conf.cmd.terminal -- Set the terminal for applications that require it
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
local binder = { modal = mb }
|
2016-04-04 12:54:30 +00:00
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
local function spawnf(cmd)
|
|
|
|
return function()
|
|
|
|
awful.spawn(cmd)
|
|
|
|
end
|
|
|
|
end
|
2016-04-04 12:54:30 +00:00
|
|
|
binder.spawn = spawnf
|
|
|
|
|
|
|
|
conf.cmd.run = conf.cmd.run or spawnf("dmenu_run")
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
local function use_layout(layout)
|
|
|
|
return function()
|
|
|
|
awful.layout.set(layout)
|
|
|
|
end
|
|
|
|
end
|
2024-02-06 16:25:23 +00:00
|
|
|
local layoutmap = {
|
2025-02-02 16:05:47 +00:00
|
|
|
{ "f", use_layout(awful.layout.suit.fair), "Fair" },
|
|
|
|
{ "h", use_layout(awful.layout.suit.fair.horizontal), "Fair Horizontal" },
|
|
|
|
{ "t", use_layout(awful.layout.suit.tile), "Tile" },
|
|
|
|
{ "b", use_layout(awful.layout.suit.tile.bottom), "Tile Bottom" },
|
|
|
|
{ "m", use_layout(awful.layout.suit.max), "Maximized" },
|
|
|
|
{ "F", use_layout(awful.layout.suit.max.fullscreen), "Fullscreen" },
|
|
|
|
{ "space", use_layout(awful.layout.suit.floating), "Float" },
|
2016-04-04 12:54:30 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 16:25:23 +00:00
|
|
|
local layoutsettings = {
|
2025-02-02 16:05:47 +00:00
|
|
|
{
|
|
|
|
"h",
|
|
|
|
function()
|
|
|
|
awful.tag.incmwfact(-0.05)
|
|
|
|
end,
|
|
|
|
"Master smaller",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"l",
|
|
|
|
function()
|
|
|
|
awful.tag.incmwfact(0.05)
|
|
|
|
end,
|
|
|
|
"Master bigger",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"H",
|
|
|
|
function()
|
|
|
|
awful.tag.incnmaster(1)
|
|
|
|
end,
|
|
|
|
"More masters",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"L",
|
|
|
|
function()
|
|
|
|
awful.tag.incnmaster(-1)
|
|
|
|
end,
|
|
|
|
"Less masters",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"c",
|
|
|
|
function()
|
|
|
|
awful.tag.incncol(1)
|
|
|
|
end,
|
|
|
|
"More columns",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"C",
|
|
|
|
function()
|
|
|
|
awful.tag.incncol(-1)
|
|
|
|
end,
|
|
|
|
"Less columns",
|
|
|
|
},
|
2016-04-04 12:54:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 13:08:14 +00:00
|
|
|
local opposite_dirs = {
|
2025-02-02 16:05:47 +00:00
|
|
|
left = "right",
|
2016-07-25 13:08:14 +00:00
|
|
|
right = "left",
|
2025-02-02 16:05:47 +00:00
|
|
|
up = "down",
|
|
|
|
down = "up",
|
2016-07-25 13:08:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-06 16:25:23 +00:00
|
|
|
local function screen_in_wrapdir(dir, _screen)
|
2025-02-02 16:05:47 +00:00
|
|
|
local sel = _screen or mouse.screen
|
|
|
|
if sel then
|
|
|
|
local geomtbl = {}
|
|
|
|
for s = 1, screen.count() do
|
|
|
|
geomtbl[s] = screen[s].geometry
|
|
|
|
end
|
|
|
|
local target = awful.util.get_rectangle_in_direction(dir, geomtbl, screen[sel].geometry)
|
|
|
|
if not target then
|
|
|
|
local new_target = sel
|
|
|
|
while new_target do
|
|
|
|
target = new_target
|
|
|
|
new_target = awful.util.get_rectangle_in_direction(opposite_dirs[dir], geomtbl, screen[target].geometry)
|
|
|
|
end
|
2016-07-25 13:08:14 +00:00
|
|
|
end
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
return target
|
|
|
|
end
|
2016-07-25 13:08:14 +00:00
|
|
|
end
|
|
|
|
|
2024-02-06 16:25:23 +00:00
|
|
|
local function screen_focus_wrapdir(dir)
|
|
|
|
return function()
|
|
|
|
local target = screen_in_wrapdir(dir)
|
|
|
|
awful.screen.focus(target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function screen_move_client_wrapdir(dir)
|
|
|
|
return function(c)
|
|
|
|
local target = screen_in_wrapdir(dir)
|
|
|
|
awful.client.movetoscreen(c, target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-04 12:54:30 +00:00
|
|
|
function binder.add_bindings(keys)
|
2025-02-02 16:05:47 +00:00
|
|
|
globalkeys = awful.util.table.join(globalkeys, keys)
|
2016-04-04 12:54:30 +00:00
|
|
|
return binder
|
|
|
|
end
|
|
|
|
|
2020-07-22 12:32:46 +00:00
|
|
|
function binder.add_reloadable(key_func)
|
2025-02-02 16:05:47 +00:00
|
|
|
table.insert(globalkeyfuncs, key_func)
|
|
|
|
return binder
|
2016-04-04 12:54:30 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 13:07:53 +00:00
|
|
|
function binder.clear()
|
|
|
|
globalkeys = {}
|
2020-07-22 12:32:46 +00:00
|
|
|
globalkeyfuncs = {}
|
2016-07-25 13:07:53 +00:00
|
|
|
end
|
|
|
|
|
2016-04-04 12:54:30 +00:00
|
|
|
function binder.apply()
|
2025-02-02 16:05:47 +00:00
|
|
|
naughty.notify({ text = "Reloading key bindings" })
|
|
|
|
local allkeys = awful.util.table.clone(globalkeys)
|
|
|
|
for _, v in pairs(globalkeyfuncs) do
|
|
|
|
local loadedkeys = v()
|
|
|
|
allkeys = awful.util.table.join(allkeys, loadedkeys)
|
|
|
|
end
|
|
|
|
root.keys(allkeys)
|
2016-04-04 12:54:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function client_opacity_set(c, default, max, step)
|
|
|
|
if c.opacity < 0 or c.opacity > 1 then
|
|
|
|
c.opacity = default
|
|
|
|
end
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
if c.opacity * step < (max - step) * step then
|
2016-04-04 12:54:30 +00:00
|
|
|
c.opacity = c.opacity + step
|
|
|
|
else
|
|
|
|
c.opacity = max
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local clientkeys = awful.util.table.join(
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey, "Shift" }, "f", function(c)
|
|
|
|
c.fullscreen = not c.fullscreen
|
|
|
|
end),
|
|
|
|
awful.key({ modkey, "Shift" }, "c", function(c)
|
|
|
|
c:kill()
|
|
|
|
end),
|
|
|
|
awful.key({ modkey }, "f", awful.client.floating.toggle),
|
|
|
|
awful.key({ modkey, "Control" }, "Return", function(c)
|
|
|
|
c:swap(awful.client.getmaster())
|
|
|
|
end),
|
|
|
|
awful.key({ modkey }, "o", awful.client.movetoscreen),
|
|
|
|
awful.key({ modkey, "Shift" }, "h", screen_move_client_wrapdir("left")),
|
|
|
|
awful.key({ modkey, "Shift" }, "l", screen_move_client_wrapdir("right")),
|
|
|
|
awful.key({ modkey, "Control" }, "o", function(c)
|
|
|
|
c.ontop = not c.ontop
|
|
|
|
end),
|
|
|
|
awful.key({ modkey, "Shift" }, "a", function(c)
|
|
|
|
c.sticky = not c.sticky
|
|
|
|
end),
|
|
|
|
awful.key({ modkey }, "Up", function(c)
|
|
|
|
client_opacity_set(c, 1, 1, 0.1)
|
|
|
|
end),
|
|
|
|
awful.key({ modkey }, "Down", function(c)
|
|
|
|
client_opacity_set(c, 1, 0, -0.1)
|
|
|
|
end),
|
|
|
|
awful.key({}, "XF86Calculater", awful.client.movetoscreen),
|
|
|
|
awful.key({ modkey }, "i", function(c)
|
|
|
|
require("naughty").notify({
|
|
|
|
text = string.format(
|
|
|
|
"name: '%s'\nclass: '%s'\ninstance: '%s'\ntype: '%s'\npid: %d",
|
|
|
|
c["name"],
|
|
|
|
c["class"],
|
|
|
|
c["instance"],
|
|
|
|
c["type"],
|
|
|
|
c["pid"]
|
|
|
|
),
|
|
|
|
})
|
|
|
|
end)
|
2016-04-04 12:54:30 +00:00
|
|
|
)
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
root.buttons(awful.util.table.join(awful.button({}, 4, awful.tag.viewnext), awful.button({}, 5, awful.tag.viewprev)))
|
2017-10-31 20:20:23 +00:00
|
|
|
|
2016-04-04 12:54:30 +00:00
|
|
|
local clientbuttons = awful.util.table.join(
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.button({}, 1, function(c)
|
|
|
|
if c.name ~= "Onboard" then
|
|
|
|
client.focus = c
|
|
|
|
c:raise()
|
|
|
|
end
|
|
|
|
end),
|
|
|
|
awful.button({ modkey }, 1, awful.mouse.client.move),
|
|
|
|
awful.button({ modkey }, 3, awful.mouse.client.resize)
|
|
|
|
)
|
2016-04-04 12:54:30 +00:00
|
|
|
|
|
|
|
binder.client = {}
|
|
|
|
|
|
|
|
function binder.client.buttons()
|
|
|
|
return clientbuttons
|
|
|
|
end
|
|
|
|
|
|
|
|
function binder.client.keys()
|
|
|
|
return clientkeys
|
|
|
|
end
|
|
|
|
|
|
|
|
function binder.client.add_buttons(buttons)
|
2025-02-02 16:05:47 +00:00
|
|
|
clientbuttons = awful.util.table.join(clientbuttons, buttons)
|
2016-04-04 12:54:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function binder.client.add_bindings(keys)
|
2025-02-02 16:05:47 +00:00
|
|
|
clientkeys = awful.util.table.join(clientkeys, keys)
|
2016-04-04 12:54:30 +00:00
|
|
|
end
|
|
|
|
|
2020-07-22 12:32:46 +00:00
|
|
|
local default_bindings = awful.util.table.join(
|
|
|
|
awful.key({ modkey, "Control" }, "r", awesome.restart),
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey, "Shift" }, "q", awesome.quit),
|
|
|
|
awful.key({ modkey }, "Return", spawnf(conf.cmd.terminal)),
|
|
|
|
awful.key({ modkey, "Shift" }, "Return", spawnf("kitty-session")),
|
2020-07-22 12:32:46 +00:00
|
|
|
|
|
|
|
--{{{ Layout manipulation and client position
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey }, "j", function()
|
|
|
|
awful.client.focus.byidx(1)
|
|
|
|
if client.focus then
|
|
|
|
client.focus:raise()
|
|
|
|
end
|
2020-07-22 12:32:46 +00:00
|
|
|
end),
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey }, "k", function()
|
2020-07-22 12:32:46 +00:00
|
|
|
awful.client.focus.byidx(-1)
|
2025-02-02 16:05:47 +00:00
|
|
|
if client.focus then
|
|
|
|
client.focus:raise()
|
|
|
|
end
|
2020-07-22 12:32:46 +00:00
|
|
|
end),
|
|
|
|
|
|
|
|
-- Layout manipulation
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey }, "Tab", function()
|
2020-07-22 12:32:46 +00:00
|
|
|
awful.client.focus.history.previous()
|
|
|
|
if client.focus then
|
|
|
|
client.focus:raise()
|
|
|
|
end
|
|
|
|
end),
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ "Mod1" }, "Tab", function()
|
2020-07-22 12:32:46 +00:00
|
|
|
awful.client.focus.history.previous()
|
|
|
|
if client.focus then
|
|
|
|
client.focus:raise()
|
|
|
|
end
|
|
|
|
end),
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey, "Shift" }, "j", function()
|
|
|
|
awful.client.swap.byidx(1)
|
|
|
|
end),
|
|
|
|
awful.key({ modkey, "Shift" }, "k", function()
|
|
|
|
awful.client.swap.byidx(-1)
|
2020-07-22 12:32:46 +00:00
|
|
|
end),
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey }, "h", function()
|
|
|
|
awful.screen.focus_relative(1)
|
|
|
|
end),
|
|
|
|
awful.key({ modkey }, "l", function()
|
|
|
|
awful.screen.focus_relative(-1)
|
2020-07-22 12:32:46 +00:00
|
|
|
end),
|
|
|
|
--}}}
|
|
|
|
|
|
|
|
--{{{ Modal mappings
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
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 })
|
|
|
|
),
|
2020-07-22 12:32:46 +00:00
|
|
|
--}}}
|
|
|
|
|
|
|
|
--{{{ Prompt
|
|
|
|
|
2025-02-02 16:05:47 +00:00
|
|
|
awful.key({ modkey }, "r", conf.cmd.drun),
|
|
|
|
awful.key({ modkey, "Shift" }, "r", conf.cmd.run),
|
2020-07-22 12:32:46 +00:00
|
|
|
|
|
|
|
--}}}
|
|
|
|
|
|
|
|
-- reloading
|
|
|
|
awful.key({ modkey, "Control" }, "b", binder.apply)
|
|
|
|
)
|
|
|
|
function binder.add_default_bindings()
|
|
|
|
return binder.add_bindings(default_bindings)
|
|
|
|
end
|
|
|
|
|
2016-04-04 12:54:30 +00:00
|
|
|
return binder
|
|
|
|
-- vim: set fenc=utf-8 tw=80 foldmethod=marker :
|