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