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")
-- Placements
local leftTileGeometry = awful.placement.scale
+ awful.placement.left
+ awful.placement['maximize_vertically']
local rightTileGeometry = awful.placement.scale
+ awful.placement.right
+ awful.placement['maximize_vertically']
local maximizedTileGeometry = awful.placement.scale
+ awful.placement['maximize']
-- Check if geometries are the same -- Check if geometries are the same
local isTiled = function(c, geometry) local geometryEquals = function(geo1, geo2)
return c.height == geometry.height and c.x == geometry.x and c.y == geometry.y return geo1.width == geo2.width and geo1.height == geo2.height and
geo1.x == geo2.x and geo1.y == geo2.y
end end
-- Tile a window to the left -- Try to apply a tile placement to a client
local tileToLeft = function(c) -- return false if it changed nothing
local apply = awful.placement.scale local applyTile = function(c, geometry)
+ awful.placement.left local initialGeometry = {
+ awful.placement['maximize_vertically'] x = c.x,
return apply(c, {honor_workarea=true, to_percent = 0.5}) y = c.y,
end width = c.width,
height = c.height
-- Tile a window to the right }
local tileToRight = function(c) local newGeometry = geometry(c, {honor_workarea=true, to_percent = 0.5})
local apply = awful.placement.scale return not geometryEquals(initialGeometry, newGeometry)
+ awful.placement.right
+ awful.placement['maximize_vertically']
return apply(c, {honor_workarea=true, to_percent = 0.5})
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
} }
} }