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,7 +27,7 @@ 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") {
@ -35,8 +35,15 @@ require("awesomewm-vim-tmux-navigator"){
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

116
init.lua
View File

@ -1,92 +1,79 @@
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
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 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
capi.keygrabber.stop() keygrabber.stop()
capi.root.fake_input("key_release", "Super_L") root.fake_input("key_release", mod_keysym)
capi.root.fake_input("key_release", "Control_L") root.fake_input("key_release", "Control_L")
capi.root.fake_input("key_press", "Control_L") root.fake_input("key_press", "Control_L")
if dir == "left" then if dir == "left" then
capi.root.fake_input("key_release", "h") root.fake_input("key_release", "h")
capi.root.fake_input("key_press", "h") root.fake_input("key_press", "h")
capi.root.fake_input("key_release", "h") root.fake_input("key_release", "h")
else else
if dir == "right" then if dir == "right" then
capi.root.fake_input("key_release", "l") root.fake_input("key_release", "l")
capi.root.fake_input("key_press", "l") root.fake_input("key_press", "l")
capi.root.fake_input("key_release", "l") root.fake_input("key_release", "l")
else else
if dir == "up" then if dir == "up" then
capi.root.fake_input("key_release", "k") root.fake_input("key_release", "k")
capi.root.fake_input("key_press", "k") root.fake_input("key_press", "k")
capi.root.fake_input("key_release", "k") root.fake_input("key_release", "k")
else else
if dir == "down" then if dir == "down" then
capi.root.fake_input("key_release", "j") root.fake_input("key_release", "j")
capi.root.fake_input("key_press", "j") root.fake_input("key_press", "j")
capi.root.fake_input("key_release", "j") 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
if string.find(client_name, "- TMUX$") then if string.find(client_name, "- TMUX$") then
capi.keygrabber.stop() keygrabber.stop()
capi.root.fake_input("key_release", "Super_L") root.fake_input("key_release", mod_keysym)
capi.root.fake_input("key_press", "Control_L") 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", "Left")
capi.root.fake_input("key_press", "Left") root.fake_input("key_press", "Left")
capi.root.fake_input("key_release", "Left") root.fake_input("key_release", "Left")
else else
if dir == "right" then if dir == "right" then
capi.root.fake_input("key_release", "Right") root.fake_input("key_release", "Right")
capi.root.fake_input("key_press", "Right") root.fake_input("key_press", "Right")
capi.root.fake_input("key_release", "Right") root.fake_input("key_release", "Right")
else else
if dir == "up" then if dir == "up" then
capi.root.fake_input("key_release", "Up") root.fake_input("key_release", "Up")
capi.root.fake_input("key_press", "Up") root.fake_input("key_press", "Up")
capi.root.fake_input("key_release", "Up") root.fake_input("key_release", "Up")
else else
if dir == "down" then if dir == "down" then
capi.root.fake_input("key_release", "Down") root.fake_input("key_release", "Down")
capi.root.fake_input("key_press", "Down") root.fake_input("key_press", "Down")
capi.root.fake_input("key_release", "Down") root.fake_input("key_release", "Down")
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) awful.client.focus.global_bydirection(dir)
@ -94,6 +81,23 @@ function module.focus(dir)
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
return setmetatable(module, { return setmetatable(module, {
__call = function(_, ...) __call = function(_, ...)
return new(...) return new(...)