provide option to define the modifier key

This commit is contained in:
BZ 2021-03-29 15:14:28 +02:00
parent f54a4d502c
commit 627dd2993f
2 changed files with 91 additions and 80 deletions

View File

@ -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. 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"}, up = {"Up", "k"},
down = {"Down", "j"}, down = {"Down", "j"},
left = {"Left", "h"}, left = {"Left", "h"},
right = {"Right", "l"}, 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`. Remove conflicting keybinds from your `rc.lua`.
### Vim ### Vim

150
init.lua
View File

@ -1,97 +1,101 @@
local capi = {root = root, screen = screen, client = client, keygrabber = keygrabber}
local awful = require("awful") local awful = require("awful")
local glib = require("lgi").GLib 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 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) local mod = keys.mod or "Mod4"
keys = ks or keys local mod_keysym = keys.mod_keysym or "Super_L"
local aw = {}
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function() local focus = function(dir)
for k, v in pairs(keys) do local c = client.focus
for _, key_name in ipairs(v) do local client_name = c and c.name or ""
aw[#aw + 1] = awful.key({"Mod4"}, key_name, function() if string.find(client_name, "- N?VIM$") then
module.focus(k) keygrabber.stop()
end, {description = "focus " .. key_name .. " window", group = "client"}) root.fake_input("key_release", mod_keysym)
end root.fake_input("key_release", "Control_L")
end root.fake_input("key_press", "Control_L")
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 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")
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")
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")
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")
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")
end
end
end
end
capi.root.fake_input("key_release", "Control_L")
capi.root.fake_input("key_press", "Super_L")
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")
if dir == "left" then if dir == "left" then
capi.root.fake_input("key_release", "Left") root.fake_input("key_release", "h")
capi.root.fake_input("key_press", "Left") root.fake_input("key_press", "h")
capi.root.fake_input("key_release", "Left") root.fake_input("key_release", "h")
else else
if dir == "right" then if dir == "right" then
capi.root.fake_input("key_release", "Right") root.fake_input("key_release", "l")
capi.root.fake_input("key_press", "Right") root.fake_input("key_press", "l")
capi.root.fake_input("key_release", "Right") root.fake_input("key_release", "l")
else else
if dir == "up" then if dir == "up" then
capi.root.fake_input("key_release", "Up") root.fake_input("key_release", "k")
capi.root.fake_input("key_press", "Up") root.fake_input("key_press", "k")
capi.root.fake_input("key_release", "Up") root.fake_input("key_release", "k")
else else
if dir == "down" then if dir == "down" then
capi.root.fake_input("key_release", "Down") root.fake_input("key_release", "j")
capi.root.fake_input("key_press", "Down") root.fake_input("key_press", "j")
capi.root.fake_input("key_release", "Down") root.fake_input("key_release", "j")
end end
end end
end end
end end
capi.root.fake_input("key_release", "Control_L") root.fake_input("key_release", "Control_L")
capi.root.fake_input("key_press", "Super_L") root.fake_input("key_press", mod_keysym)
return return
else else
awful.client.focus.global_bydirection(dir) if string.find(client_name, "- TMUX$") then
keygrabber.stop()
root.fake_input("key_release", mod_keysym)
root.fake_input("key_press", "Control_L")
if dir == "left" then
root.fake_input("key_release", "Left")
root.fake_input("key_press", "Left")
root.fake_input("key_release", "Left")
else
if dir == "right" then
root.fake_input("key_release", "Right")
root.fake_input("key_press", "Right")
root.fake_input("key_release", "Right")
else
if dir == "up" then
root.fake_input("key_release", "Up")
root.fake_input("key_press", "Up")
root.fake_input("key_release", "Up")
else
if dir == "down" then
root.fake_input("key_release", "Down")
root.fake_input("key_press", "Down")
root.fake_input("key_release", "Down")
end
end
end
end
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
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 end
return setmetatable(module, { return setmetatable(module, {