2013-07-17 06:53:30 +02:00
|
|
|
local capi = { client = client , mouse = mouse ,
|
|
|
|
screen = screen , keygrabber = keygrabber,}
|
2013-06-03 23:22:41 +02:00
|
|
|
|
2013-07-17 06:53:30 +02:00
|
|
|
local ipairs = ipairs
|
2016-06-13 05:31:00 +02:00
|
|
|
local grect = require( "gears.geometry" ).rectangle
|
|
|
|
local placement = require( "awful.placement")
|
2016-12-07 01:53:02 +01:00
|
|
|
local areamap = require( "collision.areamap" )
|
|
|
|
local focus_arrow = require( "collision.widgets.focus_arrow" )
|
2013-06-03 23:22:41 +02:00
|
|
|
|
|
|
|
local module = {}
|
2016-12-07 01:53:02 +01:00
|
|
|
local wiboxes = nil
|
|
|
|
|
|
|
|
local target_client = nil
|
|
|
|
local current_map = nil
|
2013-06-03 23:22:41 +02:00
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
---------------- Visual -----------------------
|
2013-07-17 06:53:30 +02:00
|
|
|
local function init()
|
2016-06-13 05:31:00 +02:00
|
|
|
wiboxes = {}
|
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
for _,dir in ipairs({"up","right","down","left","center"}) do
|
|
|
|
wiboxes[dir] = focus_arrow(dir)
|
2016-06-13 05:31:00 +02:00
|
|
|
end
|
2013-06-03 23:22:41 +02:00
|
|
|
end
|
|
|
|
|
2015-03-15 04:17:18 +01:00
|
|
|
local function emulate_client(screen)
|
|
|
|
return {is_screen = true, screen=screen, geometry=function() return capi.screen[screen].workarea end}
|
|
|
|
end
|
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
local function display_wiboxes(cltbl)
|
|
|
|
if not wiboxes then
|
|
|
|
init()
|
2014-05-08 07:53:57 +02:00
|
|
|
end
|
2013-06-03 23:22:41 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
local fc = target_client-- or emulate_client(capi.mouse.screen)
|
2013-06-03 23:22:41 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
if not fc then return end
|
|
|
|
|
|
|
|
for k,v in ipairs({"left","right","up","down","center"}) do
|
|
|
|
|
|
|
|
local next_clients = cltbl[grect.get_in_direction(v , cltbl, fc)]
|
|
|
|
|
|
|
|
if next_clients or k==5 then
|
|
|
|
local parent = k==5 and fc or next_clients
|
|
|
|
wiboxes[v].visible = true
|
|
|
|
placement.centered(wiboxes[v], {parent = parent})
|
|
|
|
else
|
|
|
|
wiboxes[v].visible = false
|
|
|
|
end
|
2013-06-03 23:22:41 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
end
|
2013-06-03 23:22:41 +02:00
|
|
|
end
|
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
|
|
|
|
local function bydirection(dir, c, swap, max)
|
|
|
|
if not c then
|
|
|
|
c = emulate_client(capi.mouse.screen)
|
2015-03-15 06:16:31 +01:00
|
|
|
end
|
|
|
|
|
2015-03-15 04:17:18 +01:00
|
|
|
-- Get all clients rectangle
|
2016-12-07 01:53:02 +01:00
|
|
|
local cltbl = current_map and current_map.rects or nil
|
2015-03-15 06:16:31 +01:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
if not cltbl then
|
|
|
|
current_map = areamap()
|
|
|
|
cltbl = current_map.rects
|
2015-03-15 04:17:18 +01:00
|
|
|
end
|
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
--TODO add wrapping elements
|
2015-03-15 04:17:18 +01:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
local target = grect.get_in_direction(dir, cltbl, c)
|
|
|
|
|
|
|
|
-- If we found a client to focus, then do it.
|
|
|
|
if target then
|
2015-03-15 04:17:18 +01:00
|
|
|
local cl = cltbl[target]
|
|
|
|
if cl and cl.is_screen then
|
2016-12-07 01:53:02 +01:00
|
|
|
target_client = nil
|
|
|
|
capi.mouse.screen = capi.screen[cl.screen]
|
2015-02-24 16:27:57 +01:00
|
|
|
else
|
2016-12-07 01:53:02 +01:00
|
|
|
local prev = target_client
|
|
|
|
|
|
|
|
target_client = cltbl[((not cl and #cltbl == 1) and 1 or target)]
|
|
|
|
|
|
|
|
--FIXME when prev isn't set, it doesn't work
|
|
|
|
if prev and swap and target_client.on_swap then
|
|
|
|
target_client.on_swap(prev)
|
|
|
|
elseif target_client.on_select then
|
|
|
|
target_client.on_select()
|
|
|
|
end
|
2015-02-24 16:28:20 +01:00
|
|
|
end
|
2013-06-03 23:22:41 +02:00
|
|
|
end
|
2016-12-07 01:53:02 +01:00
|
|
|
display_wiboxes(cltbl)
|
|
|
|
|
2013-06-03 23:22:41 +02:00
|
|
|
end
|
2013-06-04 05:00:09 +02:00
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
function module.global_bydirection(dir, c,swap,max)
|
2016-12-07 01:53:02 +01:00
|
|
|
bydirection(dir, c or target_client or capi.client.focus, swap,max)
|
2014-05-08 05:51:28 +02:00
|
|
|
end
|
|
|
|
|
2014-05-08 07:53:57 +02:00
|
|
|
function module._global_bydirection_key(mod,key,event,direction,is_swap,is_max)
|
2016-12-07 01:53:02 +01:00
|
|
|
bydirection(direction,target_client or capi.client.focus,is_swap,is_max)
|
|
|
|
|
|
|
|
return true
|
2014-05-08 07:53:57 +02:00
|
|
|
end
|
2014-05-08 05:51:28 +02:00
|
|
|
|
2014-05-10 06:42:59 +02:00
|
|
|
function module.display(mod,key,event,direction,is_swap,is_max)
|
2016-12-07 01:53:02 +01:00
|
|
|
-- -- local c = capi.client.focus
|
|
|
|
-- -- local cltbl = max and floating_clients() or client.tiled()
|
|
|
|
-- --
|
|
|
|
-- -- -- Sometime, there is no focussed clients
|
|
|
|
-- -- c = c or cltbl[1]
|
|
|
|
-- --
|
|
|
|
-- -- -- If there is still no accessible clients, there is nothing to display
|
|
|
|
-- -- if not c then return end
|
|
|
|
-- --
|
|
|
|
-- -- display_wiboxes(cltbl)
|
|
|
|
end
|
2014-10-04 08:53:01 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
function module._quit()
|
|
|
|
if not wiboxes then return end
|
2014-10-04 08:53:01 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
for _,v in ipairs({"left","right","up","down","center"}) do
|
|
|
|
wiboxes[v].visible = false
|
|
|
|
end
|
2014-10-04 08:53:01 +02:00
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
if target_client then
|
|
|
|
if target_client.on_exit then
|
|
|
|
target_client.on_exit()
|
|
|
|
end
|
|
|
|
|
|
|
|
target_client = nil
|
|
|
|
current_map:hide()
|
|
|
|
current_map = nil
|
|
|
|
end
|
2014-05-10 06:42:59 +02:00
|
|
|
|
2013-06-04 05:00:09 +02:00
|
|
|
end
|
|
|
|
|
2016-12-07 01:53:02 +01:00
|
|
|
return module
|
2016-06-13 05:31:00 +02:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|