forked from JamesWilmot/AwesomeWMColumnsLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolumns.lua
More file actions
177 lines (148 loc) · 4.25 KB
/
columns.lua
File metadata and controls
177 lines (148 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---------------------------------------------------------------------------
-- @author James Wilmot <djameswilmot2000@gmail.com>
-- @copyright 2014 James Wilmot
---------------------------------------------------------------------------
local ipairs = ipairs
local client = require("awful.client")
local math = math
local naughty = require("naughty")
local beautiful = require("beautiful")
--local write = io.stderr:write
local io = io
module("awful.layout.suit.columns")
-- stuff for debugging
function dbg(vars)
local text = ""
for i=1, #vars do text = text .. vars[i] .. " | " end
naughty.notify({ text = text, timeout = 5 })
end
function log_dbg_heading(heading)
io.stderr:write("\n".."*** "..heading.." ***".."\n")
end
function log_dbg_var(msg, var, tabs)
local text = ""
for i=1, tabs do text = "\t"..text end
text = text..msg.." : "..var.."\n"
io.stderr:write(text)
end
function log_dbg_message(msg, tabs)
local text = ""
for i=1, tabs do text = "\t"..text end
text = text..msg.."\n"
io.stderr:write(text)
end
local function cols_arrange(p, cols)
-- globals for geometry strings
x = "x"
y = "y"
height = "height"
width = "width"
-- screen context:
-- number of clients, clients,
-- screen work area
local wa = p.workarea
local cls = p.clients
local n = #cls
-- for few clients
-- want to make best use of
-- screen real estate
-- number of cols is then number of clients
if n <= cols then
cols = n
end
-- column book keeping
-- how many clients per column
-- how many clients that have been
-- arranged in columns
local n_cls_col = 0
local cls_arranged = 0
local col_cls = {}
local col_geom = {}
col_geom[width] = math.ceil(wa[width]/cols) - ( cols * beautiful.border_width )
col_geom[height] = wa[height]
col_geom[x] = wa[x]
col_geom[y] = wa[y]
--notify("test issue")
n_cls_col = math.floor(n/cols)
local start = 1
local finish = n_cls_col
local cls_arranged = 0
local cls_not_arranged = 0
-- iterate over columns
-- arranging each column
for col=1,cols,1 do
-- get clients for column
cols_cls = table_slice(cls,start,finish)
-- arrange single column
arrange_column(cols_cls, col_geom)
-- move x over for new column
col_geom[x] = col_geom[x] + col_geom[width]
-- tally clients arranged
-- determine clients not arranged
cls_arranged = n_cls_col + cls_arranged
cls_not_arranged = n - cls_arranged
-- algorithm for next column
local cols_left = cols - col
local spare_cls = cls_not_arranged - cols_left*n_cls_col
if spare_cls == cols_left then
n_cls_col = n_cls_col + 1
end
-- increment indices
start = finish + 1
finish = finish + n_cls_col
end
end
function arrange_column(clients, col_geom)
local geom = {}
local n = #clients
-- all clients in a column:
-- same width and x position
geom[width] = col_geom[width]
geom[x] = col_geom[x]
-- each client in column
-- is same height
geom[height] = math.floor(col_geom[height]/n)
geom[y] = col_geom[y]
for k, c in ipairs(clients) do
c:geometry(geom)
--http://tychoish.com/rhizome/window-sizes-in-tiling-window-managers/
c.size_hints_honor = false
geom[y] = geom[height] + geom[y]
end
end
-- given a table: values
-- return subtable between
-- indices start and finish
--
-- Source: http://snippets.luacode.org/?p=snippets/Table_Slice_116
function table_slice(values, start, finish)
local res = {}
local n = #values
-- default values for range
start = start or 1
finish = finish or n
if finish < 0 then
finish = n + finish + 1
elseif finish > n then
finish = n
end
if start < 1 or start > n then
return {}
end
local k = 1
for i = start,finish do
res[k] = values[i]
k = k + 1
end
return res
end
two = {}
two.name = "twocols"
function two.arrange(p)
return cols_arrange(p, 2)
end
three = {}
three.name = "threecols"
function three.arrange(p)
return cols_arrange(p, 3)
end