awful: add some control with modkeys
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
975eba0049
commit
6d2fc20038
57
awful.lua
57
awful.lua
|
@ -474,6 +474,14 @@ local function menu(args, textbox, exe_callback)
|
||||||
textbox:set("text", prompt .. menu_text_with_cursor(text, inv_col, cur_col, cur_pos))
|
textbox:set("text", prompt .. menu_text_with_cursor(text, inv_col, cur_col, cur_pos))
|
||||||
keygrabber.run(
|
keygrabber.run(
|
||||||
function (mod, key)
|
function (mod, key)
|
||||||
|
local has_ctrl = false
|
||||||
|
|
||||||
|
-- Compute modifiers keys
|
||||||
|
for k, v in ipairs(mod) do
|
||||||
|
if v == "Control" then has_ctrl = true end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get out cases
|
||||||
if key == "Return" then
|
if key == "Return" then
|
||||||
textbox:set("text", "")
|
textbox:set("text", "")
|
||||||
exe_callback(command)
|
exe_callback(command)
|
||||||
|
@ -481,26 +489,41 @@ local function menu(args, textbox, exe_callback)
|
||||||
elseif key == "Escape" then
|
elseif key == "Escape" then
|
||||||
textbox:set("text", "")
|
textbox:set("text", "")
|
||||||
return false
|
return false
|
||||||
elseif key == "BackSpace" then
|
end
|
||||||
command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
|
|
||||||
cur_pos = cur_pos - 1
|
-- Control cases
|
||||||
-- That's DEL
|
if has_ctrl then
|
||||||
elseif key:byte() == 127 then
|
if key == "a" then
|
||||||
command = command:sub(1, cur_pos - 1) .. command:sub(cur_pos + 1)
|
cur_pos = 1
|
||||||
elseif key == "Left" then
|
elseif key == "e" then
|
||||||
cur_pos = cur_pos - 1
|
cur_pos = #command + 1
|
||||||
elseif key == "Right" then
|
end
|
||||||
cur_pos = cur_pos + 1
|
|
||||||
else
|
else
|
||||||
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
|
-- Typin cases
|
||||||
cur_pos = cur_pos + 1
|
if key == "BackSpace" then
|
||||||
end
|
command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
|
||||||
if cur_pos < 1 then
|
cur_pos = cur_pos - 1
|
||||||
cur_pos = 1
|
-- That's DEL
|
||||||
elseif cur_pos > #command + 1 then
|
elseif key:byte() == 127 then
|
||||||
cur_pos = #command + 1
|
command = command:sub(1, cur_pos - 1) .. command:sub(cur_pos + 1)
|
||||||
|
elseif key == "Left" then
|
||||||
|
cur_pos = cur_pos - 1
|
||||||
|
elseif key == "Right" then
|
||||||
|
cur_pos = cur_pos + 1
|
||||||
|
else
|
||||||
|
command = command:sub(1, cur_pos - 1) .. key .. command:sub(cur_pos)
|
||||||
|
cur_pos = cur_pos + 1
|
||||||
|
end
|
||||||
|
if cur_pos < 1 then
|
||||||
|
cur_pos = 1
|
||||||
|
elseif cur_pos > #command + 1 then
|
||||||
|
cur_pos = #command + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update textbox
|
||||||
textbox:set("text", prompt .. menu_text_with_cursor(command, inv_col, cur_col, cur_pos))
|
textbox:set("text", prompt .. menu_text_with_cursor(command, inv_col, cur_col, cur_pos))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue