Add support for switching mode and resizing tiled content

This commit is contained in:
Emmanuel Lepage Vallee 2014-05-10 00:42:59 -04:00
parent 99e8326fe5
commit a38e38d795
3 changed files with 56 additions and 25 deletions

View File

@ -5,6 +5,7 @@ local setmetatable = setmetatable
local ipairs = ipairs
local util = require( "awful.util" )
local client = require( "awful.client" )
local alayout = require( "awful.layout" )
local screen = require( "awful.screen" )
local wibox = require( "wibox" )
local cairo = require( "lgi" ).cairo
@ -86,7 +87,7 @@ local function init()
wiboxes["center"].shape_bounding = img._native
end
local function move_wiboxes(cltbl,geomtbl,float,swap,c)
local function display_wiboxes(cltbl,geomtbl,float,swap,c)
if not wiboxes then
init()
end
@ -124,11 +125,11 @@ end
local function bydirection(dir, c, swap,max)
if c then
local float = client.floating.get(c)
local float = client.floating.get(c) or alayout.get(c.screen) == alayout.suit.floating
-- Move the client if floating, swaping wont work anyway
if swap and float then
c:geometry((max and float_move_max or float_move)(dir,c))
move_wiboxes(nil,nil,float,swap,c)
display_wiboxes(nil,nil,float,swap,c)
else
-- Get all clients rectangle
local cltbl,geomtbl = max and floating_clients() or client.tiled(),{}
@ -144,7 +145,7 @@ local function bydirection(dir, c, swap,max)
else
c:swap(cltbl[target])
end
move_wiboxes(cltbl,geomtbl,float,swap,c)
display_wiboxes(cltbl,geomtbl,float,swap,c)
end
end
end
@ -159,6 +160,14 @@ function module._global_bydirection_key(mod,key,event,direction,is_swap,is_max)
return true
end
function module.display(mod,key,event,direction,is_swap,is_max)
local cltbl,geomtbl = max and floating_clients() or client.tiled(),{}
for i,cl in ipairs(cltbl) do
geomtbl[i] = cl:geometry()
end
display_wiboxes(cltbl,geomtbl,false,is_swap,capi.client.focus)
end
function module._quit()
for k,v in ipairs({"left","right","up","down","center"}) do
wiboxes[v].visible = false

View File

@ -14,6 +14,12 @@ local event_callback = {
resize = module._resize.resize
}
local start_callback = {
focus = module._focus.display,
move = module._focus.display,
resize = module._resize.display
}
local exit_callback = {
focus = module._focus._quit,
move = module._focus._quit,
@ -55,6 +61,11 @@ local function start_loop(is_swap,is_max)
elseif key == "Control_L" or key == "Control_R" then
is_max = event == "press"
return true
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)
return true
end
return exit_loop()

View File

@ -69,6 +69,7 @@ local function create_indicators()
end
end
-- Resize using the mouse
local placement_f = {
left = function(g) return {x = g.x , y = g.y + g.height/2 } end,
top_left = function(g) return {x = g.x , y = g.y } end,
@ -80,23 +81,22 @@ local placement_f = {
bottom = function(g) return {x = g.x + g.width/2 , y = g.y+g.height } end,
}
local resize_f = {
right = function(c,delta) return {width=c:geometry().width+100} end,
left = function(c,delta) return {width=c:geometry().width-100} end,
up = function(c,delta) return {width=c:geometry().height-100} end,
down = function(c,delta) return {width=c:geometry().height+100} end
}
local resize_f_alt = {
right = function(c,delta) return {width=c:geometry().width+100} end,
left = function(c,delta) return {width=c:geometry().width-100} end,
up = function(c,delta) return {width=c:geometry().height-100} end,
down = function(c,delta) return {width=c:geometry().height+100} end
}
-- Resize floating using the keyboard
local r_orientation = { right = "width", left = "width", up = "height", down = "height" }
local r_direction = { right = "x", left = "x", up = "y", down = "y" }
local r_sign = { right = 1, left = -1, up = -1, down = 1 }
local r_direction = { right = "x" , left = "x" , up = "y" , down = "y" }
local r_sign = { right = 1 , left = -1 , up = -1 , down = 1 }
-- Resize tiled using the keyboard
local layouts_all = {
[awful.layout.suit.floating] = { right = "" },
[awful.layout.suit.tile] = { right = {mwfact= 0.05}, left = {mwfact=-0.05}, up ={wfact=-0.1 }, down = {wfact = 0.1 } },
[awful.layout.suit.tile.left] = { right = {mwfact=-0.05}, left = {mwfact= 0.05}, up ={wfact= 0.1 }, down = {wfact =-0.1 } },
[awful.layout.suit.tile.bottom] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact=-0.05}, down = {mwfact= 0.05} },
[awful.layout.suit.tile.top] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
[awful.layout.suit.spiral] = { right = {wfact=-0.1 }, left = {wfact= 0.1 }, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
[awful.layout.suit.magnifier] = { right = {mwfact= 0.05}, left = {mwfact=-0.05}, up ={mwfact= 0.05}, down = {mwfact=-0.05} },
-- The other layouts cannot be resized using variables
}
function module.hide()
for k,v in ipairs(values) do indicators[v].visible = false end
@ -126,15 +126,26 @@ function module.display(c,toggle)
end
function module.resize(mod,key,event,direction,is_swap,is_max)
if resize_f[direction] then
local new_geo = capi.client.focus:geometry()
local c = capi.client.focus
if not c then return true end
local lay = awful.layout.get(c.screen)
if awful.client.floating.get(c) or lay == awful.layout.suit.floating then
local new_geo = c:geometry()
new_geo[r_orientation[direction]] = new_geo[r_orientation[direction]] + r_sign[direction]*100*(is_swap and -1 or 1)
if is_swap then
new_geo[r_direction[direction]] = new_geo[r_direction[direction]] + r_sign[direction]*100
new_geo[r_direction[direction]] = new_geo[r_direction[direction]] + r_sign[direction]*100
end
c:geometry(new_geo)
elseif layouts_all[lay] then
local ret = layouts_all[lay][direction]
if ret.mwfact then
awful.tag.incmwfact(ret.mwfact)
end
if ret.wfact then
awful.client.incwfact(ret.wfact,c)
end
capi.client.focus:geometry(new_geo)
return true
end
return true
end
return module