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