provide option to define the modifier key
This commit is contained in:
parent
f54a4d502c
commit
627dd2993f
13
README.md
13
README.md
|
@ -27,16 +27,23 @@ git clone https://github.com/intrntbrn/awesomewm-vim-tmux-navigator ~/.config/aw
|
|||
```
|
||||
It's not recommended to change the path since it's hardcoded in other configuration files.
|
||||
|
||||
Add your preferred navigation (focus) keybinds to `rc.lua` (e.g. <kbd>Mod4</kbd>+<kbd>arrow</kbd> or <kbd>Mod4</kbd>+<kbd>hjkl</kbd>)
|
||||
Add your preferred navigation (focus) keybinds to `rc.lua` (e.g. <kbd>Mod4</kbd>+<kbd>arrows</kbd> or <kbd>Mod4</kbd>+<kbd>hjkl</kbd>)
|
||||
|
||||
```
|
||||
require("awesomewm-vim-tmux-navigator"){
|
||||
require("awesomewm-vim-tmux-navigator") {
|
||||
up = {"Up", "k"},
|
||||
down = {"Down", "j"},
|
||||
left = {"Left", "h"},
|
||||
right = {"Right", "l"},
|
||||
}
|
||||
mod = "Mod4",
|
||||
mod_keysym = "Super_L"
|
||||
}
|
||||
```
|
||||
|
||||
Please verify that `mod` and `mod_keysym` matches your actual awesomewm modifier key by using the terminal application `xev`.
|
||||
For instance you might be using the right windows/super key and have to specify "Super_R" as your `mod_keysym`, or "Mod1" and "Alt_L" if you prefer to use the alt key.
|
||||
|
||||
|
||||
Remove conflicting keybinds from your `rc.lua`.
|
||||
|
||||
### Vim
|
||||
|
|
116
init.lua
116
init.lua
|
@ -1,97 +1,101 @@
|
|||
local capi = {root = root, screen = screen, client = client, keygrabber = keygrabber}
|
||||
local awful = require("awful")
|
||||
local glib = require("lgi").GLib
|
||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||
local unpack = unpack or table.unpack -- luacheck: globals unpack
|
||||
local module = {}
|
||||
|
||||
local keys = {up = {"k"}, down = {"j"}, left = {"h"}, right = {"l"}}
|
||||
local function new(args)
|
||||
local client, root, keygrabber = 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 function new(ks)
|
||||
keys = ks or keys
|
||||
local aw = {}
|
||||
local mod = keys.mod or "Mod4"
|
||||
local mod_keysym = keys.mod_keysym or "Super_L"
|
||||
|
||||
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
|
||||
for k, v in pairs(keys) do
|
||||
for _, key_name in ipairs(v) do
|
||||
aw[#aw + 1] = awful.key({"Mod4"}, key_name, function()
|
||||
module.focus(k)
|
||||
end, {description = "focus " .. key_name .. " window", group = "client"})
|
||||
end
|
||||
end
|
||||
capi.root.keys(awful.util.table.join(capi.root.keys(), unpack(aw)))
|
||||
end)
|
||||
return module
|
||||
end
|
||||
|
||||
function module.focus(dir)
|
||||
local c = capi.client.focus
|
||||
local focus = function(dir)
|
||||
local c = client.focus
|
||||
local client_name = c and c.name or ""
|
||||
if string.find(client_name, "- N?VIM$") then
|
||||
capi.keygrabber.stop()
|
||||
capi.root.fake_input("key_release", "Super_L")
|
||||
capi.root.fake_input("key_release", "Control_L")
|
||||
capi.root.fake_input("key_press", "Control_L")
|
||||
keygrabber.stop()
|
||||
root.fake_input("key_release", mod_keysym)
|
||||
root.fake_input("key_release", "Control_L")
|
||||
root.fake_input("key_press", "Control_L")
|
||||
if dir == "left" then
|
||||
capi.root.fake_input("key_release", "h")
|
||||
capi.root.fake_input("key_press", "h")
|
||||
capi.root.fake_input("key_release", "h")
|
||||
root.fake_input("key_release", "h")
|
||||
root.fake_input("key_press", "h")
|
||||
root.fake_input("key_release", "h")
|
||||
else
|
||||
if dir == "right" then
|
||||
capi.root.fake_input("key_release", "l")
|
||||
capi.root.fake_input("key_press", "l")
|
||||
capi.root.fake_input("key_release", "l")
|
||||
root.fake_input("key_release", "l")
|
||||
root.fake_input("key_press", "l")
|
||||
root.fake_input("key_release", "l")
|
||||
else
|
||||
if dir == "up" then
|
||||
capi.root.fake_input("key_release", "k")
|
||||
capi.root.fake_input("key_press", "k")
|
||||
capi.root.fake_input("key_release", "k")
|
||||
root.fake_input("key_release", "k")
|
||||
root.fake_input("key_press", "k")
|
||||
root.fake_input("key_release", "k")
|
||||
else
|
||||
if dir == "down" then
|
||||
capi.root.fake_input("key_release", "j")
|
||||
capi.root.fake_input("key_press", "j")
|
||||
capi.root.fake_input("key_release", "j")
|
||||
root.fake_input("key_release", "j")
|
||||
root.fake_input("key_press", "j")
|
||||
root.fake_input("key_release", "j")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
capi.root.fake_input("key_release", "Control_L")
|
||||
capi.root.fake_input("key_press", "Super_L")
|
||||
root.fake_input("key_release", "Control_L")
|
||||
root.fake_input("key_press", mod_keysym)
|
||||
return
|
||||
else
|
||||
if string.find(client_name, "- TMUX$") then
|
||||
capi.keygrabber.stop()
|
||||
capi.root.fake_input("key_release", "Super_L")
|
||||
capi.root.fake_input("key_press", "Control_L")
|
||||
keygrabber.stop()
|
||||
root.fake_input("key_release", mod_keysym)
|
||||
root.fake_input("key_press", "Control_L")
|
||||
if dir == "left" then
|
||||
capi.root.fake_input("key_release", "Left")
|
||||
capi.root.fake_input("key_press", "Left")
|
||||
capi.root.fake_input("key_release", "Left")
|
||||
root.fake_input("key_release", "Left")
|
||||
root.fake_input("key_press", "Left")
|
||||
root.fake_input("key_release", "Left")
|
||||
else
|
||||
if dir == "right" then
|
||||
capi.root.fake_input("key_release", "Right")
|
||||
capi.root.fake_input("key_press", "Right")
|
||||
capi.root.fake_input("key_release", "Right")
|
||||
root.fake_input("key_release", "Right")
|
||||
root.fake_input("key_press", "Right")
|
||||
root.fake_input("key_release", "Right")
|
||||
else
|
||||
if dir == "up" then
|
||||
capi.root.fake_input("key_release", "Up")
|
||||
capi.root.fake_input("key_press", "Up")
|
||||
capi.root.fake_input("key_release", "Up")
|
||||
root.fake_input("key_release", "Up")
|
||||
root.fake_input("key_press", "Up")
|
||||
root.fake_input("key_release", "Up")
|
||||
else
|
||||
if dir == "down" then
|
||||
capi.root.fake_input("key_release", "Down")
|
||||
capi.root.fake_input("key_press", "Down")
|
||||
capi.root.fake_input("key_release", "Down")
|
||||
root.fake_input("key_release", "Down")
|
||||
root.fake_input("key_press", "Down")
|
||||
root.fake_input("key_release", "Down")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
capi.root.fake_input("key_release", "Control_L")
|
||||
capi.root.fake_input("key_press", "Super_L")
|
||||
root.fake_input("key_release", "Control_L")
|
||||
root.fake_input("key_press", mod_keysym)
|
||||
return
|
||||
else
|
||||
awful.client.focus.global_bydirection(dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
keys.mod = nil
|
||||
keys.mod_keysym = nil
|
||||
|
||||
local aw = {}
|
||||
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
|
||||
for k, v in pairs(keys) do
|
||||
for _, key_name in ipairs(v) do
|
||||
aw[#aw + 1] = awful.key({mod}, key_name, function()
|
||||
focus(k)
|
||||
end, {description = "focus " .. k .. " window", group = "client"})
|
||||
end
|
||||
end
|
||||
root.keys(awful.util.table.join(root.keys(), unpack(aw)))
|
||||
end)
|
||||
return module
|
||||
end
|
||||
|
||||
return setmetatable(module, {
|
||||
|
|
Loading…
Reference in New Issue