Commit 2e09ab6b2c74b00ff656cd8e6582b3cca030cd78
1 parent
bfc657d496
Exists in
master
dynamic termfair positioning
Showing 1 changed file with 7 additions and 0 deletions Inline Diff
awesome/awesome/layouts/termfair.lua
View file @
2e09ab6
-- Grab environment. | 1 | 1 | -- Grab environment. | |
local tag = require("awful.tag") | 2 | 2 | local tag = require("awful.tag") | |
local beautiful = require("beautiful") | 3 | 3 | local beautiful = require("beautiful") | |
local math = math | 4 | 4 | local math = math | |
local tonumber = tonumber | 5 | 5 | local tonumber = tonumber | |
6 | 6 | |||
module("vain.layout.termfair") | 7 | 7 | module("vain.layout.termfair") | |
8 | 8 | |||
nmaster = 3 | 9 | 9 | nmaster = 3 | |
ncol = 2 | 10 | 10 | ncol = 2 | |
11 | 11 | |||
name = "termfair" | 12 | 12 | name = "termfair" | |
13 | 13 | |||
function arrange(p) | 14 | 14 | function arrange(p) | |
15 | 15 | |||
-- Layout with fixed number of vertical columns (read from nmaster). | 16 | 16 | -- Layout with fixed number of vertical columns (read from nmaster). | |
-- New windows align from left to right. When a row is full, a now | 17 | 17 | -- New windows align from left to right. When a row is full, a now | |
-- one above it is created. Like this: | 18 | 18 | -- one above it is created. Like this: | |
19 | 19 | |||
-- (1) (2) (3) | 20 | 20 | -- (1) (2) (3) | |
-- +---+---+---+ +---+---+---+ +---+---+---+ | 21 | 21 | -- +---+---+---+ +---+---+---+ +---+---+---+ | |
-- | | | | | | | | | | | | | 22 | 22 | -- | | | | | | | | | | | | | |
-- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | -> | 23 | 23 | -- | 1 | | | -> | 2 | 1 | | -> | 3 | 2 | 1 | -> | |
-- | | | | | | | | | | | | | 24 | 24 | -- | | | | | | | | | | | | | |
-- +---+---+---+ +---+---+---+ +---+---+---+ | 25 | 25 | -- +---+---+---+ +---+---+---+ +---+---+---+ | |
26 | 26 | |||
-- (4) (5) (6) | 27 | 27 | -- (4) (5) (6) | |
-- +---+---+---+ +---+---+---+ +---+---+---+ | 28 | 28 | -- +---+---+---+ +---+---+---+ +---+---+---+ | |
-- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 | | 29 | 29 | -- | 4 | | | | 5 | 4 | | | 6 | 5 | 4 | | |
-- +---+---+---+ -> +---+---+---+ -> +---+---+---+ | 30 | 30 | -- +---+---+---+ -> +---+---+---+ -> +---+---+---+ | |
-- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | | 31 | 31 | -- | 3 | 2 | 1 | | 3 | 2 | 1 | | 3 | 2 | 1 | | |
-- +---+---+---+ +---+---+---+ +---+---+---+ | 32 | 32 | -- +---+---+---+ +---+---+---+ +---+---+---+ | |
33 | 33 | |||
-- A useless gap (like the dwm patch) can be defined with | 34 | 34 | -- A useless gap (like the dwm patch) can be defined with | |
-- beautiful.useless_gap_width. | 35 | 35 | -- beautiful.useless_gap_width. | |
local useless_gap = tonumber(beautiful.useless_gap_width) | 36 | 36 | local useless_gap = tonumber(beautiful.useless_gap_width) | |
if useless_gap == nil | 37 | 37 | if useless_gap == nil | |
then | 38 | 38 | then | |
useless_gap = 0 | 39 | 39 | useless_gap = 0 | |
end | 40 | 40 | end | |
41 | 41 | |||
-- Screen. | 42 | 42 | -- Screen. | |
local wa = p.workarea | 43 | 43 | local wa = p.workarea | |
local cls = p.clients | 44 | 44 | local cls = p.clients | |
45 | 45 | |||
-- How many vertical columns? Read from nmaster on the tag. | 46 | 46 | -- How many vertical columns? Read from nmaster on the tag. | |
--local t = tag.selected(p.screen) | 47 | 47 | --local t = tag.selected(p.screen) | |
--local num_x = tag.getnmaster(t) | 48 | 48 | --local num_x = tag.getnmaster(t) | |
local num_x = nmaster | 49 | 49 | local num_x = nmaster | |
50 | 50 | |||
-- Do at least "desired_y" rows. Read this from ncol. (Yes, I use a | 51 | 51 | -- Do at least "desired_y" rows. Read this from ncol. (Yes, I use a | |
-- *column* setting to set the number of *rows*. That's because | 52 | 52 | -- *column* setting to set the number of *rows*. That's because | |
-- num_x is the *master* setting -- it's the setting that's most | 53 | 53 | -- num_x is the *master* setting -- it's the setting that's most | |
-- important to me.) | 54 | 54 | -- important to me.) | |
--local desired_y = tag.getncol(t) | 55 | 55 | --local desired_y = tag.getncol(t) | |
local desired_y = ncol | 56 | 56 | local desired_y = ncol | |
57 | 57 | |||
58 | --dynamic positioning | |||
59 | if #cls < 4 | |||
60 | then | |||
61 | num_x = #cls | |||
62 | end | |||
63 | ||||
64 | ||||
if #cls > 0 | 58 | 65 | if #cls > 0 | |
then | 59 | 66 | then | |
local num_y = math.max(math.ceil(#cls / num_x), desired_y) | 60 | 67 | local num_y = math.max(math.ceil(#cls / num_x), desired_y) | |
local cur_num_x = num_x | 61 | 68 | local cur_num_x = num_x | |
local at_x = 0 | 62 | 69 | local at_x = 0 | |
local at_y = 0 | 63 | 70 | local at_y = 0 | |
local remaining_clients = #cls | 64 | 71 | local remaining_clients = #cls | |
local width = math.floor(wa.width / num_x) | 65 | 72 | local width = math.floor(wa.width / num_x) | |
local height = math.floor(wa.height / num_y) | 66 | 73 | local height = math.floor(wa.height / num_y) | |
67 | 74 | |||
-- We start the first row. Left-align by limiting the number of | 68 | 75 | -- We start the first row. Left-align by limiting the number of | |
-- available slots. | 69 | 76 | -- available slots. | |
if remaining_clients < num_x | 70 | 77 | if remaining_clients < num_x | |
then | 71 | 78 | then | |
cur_num_x = remaining_clients | 72 | 79 | cur_num_x = remaining_clients | |
end | 73 | 80 | end | |
74 | 81 | |||
-- Iterate in reversed order. | 75 | 82 | -- Iterate in reversed order. | |
for i = #cls,1,-1 | 76 | 83 | for i = #cls,1,-1 | |
do | 77 | 84 | do | |
-- Get x and y position. | 78 | 85 | -- Get x and y position. | |
local c = cls[i] | 79 | 86 | local c = cls[i] | |
local this_x = cur_num_x - at_x - 1 | 80 | 87 | local this_x = cur_num_x - at_x - 1 | |
local this_y = num_y - at_y - 1 | 81 | 88 | local this_y = num_y - at_y - 1 | |
82 | 89 | |||
-- Calc geometry. | 83 | 90 | -- Calc geometry. | |
local g = {} | 84 | 91 | local g = {} | |
if this_x == (num_x - 1) | 85 | 92 | if this_x == (num_x - 1) | |
then | 86 | 93 | then | |
g.width = wa.width - (num_x - 1) * width | 87 | 94 | g.width = wa.width - (num_x - 1) * width | |
else | 88 | 95 | else | |
g.width = width | 89 | 96 | g.width = width | |
end | 90 | 97 | end | |
if this_y == (num_y - 1) | 91 | 98 | if this_y == (num_y - 1) | |
then | 92 | 99 | then | |
g.height = wa.height - (num_y - 1) * height | 93 | 100 | g.height = wa.height - (num_y - 1) * height | |
else | 94 | 101 | else | |
g.height = height | 95 | 102 | g.height = height | |
end | 96 | 103 | end | |
g.x = wa.x + this_x * width | 97 | 104 | g.x = wa.x + this_x * width | |
g.y = wa.y + this_y * height | 98 | 105 | g.y = wa.y + this_y * height | |
if useless_gap > 0 | 99 | 106 | if useless_gap > 0 | |
then | 100 | 107 | then | |
-- Top and left clients are shrinked by two steps and | 101 | 108 | -- Top and left clients are shrinked by two steps and | |
-- get moved away from the border. Other clients just | 102 | 109 | -- get moved away from the border. Other clients just | |
-- get shrinked in one direction. | 103 | 110 | -- get shrinked in one direction. | |
if this_x == 0 | 104 | 111 | if this_x == 0 | |
then | 105 | 112 | then | |
g.width = g.width - 2 * useless_gap | 106 | 113 | g.width = g.width - 2 * useless_gap | |
g.x = g.x + useless_gap | 107 | 114 | g.x = g.x + useless_gap | |
else | 108 | 115 | else | |
g.width = g.width - useless_gap | 109 | 116 | g.width = g.width - useless_gap | |
end | 110 | 117 | end | |
111 | 118 | |||
if this_y == 0 | 112 | 119 | if this_y == 0 | |
then | 113 | 120 | then | |
g.height = g.height - 2 * useless_gap | 114 | 121 | g.height = g.height - 2 * useless_gap | |
g.y = g.y + useless_gap | 115 | 122 | g.y = g.y + useless_gap | |
else | 116 | 123 | else | |
g.height = g.height - useless_gap | 117 | 124 | g.height = g.height - useless_gap | |
end | 118 | 125 | end | |
end | 119 | 126 | end | |
c:geometry(g) | 120 | 127 | c:geometry(g) | |
remaining_clients = remaining_clients - 1 | 121 | 128 | remaining_clients = remaining_clients - 1 | |
122 | 129 |