Implement focus rotation past the screen first/last screen edges

This commit is contained in:
Emmanuel Lepage Vallee 2015-03-15 01:16:31 -04:00
parent 38d8824668
commit 03e45b8583
3 changed files with 62 additions and 28 deletions

View File

@ -15,6 +15,7 @@ local col_utils = require( "collision.util" )
local module = {}
local wiboxes,delta = nil,100
local edge = nil
---------------- Visual -----------------------
local function init()
@ -113,11 +114,36 @@ local function bydirection(dir, c, swap,max)
c:geometry((max and float_move_max or float_move)(dir,c))
display_wiboxes(nil,nil,float,swap,c)
else
if not edge then
local scrs =col_utils.get_ordered_screens()
local last_geo =capi.screen[scrs[#scrs]].geometry
edge = last_geo.x + last_geo.width
end
-- Get all clients rectangle
local cltbl,geomtbl,scrs = max and floating_clients() or client.tiled(),{},{}
local cltbl,geomtbl,scrs,roundr,roundl = max and floating_clients() or client.tiled(),{},{},{},{}
for i,cl in ipairs(cltbl) do
geomtbl[i] = cl:geometry()
local geo = cl:geometry()
geomtbl[i] = geo
scrs[cl.screen or 1] = true
if geo.x == 0 then
roundr[#roundr+1] = cl
elseif geo.x + geo.width >= edge -2 then
roundl[#roundl+1] = cl
end
end
--Add first client at the end to be able to rotate selection
for k,c in ipairs(roundr) do
local geo = c:geometry()
geomtbl[#geomtbl+1] = {x=edge,width=geo.width,y=geo.y,height=geo.height}
cltbl[#geomtbl] = c
end
for k,c in ipairs(roundl) do
local geo = c:geometry()
geomtbl[#geomtbl+1] = {x=-geo.width,width=geo.width,y=geo.y,height=geo.height}
cltbl[#geomtbl] = c
end
-- Add rectangles for empty screens too

View File

@ -9,6 +9,7 @@ local surface = require( "gears.surface" )
local pango = require( "lgi" ).Pango
local pangocairo = require( "lgi" ).PangoCairo
local mouse = require( "collision.mouse" )
local util = require( "collision.util" )
local module = {}
@ -22,31 +23,7 @@ local opss = nil
local last_clients = setmetatable({},{__mode="v"})
local last_clients_coords = {}
-- Screen order is not always geometrical, sort them
local function get_first_screen()
local ret = {}
for i=1,capi.screen.count() do
local geom = capi.screen[i].geometry
if #ret == 0 then
ret[1] = i
elseif geom.x < capi.screen[ret[1]].geometry.x then
table.insert(ret,1,i)
else
for j=#ret,1,-1 do
if geom.x > capi.screen[ret[j]].geometry.x then
table.insert(ret,j+1,i)
break
end
end
end
end
return ret
end
local screens,screens_inv = get_first_screen(),{}
for k,v in ipairs(screens) do
screens_inv[v] = k
end
local screens,screens_inv = util.get_ordered_screens()
local function current_screen(focus)
return (not focus) and capi.mouse.screen or (capi.client.focus and capi.client.focus.screen or capi.mouse.screen)
@ -112,7 +89,7 @@ end
local function select_screen(scr_index,move,old_screen)
if scr_index ~= old_screen then
local c = last_clients[scr_index]
if c and c:isvisible() then
if c and pcall(c:isvisible()) and c:isvisible() then
local geom = c:geometry()
if last_clients_coords[scr_index] and last_clients_coords[scr_index].client == c then
capi.mouse.coords(last_clients_coords[scr_index])

View File

@ -1,3 +1,4 @@
local capi = {screen = screen}
local math = math
local color = require( "gears.color" )
local beautiful = require( "beautiful" )
@ -72,5 +73,35 @@ function module.double_click(callback,delay)
end
end
-- Screen order is not always geometrical, sort them
local screens,screens_inv
function module.get_ordered_screens()
if screens then return screens,screens_inv end
screens = {}
for i=1,capi.screen.count() do
local geom = capi.screen[i].geometry
if #screens == 0 then
screens[1] = i
elseif geom.x < capi.screen[screens[1]].geometry.x then
table.insert(screens,1,i)
else
for j=#screens,1,-1 do
if geom.x > capi.screen[screens[j]].geometry.x then
table.insert(screens,j+1,i)
break
end
end
end
end
screens_inv = {}
for k,v in ipairs(screens) do
screens_inv[v] = k
end
return screens,screens_inv
end
return module
-- kate: space-indent on; indent-width 2; replace-tabs on;