forked from ashpie/simple-awesome
Make basic tiling work and move this module's code to a dedicated file
This commit is contained in:
parent
95e1567423
commit
ec08bfe121
72
rc.lua
72
rc.lua
@ -21,6 +21,9 @@ local hotkeys_popup = require("awful.hotkeys_popup")
|
||||
-- when client with a matching name is opened:
|
||||
require("awful.hotkeys_popup.keys")
|
||||
|
||||
-- Simple awesome
|
||||
local tiling = require("tiling")
|
||||
|
||||
|
||||
-- {{{ Error handling
|
||||
-- Check if awesome encountered an error during startup and fell back to
|
||||
@ -242,25 +245,6 @@ root.buttons(gears.table.join(
|
||||
))
|
||||
-- }}}
|
||||
|
||||
-- Tiling functions
|
||||
local leftGeo = function(parent)
|
||||
local f = awful.placement.scale
|
||||
+ awful.placement.left
|
||||
+ awful.placement['maximize_vertically']
|
||||
return f(client.focus, {honor_workarea=true, to_percent = 0.5, parent = parent})
|
||||
end
|
||||
local rightGeo = function(parent)
|
||||
local f = awful.placement.scale
|
||||
+ awful.placement.right
|
||||
+ awful.placement['maximize_vertically']
|
||||
return f(client.focus, {honor_workarea=true, to_percent = 0.5, parent = parent})
|
||||
end
|
||||
|
||||
local isTiled = function(client, geometry)
|
||||
naughty.notify({title="debug", description="h=" .. client.height .. "-" .. geometry.height .. ", x=" .. client.x .. "-" .. geometry.x .. ", y=" .. client.y .. "-" .. geometry.y })
|
||||
return client.height == geometry.height and client.x == geometry.x and client.y == geometry.y
|
||||
end
|
||||
|
||||
-- {{{ Key bindings
|
||||
globalkeys = gears.table.join(
|
||||
awful.key({ modkey, }, "s", hotkeys_popup.show_help,
|
||||
@ -270,42 +254,6 @@ globalkeys = gears.table.join(
|
||||
-- awful.key({ modkey, }, "Right", awful.tag.viewnext,
|
||||
-- {description = "view next", group = "tag"}),
|
||||
|
||||
-- tiling
|
||||
awful.key({modkey,}, "Right",
|
||||
function (c)
|
||||
local targetGeo = rightGeo(client.parent)
|
||||
if isTiled(client, targetGeo) then
|
||||
local newScreen = awful.screen.get_next_in_direction(client.parent, "right")
|
||||
client.geometry = leftGeo(newScreen)
|
||||
else
|
||||
client.geometry = targetGeo
|
||||
end
|
||||
end,
|
||||
{description = "Move right", group = "window_tiling"}
|
||||
),
|
||||
awful.key({modkey,}, "Left",
|
||||
function ()
|
||||
local targetGeo = leftGeo(client.parent)
|
||||
if isTiled(client, targetGeo) then
|
||||
local newScreen = awful.screen.get_next_in_direction(client.parent, "left")
|
||||
client.geometry = rightGeo(newScreen)
|
||||
else
|
||||
client.geometry = targetGeo
|
||||
end
|
||||
end,
|
||||
{description = "Move left", group = "window_tiling"}
|
||||
),
|
||||
awful.key({modkey,}, "Up",
|
||||
function ()
|
||||
local axis = 'vertically'
|
||||
local f = awful.placement.scale
|
||||
+ (axis and awful.placement['maximize'] or nil)
|
||||
client.geometry = f(client.focus, {honor_workarea=true, to_percent = 0.5})
|
||||
client.position = "maximized"
|
||||
end,
|
||||
{description = "Move left", group = "window_tiling"}
|
||||
),
|
||||
|
||||
|
||||
awful.key({ modkey, }, "Escape", awful.tag.history.restore,
|
||||
{description = "go back", group = "tag"}),
|
||||
@ -407,6 +355,20 @@ globalkeys = gears.table.join(
|
||||
)
|
||||
|
||||
clientkeys = gears.table.join(
|
||||
-- tiling
|
||||
awful.key({modkey,}, "Right",
|
||||
tiling.key.tileRight,
|
||||
{description = "Move right", group = "window_tiling"}
|
||||
),
|
||||
awful.key({modkey,}, "Left",
|
||||
tiling.key.tileLeft,
|
||||
{description = "Move left", group = "window_tiling"}
|
||||
),
|
||||
awful.key({modkey,}, "Up",
|
||||
tiling.key.maximize,
|
||||
{description = "Move left", group = "window_tiling"}
|
||||
),
|
||||
|
||||
awful.key({ modkey, }, "f",
|
||||
function (c)
|
||||
c.fullscreen = not c.fullscreen
|
||||
|
68
tiling.lua
Normal file
68
tiling.lua
Normal file
@ -0,0 +1,68 @@
|
||||
-- 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user