This commit is contained in:
BZ 2021-03-30 14:51:41 +02:00
parent 6171918286
commit 9deaf664eb
1 changed files with 27 additions and 27 deletions

View File

@ -4,7 +4,7 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack
local module = {} local module = {}
local function new(args) local function new(args)
local awesome, client, root, keygrabber = awesome, client, root, keygrabber -- luacheck: globals client root keygrabber local awesome, client, root, keygrabber = awesome, client, root, keygrabber -- luacheck: awesome globals client root keygrabber
local keys = args or {up = {"k", "Up"}, down = {"j", "Down"}, left = {"h", "Left"}, right = {"l", "Right"}} local keys = args or {up = {"k", "Up"}, down = {"j", "Down"}, left = {"h", "Left"}, right = {"l", "Right"}}
local mod = keys.mod or "Mod4" local mod = keys.mod or "Mod4"
@ -32,7 +32,7 @@ local function new(args)
root.fake_input("key_press", "Down") root.fake_input("key_press", "Down")
root.fake_input("key_release", "Down") root.fake_input("key_release", "Down")
end end
tmux.navigate = function(dir) local tmux_navigate = function(dir)
keygrabber.stop() keygrabber.stop()
root.fake_input("key_release", mod_keysym) root.fake_input("key_release", mod_keysym)
root.fake_input("key_press", "Control_L") root.fake_input("key_press", "Control_L")
@ -62,7 +62,7 @@ local function new(args)
root.fake_input("key_press", "j") root.fake_input("key_press", "j")
root.fake_input("key_release", "j") root.fake_input("key_release", "j")
end end
vim.navigate = function(dir) local vim_navigate = function(dir)
keygrabber.stop() keygrabber.stop()
root.fake_input("key_release", mod_keysym) root.fake_input("key_release", mod_keysym)
root.fake_input("key_release", "Control_L") root.fake_input("key_release", "Control_L")
@ -72,55 +72,55 @@ local function new(args)
root.fake_input("key_press", mod_keysym) root.fake_input("key_press", mod_keysym)
end end
-- use dynamic titles to determine type of client (default)
local navigate = function(dir) local navigate = function(dir)
local c = client.focus local c = client.focus
local client_name = c and c.name or "" local client_name = c and c.name or ""
if string.find(client_name, "- N?VIM$") then if string.find(client_name, "- N?VIM$") then
return vim.navigate(dir) return vim_navigate(dir)
else elseif string.find(client_name, "- TMUX$") then
if string.find(client_name, "- TMUX$") then return tmux_navigate(dir)
return tmux.navigate(dir)
else else
focus(dir) focus(dir)
end end
end end
end
-- experimental version that uses pstree to determine the running application -- use pstree to determine type of client (experimental)
if keys.experimental then if keys.experimental then
navigate = function(dir) navigate = function(dir)
local c = client.focus local c = client.focus
local pid = c and c.pid or -1 local pid = c and c.pid or -1
awful.spawn.easy_async("pstree -A -T " .. pid, function(out) awful.spawn.easy_async("pstree -A -T " .. pid, function(out)
if string.find(out, "[^.*\n]%-tmux: client") then if string.find(out, "[^.*\n]%-tmux: client") then
return tmux.navigate(dir) return tmux_navigate(dir)
else elseif string.find(out, "[^.*\n]%-n?vim$") or string.find(out, "[^.*\n]%-n?vim%-") or
if string.find(out, "[^.*\n]%-n?vim$") or string.find(out, "[^.*\n]%-n?vim%-") or
string.find(out, "^gvim$") or string.find(out, "^gvim%-") then string.find(out, "^gvim$") or string.find(out, "^gvim%-") then
return vim.navigate(dir) return vim_navigate(dir)
else else
focus(dir) focus(dir)
end end
end
end) end)
end end
end end
-- register focus signal
awesome.connect_signal("navigator::focus", focus) awesome.connect_signal("navigator::focus", focus)
keys.mod = nil -- setup keybinds
keys.mod_keysym = nil
keys.experimental = nil
keys.focus = nil
local aw = {}
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function() glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
local aw = {}
for k, v in pairs(keys) do for k, v in pairs(keys) do
for _, dir in pairs({"left", "right", "up", "down"}) do
if k == dir then
for _, key_name in ipairs(v) do for _, key_name in ipairs(v) do
aw[#aw + 1] = awful.key({mod}, key_name, function() aw[#aw + 1] = awful.key({mod}, key_name, function()
navigate(k) navigate(k)
end, {description = "navigate " .. k, group = "client"}) end, {description = "navigate " .. k, group = "client"})
end end
break
end
end
end end
root.keys(awful.util.table.join(root.keys(), unpack(aw))) root.keys(awful.util.table.join(root.keys(), unpack(aw)))
end) end)