provide option to define own focus function
This commit is contained in:
parent
6a2c72c643
commit
6171918286
|
@ -49,6 +49,8 @@ For instance you might be using the right windows/super key and have to specify
|
||||||
|
|
||||||
Don't forget to remove your previously used navigation keybinds (or other conflicting keybinds) in `rc.lua`.
|
Don't forget to remove your previously used navigation keybinds (or other conflicting keybinds) in `rc.lua`.
|
||||||
|
|
||||||
|
It is possible to use a custom focus function by defining `focus`. Default is `awful.client.focus.global_bydirection`.
|
||||||
|
|
||||||
### Vim
|
### Vim
|
||||||
|
|
||||||
|
|
||||||
|
|
30
init.lua
30
init.lua
|
@ -4,11 +4,12 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
local function new(args)
|
local function new(args)
|
||||||
local client, root, keygrabber = client, root, keygrabber -- luacheck: globals client root keygrabber
|
local awesome, client, root, keygrabber = awesome, client, root, keygrabber -- luacheck: 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"
|
||||||
local mod_keysym = keys.mod_keysym or "Super_L"
|
local mod_keysym = keys.mod_keysym or "Super_L"
|
||||||
|
local focus = keys.focus or awful.client.focus.global_bydirection
|
||||||
|
|
||||||
local tmux = {}
|
local tmux = {}
|
||||||
tmux.left = function()
|
tmux.left = function()
|
||||||
|
@ -71,55 +72,54 @@ local function new(args)
|
||||||
root.fake_input("key_press", mod_keysym)
|
root.fake_input("key_press", mod_keysym)
|
||||||
end
|
end
|
||||||
|
|
||||||
local focus = 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
|
||||||
vim.navigate(dir)
|
return vim.navigate(dir)
|
||||||
return
|
|
||||||
else
|
else
|
||||||
if string.find(client_name, "- TMUX$") then
|
if string.find(client_name, "- TMUX$") then
|
||||||
tmux.navigate(dir)
|
return tmux.navigate(dir)
|
||||||
return
|
|
||||||
else
|
else
|
||||||
awful.client.focus.global_bydirection(dir)
|
focus(dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- experimental version that uses pstree to determine the running application
|
-- experimental version that uses pstree to determine the running application
|
||||||
if keys.experimental then
|
if keys.experimental then
|
||||||
focus = 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
|
||||||
tmux.navigate(dir)
|
return tmux.navigate(dir)
|
||||||
return
|
|
||||||
else
|
else
|
||||||
if 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
|
||||||
vim.navigate(dir)
|
return vim.navigate(dir)
|
||||||
return
|
|
||||||
else
|
else
|
||||||
awful.client.focus.global_bydirection(dir)
|
focus(dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
awesome.connect_signal("navigator::focus", focus)
|
||||||
|
|
||||||
keys.mod = nil
|
keys.mod = nil
|
||||||
keys.mod_keysym = nil
|
keys.mod_keysym = nil
|
||||||
keys.experimental = nil
|
keys.experimental = nil
|
||||||
|
keys.focus = nil
|
||||||
|
|
||||||
local aw = {}
|
local aw = {}
|
||||||
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
|
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
|
||||||
for k, v in pairs(keys) do
|
for k, v in pairs(keys) do
|
||||||
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()
|
||||||
focus(k)
|
navigate(k)
|
||||||
end, {description = "focus " .. k .. " window", group = "client"})
|
end, {description = "navigate " .. k, group = "client"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
root.keys(awful.util.table.join(root.keys(), unpack(aw)))
|
root.keys(awful.util.table.join(root.keys(), unpack(aw)))
|
||||||
|
|
|
@ -114,7 +114,7 @@ func! s:SystemWindowNavigate(cmd)
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let dir = s:CmdToDir(a:cmd)
|
let dir = s:CmdToDir(a:cmd)
|
||||||
call system('awesome-client ''require("awful.client").focus.global_bydirection("' . dir . '") ''')
|
call system('awesome-client ''awesome.emit_signal("navigator::focus","' . dir . '")''')
|
||||||
|
|
||||||
if !has("gui_running")
|
if !has("gui_running")
|
||||||
redraw!
|
redraw!
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
dir=$1
|
dir=$1
|
||||||
|
|
||||||
wm_focus() {
|
wm_focus() {
|
||||||
awesome-client 'require("awful.client").focus.global_bydirection("'"$dir"'")'
|
awesome-client 'awesome.emit_signal("navigator::focus", "'"$dir"'")'
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$dir" in
|
case "$dir" in
|
||||||
|
|
Loading…
Reference in New Issue