Make maximization compatible with tiling & add toggle maximization

This commit is contained in:
Alice Gaudon 2019-07-23 15:06:40 +02:00
parent 3ae20fda42
commit cf390176f1
2 changed files with 40 additions and 41 deletions

2
rc.lua
View File

@ -370,7 +370,7 @@ clientkeys = gears.table.join(
{description = "Move left", group = "window_tiling"} {description = "Move left", group = "window_tiling"}
), ),
awful.key({modkey,}, "Up", awful.key({modkey,}, "Up",
tiling.key.maximize, tiling.key.toggleMaximized,
{description = "Move left", group = "window_tiling"} {description = "Move left", group = "window_tiling"}
), ),

View File

@ -2,67 +2,66 @@
local awful = require("awful") local awful = require("awful")
-- Check if geometries are the same -- Placements
local isTiled = function(c, geometry) local leftTileGeometry = awful.placement.scale
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.left
+ awful.placement['maximize_vertically'] + awful.placement['maximize_vertically']
return apply(c, {honor_workarea=true, to_percent = 0.5}) local rightTileGeometry = awful.placement.scale
end
-- Tile a window to the right
local tileToRight = function(c)
local apply = awful.placement.scale
+ awful.placement.right + awful.placement.right
+ awful.placement['maximize_vertically'] + awful.placement['maximize_vertically']
return apply(c, {honor_workarea=true, to_percent = 0.5}) local maximizedTileGeometry = awful.placement.scale
+ awful.placement['maximize']
-- Check if geometries are the same
local geometryEquals = function(geo1, geo2)
return geo1.width == geo2.width and geo1.height == geo2.height and
geo1.x == geo2.x and geo1.y == geo2.y
end
-- Try to apply a tile placement to a client
-- return false if it changed nothing
local applyTile = function(c, geometry)
local initialGeometry = {
x = c.x,
y = c.y,
width = c.width,
height = c.height
}
local newGeometry = geometry(c, {honor_workarea=true, to_percent = 0.5})
return not geometryEquals(initialGeometry, newGeometry)
end end
return { return {
key = { key = {
tileRight = function (c) tileRight = function (c)
local initialGeometry = { c.maximized = true
x = c.x, if not applyTile(c, rightTileGeometry) then
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") local newScreen = c.screen.get_next_in_direction(c.screen, "right")
if newScreen ~= nil then if newScreen ~= nil then
c.screen = newScreen c.screen = newScreen
tileToLeft(c) applyTile(c, leftTileGeometry)
end end
end end
end, end,
tileLeft = function (c) tileLeft = function (c)
local initialGeometry = { c.maximized = true
x = c.x, if not applyTile(c, leftTileGeometry) then
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") local newScreen = c.screen.get_next_in_direction(c.screen, "left")
if newScreen ~= nil then if newScreen ~= nil then
c.screen = newScreen c.screen = newScreen
tileToRight(c) applyTile(c, rightTileGeometry)
end end
end end
end, end,
maximize = function (c) toggleMaximized = function (c)
local axis = 'vertically' if not c.maximized then
local f = awful.placement.scale c.maximized = true
+ (axis and awful.placement['maximize'] or nil) else
c.geometry = f(c.focus, {honor_workarea=true, to_percent = 0.5}) if not applyTile(c, maximizedTileGeometry) then
c.position = "maximized" c.maximized = false
end
end
end end
} }
} }