forked from ashpie/simple-awesome
68 lines
2.1 KiB
Lua
68 lines
2.1 KiB
Lua
-- Offers window tiling functionnality
|
|
|
|
local awful = require("awful")
|
|
|
|
-- Check if geometries are the same
|
|
local isTiled = function(c, geometry)
|
|
return c.height == geometry.height and c.x == geometry.x and c.y == geometry.y
|
|
end
|
|
|
|
-- Tile a window to the left
|
|
local tileToLeft = function(c)
|
|
local apply = awful.placement.scale
|
|
+ awful.placement.left
|
|
+ awful.placement['maximize_vertically']
|
|
return apply(c, {honor_workarea=true, to_percent = 0.5})
|
|
end
|
|
|
|
-- Tile a window to the right
|
|
local tileToRight = function(c)
|
|
local apply = awful.placement.scale
|
|
+ awful.placement.right
|
|
+ awful.placement['maximize_vertically']
|
|
return apply(c, {honor_workarea=true, to_percent = 0.5})
|
|
end
|
|
|
|
return {
|
|
key = {
|
|
tileRight = function (c)
|
|
local initialGeometry = {
|
|
x = c.x,
|
|
y = c.y,
|
|
width = c.width,
|
|
height = c.height
|
|
}
|
|
local newGeometry = tileToRight(c, c.screen)
|
|
if isTiled(initialGeometry, newGeometry) then
|
|
local newScreen = c.screen.get_next_in_direction(c.screen, "right")
|
|
if newScreen ~= nil then
|
|
c.screen = newScreen
|
|
tileToLeft(c)
|
|
end
|
|
end
|
|
end,
|
|
tileLeft = function (c)
|
|
local initialGeometry = {
|
|
x = c.x,
|
|
y = c.y,
|
|
width = c.width,
|
|
height = c.height
|
|
}
|
|
local newGeometry = tileToLeft(c, c.screen)
|
|
if isTiled(initialGeometry, newGeometry) then
|
|
local newScreen = c.screen.get_next_in_direction(c.screen, "left")
|
|
if newScreen ~= nil then
|
|
c.screen = newScreen
|
|
tileToRight(c)
|
|
end
|
|
end
|
|
end,
|
|
maximize = function (c)
|
|
local axis = 'vertically'
|
|
local f = awful.placement.scale
|
|
+ (axis and awful.placement['maximize'] or nil)
|
|
c.geometry = f(c.focus, {honor_workarea=true, to_percent = 0.5})
|
|
c.position = "maximized"
|
|
end
|
|
}
|
|
} |