restore_mods and debug options
This commit is contained in:
parent
ee842bd0c5
commit
f3633468a1
83
init.lua
83
init.lua
|
@ -10,14 +10,8 @@ local function run_key_sequence(seq)
|
||||||
for _, s in ipairs(seq) do
|
for _, s in ipairs(seq) do
|
||||||
if s.action == "press" then
|
if s.action == "press" then
|
||||||
root.fake_input("key_press", s.key)
|
root.fake_input("key_press", s.key)
|
||||||
print("key_press: " .. s.key)
|
|
||||||
elseif s.action == "release" then
|
elseif s.action == "release" then
|
||||||
root.fake_input("key_release", s.key)
|
root.fake_input("key_release", s.key)
|
||||||
print("key_release: " .. s.key)
|
|
||||||
elseif s.action == "press_and_release" then
|
|
||||||
root.fake_input("key_release", s.key)
|
|
||||||
root.fake_input("key_press", s.key)
|
|
||||||
root.fake_input("key_release", s.key)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,53 +19,21 @@ end
|
||||||
local function run_key_sequence_xdotool(seq)
|
local function run_key_sequence_xdotool(seq)
|
||||||
keygrabber.stop()
|
keygrabber.stop()
|
||||||
|
|
||||||
-- combine inputs to speed things up
|
|
||||||
local queue = nil
|
|
||||||
|
|
||||||
local combine = false -- @WIP
|
|
||||||
|
|
||||||
print("")
|
|
||||||
|
|
||||||
local run_fn = function(s)
|
local run_fn = function(s)
|
||||||
if s.action == "press" then
|
if s.action == "press" then
|
||||||
if s.is_combined then
|
|
||||||
awful.spawn("xdotool key " .. s.key)
|
|
||||||
print("xdotool key " .. s.key)
|
|
||||||
else
|
|
||||||
awful.spawn("xdotool keydown " .. s.key)
|
awful.spawn("xdotool keydown " .. s.key)
|
||||||
print("xdotool keydown " .. s.key)
|
|
||||||
end
|
|
||||||
elseif s.action == "release" then
|
elseif s.action == "release" then
|
||||||
if s.is_combined then
|
|
||||||
else
|
|
||||||
awful.spawn("xdotool keyup " .. s.key)
|
awful.spawn("xdotool keyup " .. s.key)
|
||||||
print("xdotool keyup " .. s.key)
|
|
||||||
end
|
|
||||||
elseif s.action == "press_and_release" then
|
|
||||||
awful.spawn("xdotool key " .. s.key)
|
|
||||||
print("key " .. s.key)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, s in ipairs(seq) do
|
for _, s in ipairs(seq) do
|
||||||
if queue then
|
run_fn(s)
|
||||||
if combine and s.action == queue.action then
|
|
||||||
queue.key = string.format("%s+%s", queue.key, s.key)
|
|
||||||
queue.is_combined = true
|
|
||||||
else
|
|
||||||
run_fn(queue)
|
|
||||||
queue = s
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
queue = s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
run_fn(queue)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get key sequence to transition from current mods to next mods
|
-- get key sequence to transition from current mods to next mods
|
||||||
local change_mods = function(current, next)
|
local function change_mods(current, next)
|
||||||
local sequence = {}
|
local sequence = {}
|
||||||
local intersect = {}
|
local intersect = {}
|
||||||
|
|
||||||
|
@ -108,6 +70,15 @@ local change_mods = function(current, next)
|
||||||
return sequence
|
return sequence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function dump_sequence(seq)
|
||||||
|
local str = "{ "
|
||||||
|
for _, s in ipairs(seq) do
|
||||||
|
str = string.format("%s%s %s, ", str, s.action, s.key)
|
||||||
|
end
|
||||||
|
str = str .. "}"
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
local function new(args)
|
local function new(args)
|
||||||
local cfg = args
|
local cfg = args
|
||||||
or { up = { "k", "Up" }, down = { "j", "Down" }, left = { "h", "Left" }, right = {
|
or { up = { "k", "Up" }, down = { "j", "Down" }, left = { "h", "Left" }, right = {
|
||||||
|
@ -118,6 +89,8 @@ local function new(args)
|
||||||
local mod = cfg.mod or "Mod4"
|
local mod = cfg.mod or "Mod4"
|
||||||
local mod_keysym = cfg.mod_keysym or "Super_L"
|
local mod_keysym = cfg.mod_keysym or "Super_L"
|
||||||
local focus = cfg.focus or awful.client.focus.global_bydirection
|
local focus = cfg.focus or awful.client.focus.global_bydirection
|
||||||
|
local restore_mods = cfg.restore_mods or true
|
||||||
|
local debug = cfg.debug or false
|
||||||
|
|
||||||
local wm_keys = {
|
local wm_keys = {
|
||||||
mods = { mod_keysym },
|
mods = { mod_keysym },
|
||||||
|
@ -127,7 +100,7 @@ local function new(args)
|
||||||
right = cfg.right,
|
right = cfg.right,
|
||||||
}
|
}
|
||||||
|
|
||||||
local use_xdotool = cfg.use_xdotool or true
|
local use_xdotool = cfg.use_xdotool or false
|
||||||
|
|
||||||
local tmux_keys = cfg.tmux
|
local tmux_keys = cfg.tmux
|
||||||
or {
|
or {
|
||||||
|
@ -146,16 +119,21 @@ local function new(args)
|
||||||
right = "l",
|
right = "l",
|
||||||
}
|
}
|
||||||
|
|
||||||
local get_key_sequence = function(current_mods, next_mods, fn, dir)
|
local get_key_sequence = function(wm_mods, app_mods, fn, dir)
|
||||||
local sequence = {}
|
local sequence = {}
|
||||||
-- release wm mods, press vim/tmux mods
|
-- release wm mods, press vim/tmux mods
|
||||||
gears.table.merge(sequence, change_mods(current_mods, next_mods))
|
gears.table.merge(sequence, change_mods(wm_mods, app_mods))
|
||||||
|
|
||||||
-- press navigation direction
|
-- press navigation direction
|
||||||
gears.table.merge(sequence, fn(dir))
|
gears.table.merge(sequence, fn(dir))
|
||||||
|
|
||||||
|
local restored_mods = {}
|
||||||
|
if restore_mods then
|
||||||
|
restored_mods = wm_mods
|
||||||
|
end
|
||||||
|
|
||||||
-- release vim/tmux mods, restore wm mods
|
-- release vim/tmux mods, restore wm mods
|
||||||
gears.table.merge(sequence, change_mods(next_mods, current_mods))
|
gears.table.merge(sequence, change_mods(app_mods, restored_mods))
|
||||||
|
|
||||||
return sequence
|
return sequence
|
||||||
end
|
end
|
||||||
|
@ -170,7 +148,7 @@ local function new(args)
|
||||||
|
|
||||||
local navigate_vim = function(dir)
|
local navigate_vim = function(dir)
|
||||||
return {
|
return {
|
||||||
--{ action = "release", key = vim_keys[dir] },
|
{ action = "release", key = vim_keys[dir] },
|
||||||
{ action = "press", key = vim_keys[dir] },
|
{ action = "press", key = vim_keys[dir] },
|
||||||
{ action = "release", key = vim_keys[dir] },
|
{ action = "release", key = vim_keys[dir] },
|
||||||
}
|
}
|
||||||
|
@ -184,13 +162,24 @@ local function new(args)
|
||||||
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
|
||||||
run_fn(get_key_sequence(wm_keys.mods, vim_keys.mods, navigate_vim, dir))
|
local seq = get_key_sequence(wm_keys.mods, vim_keys.mods, navigate_vim, dir)
|
||||||
|
run_fn(seq)
|
||||||
|
if debug then
|
||||||
|
debug(string.format("VIM(%s): %s", dir, dump_sequence(seq)))
|
||||||
|
end
|
||||||
return
|
return
|
||||||
elseif string.find(client_name, "%- TMUX$") then
|
elseif string.find(client_name, "%- TMUX$") then
|
||||||
run_fn(get_key_sequence(wm_keys.mods, tmux_keys.mods, navigate_tmux, dir))
|
local seq = get_key_sequence(wm_keys.mods, tmux_keys.mods, navigate_tmux, dir)
|
||||||
|
run_fn(seq)
|
||||||
|
if debug then
|
||||||
|
debug(string.format("TMUX(%s): %s", dir, dump_sequence(seq)))
|
||||||
|
end
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
focus(dir)
|
focus(dir)
|
||||||
|
if debug then
|
||||||
|
debug(string.format("WM(%s)", dir))
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue