diff --git a/rc.lua b/rc.lua index 90d2964..77b960f 100644 --- a/rc.lua +++ b/rc.lua @@ -370,7 +370,7 @@ clientkeys = gears.table.join( {description = "Move left", group = "window_tiling"} ), awful.key({modkey,}, "Up", - tiling.key.maximize, + tiling.key.toggleMaximized, {description = "Move left", group = "window_tiling"} ), diff --git a/tiling.lua b/tiling.lua index 0821d8c..b4f18b9 100644 --- a/tiling.lua +++ b/tiling.lua @@ -2,67 +2,66 @@ 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 -local isTiled = function(c, geometry) - return c.height == geometry.height and c.x == geometry.x and c.y == geometry.y +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 --- 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}) +-- 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 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 + c.maximized = true + if not applyTile(c, rightTileGeometry) then local newScreen = c.screen.get_next_in_direction(c.screen, "right") if newScreen ~= nil then c.screen = newScreen - tileToLeft(c) + applyTile(c, leftTileGeometry) 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 + c.maximized = true + if not applyTile(c, leftTileGeometry) then local newScreen = c.screen.get_next_in_direction(c.screen, "left") if newScreen ~= nil then c.screen = newScreen - tileToRight(c) + applyTile(c, rightTileGeometry) 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" + toggleMaximized = function (c) + if not c.maximized then + c.maximized = true + else + if not applyTile(c, maximizedTileGeometry) then + c.maximized = false + end + end end } } \ No newline at end of file