2014-05-15 05:43:19 +02:00
|
|
|
local capi = {root=root,client=client,mouse=mouse,
|
2014-05-08 05:51:28 +02:00
|
|
|
screen = screen, keygrabber = keygrabber}
|
2014-10-16 07:20:41 +02:00
|
|
|
local util = require( "awful.util" )
|
|
|
|
local awful = require( "awful" )
|
|
|
|
local glib = require( "lgi" ).GLib
|
|
|
|
local col_utils = require( "collision.util" )
|
2014-05-08 05:51:28 +02:00
|
|
|
local module = {
|
2014-05-14 07:12:20 +02:00
|
|
|
_focus = require( "collision.focus" ),
|
|
|
|
_resize = require( "collision.resize"),
|
|
|
|
_max = require( "collision.max" ),
|
2014-10-04 08:53:01 +02:00
|
|
|
_screen = require( "collision.screen"),
|
2014-10-16 07:20:41 +02:00
|
|
|
settings= col_utils.settings ,
|
2014-05-08 05:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local current_mode = "focus"
|
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
local event_callback = {
|
2014-05-10 05:09:17 +02:00
|
|
|
focus = module._focus._global_bydirection_key,
|
|
|
|
move = module._focus._global_bydirection_key,
|
2014-05-14 05:18:02 +02:00
|
|
|
resize = module._resize.resize ,
|
|
|
|
max = module._max.change_focus ,
|
2014-05-14 07:48:00 +02:00
|
|
|
tag = module._max.change_tag ,
|
2014-10-04 08:53:01 +02:00
|
|
|
screen = module._screen.reload ,
|
2014-05-08 05:51:28 +02:00
|
|
|
}
|
|
|
|
|
2014-05-10 06:42:59 +02:00
|
|
|
local start_callback = {
|
2014-05-15 05:43:19 +02:00
|
|
|
focus = module._focus.display ,
|
|
|
|
move = module._focus.display ,
|
|
|
|
resize = module._resize.display ,
|
2014-05-14 05:18:02 +02:00
|
|
|
max = module._max.display_clients,
|
2014-05-15 05:43:19 +02:00
|
|
|
tag = module._max.display_tags ,
|
2014-10-04 08:53:01 +02:00
|
|
|
screen = module._screen.display ,
|
2014-05-10 06:42:59 +02:00
|
|
|
}
|
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
local exit_callback = {
|
2014-05-15 05:43:19 +02:00
|
|
|
focus = module._focus._quit ,
|
|
|
|
move = module._focus._quit ,
|
|
|
|
resize = module._resize.hide ,
|
|
|
|
max = module._max.hide ,
|
|
|
|
tag = module._max.hide ,
|
2014-10-04 08:53:01 +02:00
|
|
|
screen = module._screen.hide ,
|
2014-05-08 07:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local keys = {--Normal Xephyr G510 alt G510
|
2014-05-11 05:46:27 +02:00
|
|
|
up = {"Up" --[[, "&" , "XF86AudioPause" , "F15"]] },
|
|
|
|
down = {"Down" --[[, "KP_Enter" , "XF86WebCam" , "F14"]] },
|
|
|
|
left = {"Left" --[[, "#" , "Cancel" , "F13"]] },
|
2014-05-15 05:43:19 +02:00
|
|
|
right = {"Right" --[[, "\"" , "XF86Paste" , "F17"]] },
|
2014-05-08 07:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local function exit_loop()
|
2014-05-10 05:09:17 +02:00
|
|
|
exit_callback[current_mode]()
|
|
|
|
capi.keygrabber.stop()
|
|
|
|
return false
|
2014-05-08 07:53:57 +02:00
|
|
|
end
|
|
|
|
|
2014-05-08 05:51:28 +02:00
|
|
|
-- Event loop
|
2014-05-08 07:53:57 +02:00
|
|
|
local function start_loop(is_swap,is_max)
|
2014-05-10 05:09:17 +02:00
|
|
|
capi.keygrabber.run(function(mod, key, event)
|
|
|
|
-- Detect the direction
|
|
|
|
for k,v in pairs(keys) do
|
|
|
|
if util.table.hasitem(v,key) then
|
|
|
|
if event == "press" then
|
|
|
|
if not event_callback[current_mode](mod,key,event,k,is_swap,is_max) then
|
|
|
|
return exit_loop()
|
|
|
|
end
|
|
|
|
return
|
2014-05-08 07:53:57 +02:00
|
|
|
end
|
2014-05-14 07:48:00 +02:00
|
|
|
return #mod > 0
|
2014-05-10 05:09:17 +02:00
|
|
|
end
|
|
|
|
end
|
2014-05-08 07:53:57 +02:00
|
|
|
|
2014-05-10 05:09:17 +02:00
|
|
|
if key == "Shift_L" or key == "Shift_R" then
|
|
|
|
is_swap = event == "press"
|
2014-05-14 07:48:00 +02:00
|
|
|
return #mod > 0
|
2014-05-10 05:09:17 +02:00
|
|
|
elseif key == "Control_L" or key == "Control_R" then
|
|
|
|
is_max = event == "press"
|
2014-05-15 05:43:19 +02:00
|
|
|
return #mod > 0 and awful.util.table.hasitem(mod,"Mod4") or exit_loop()
|
2014-05-10 06:42:59 +02:00
|
|
|
elseif key == "Alt_L" or key == "Alt_R" then
|
|
|
|
exit_callback[current_mode]()
|
|
|
|
current_mode = event == "press" and "resize" or "focus"
|
|
|
|
start_callback[current_mode](mod,key,event,k,is_swap,is_max)
|
2014-05-15 05:43:19 +02:00
|
|
|
return #mod > 0 and awful.util.table.hasitem(mod,"Mod4") or exit_loop()
|
2014-05-10 05:09:17 +02:00
|
|
|
end
|
2014-05-08 07:53:57 +02:00
|
|
|
|
2014-05-10 05:09:17 +02:00
|
|
|
return exit_loop()
|
|
|
|
end)
|
2014-05-08 05:51:28 +02:00
|
|
|
end
|
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
function module.focus(direction,c,max)
|
2014-10-03 05:57:22 +02:00
|
|
|
local screen = (c or ((capi.client.focus and capi.client.focus.focusable) and capi.client.focus or capi.mouse)).screen
|
2014-07-26 07:38:27 +02:00
|
|
|
-- Useless when there is only 1 client tiled, incompatible with the "max_out" mode (in this case, focus floating mode)
|
|
|
|
if awful.layout.get(screen) == awful.layout.suit.max and #awful.client.tiled(screen) > 1 and not max then
|
2014-05-14 07:48:00 +02:00
|
|
|
current_mode = "max"
|
2014-05-15 05:43:19 +02:00
|
|
|
module._max.display_clients(screen,direction)
|
2014-05-14 07:48:00 +02:00
|
|
|
else
|
|
|
|
current_mode = "focus"
|
|
|
|
module._focus.global_bydirection(direction,c,false,max)
|
|
|
|
end
|
|
|
|
start_loop(false,max)
|
2014-05-08 05:51:28 +02:00
|
|
|
end
|
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
function module.move(direction,c,max)
|
2014-05-14 07:48:00 +02:00
|
|
|
current_mode = "move"
|
2014-10-04 23:00:51 +02:00
|
|
|
module._focus.global_bydirection(direction,c,true,max)
|
2014-05-14 07:48:00 +02:00
|
|
|
start_loop(true,max)
|
2014-05-08 05:51:28 +02:00
|
|
|
end
|
|
|
|
|
2014-05-10 05:09:17 +02:00
|
|
|
function module.resize(direction,c,max)
|
2014-05-14 07:48:00 +02:00
|
|
|
current_mode = "resize"
|
|
|
|
start_loop(false,max)
|
|
|
|
module._resize.display(c)
|
2014-05-10 05:09:17 +02:00
|
|
|
end
|
|
|
|
|
2014-10-16 07:20:41 +02:00
|
|
|
function module.tag(direction,swap,max)
|
2014-05-14 07:48:00 +02:00
|
|
|
current_mode = "tag"
|
2014-10-16 07:20:41 +02:00
|
|
|
local c = capi.client.focus
|
|
|
|
module._max.display_tags((c) and c.screen or capi.mouse.screen,direction,c,true,max)
|
|
|
|
start_loop(swap,max)
|
2014-05-14 07:48:00 +02:00
|
|
|
end
|
|
|
|
|
2014-10-04 08:53:01 +02:00
|
|
|
function module.screen(direction)
|
|
|
|
current_mode = "screen"
|
2014-10-18 03:55:53 +02:00
|
|
|
module._screen.display(nil,direction)
|
2014-10-04 08:53:01 +02:00
|
|
|
start_loop(false,max)
|
|
|
|
end
|
|
|
|
|
2014-05-11 05:46:27 +02:00
|
|
|
local function new(k)
|
2014-09-08 06:05:16 +02:00
|
|
|
-- Replace the keys array. The new one has to have a valid mapping
|
|
|
|
keys = k or keys
|
2014-05-11 05:46:27 +02:00
|
|
|
local aw = {}
|
|
|
|
|
2014-10-16 07:20:41 +02:00
|
|
|
-- This have to be executer after rc.lua
|
|
|
|
glib.idle_add(glib.PRIORITY_DEFAULT_IDLE, function()
|
|
|
|
for k,v in pairs(keys) do
|
|
|
|
for _,key_nane in ipairs(v) do
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", }, key_nane, function () module.focus (k ) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", "Mod1" }, key_nane, function () module.resize(k ) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", "Shift" }, key_nane, function () module.move (k ) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", "Shift", "Control" }, key_nane, function () module.move (k,nil ,true) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", "Control" }, key_nane, function () module.focus (k,nil ,true) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod4", "Mod1" , "Control" }, key_nane, function () module.screen(k ) end)
|
|
|
|
if k == "left" or k =="right" then -- Conflict with my text editor, so I say no
|
|
|
|
aw[#aw+1] = awful.key({ "Mod1", "Control" }, key_nane, function () module.tag (k,nil ,true) end)
|
|
|
|
aw[#aw+1] = awful.key({ "Mod1", "Shift", "Control" }, key_nane, function () module.tag (k,true,true) end)
|
|
|
|
end
|
2014-07-26 07:38:27 +02:00
|
|
|
end
|
2014-05-11 05:46:27 +02:00
|
|
|
end
|
2014-10-16 07:20:41 +02:00
|
|
|
capi.root.keys(awful.util.table.join(capi.root.keys(),unpack(aw)))
|
|
|
|
end)
|
2014-05-11 05:46:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2014-09-08 17:31:12 +02:00
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|