]> git.madduck.net Git - etc/awesome.git/blob - layout/uselesstile.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Window border width issue fixes in uselesstile
[etc/awesome.git] / layout / uselesstile.lua
1
2 --[[
3
4      Licensed under GNU General Public License v2
5       * (c) 2014       projektile
6       * (c) 2013       Luke Bonham
7       * (c) 2009       Donald Ephraim Curtis
8       * (c) 2008       Julien Danjolu
9
10 --]]
11
12 local tag       = require("awful.tag")
13 local beautiful = require("beautiful")
14 local ipairs    = ipairs
15 local math      = { floor = math.floor,
16                     max   = math.max,
17                     min   = math.min }
18 local tonumber  = tonumber
19
20 local uselesstile = {}
21
22 local function tile_group(cls, wa, orientation, fact, group, gap)
23
24     -- Themes border width requires an offset
25     local bw = tonumber(beautiful.border_width) or 0
26
27     -- get our orientation right
28     local height = "height"
29     local width = "width"
30     local x = "x"
31     local y = "y"
32     if orientation == "top" or orientation == "bottom" then
33         height = "width"
34         width = "height"
35         x = "y"
36         y = "x"
37     end
38
39     -- make this more generic (not just width)
40     --if for top
41     available = wa[width] - (group.coord - wa[x]) -- it's truly not here
42
43     -- find our total values
44     local total_fact = 0
45     local min_fact = 1
46     local size = group.size
47     for c = group.first,group.last do
48         -- determine the width/height based on the size_hint
49         local i = c - group.first +1
50         local size_hints = cls[c].size_hints
51         local size_hint = size_hints["min_"..width] or size_hints["base_"..width] or 0
52         size_hint = size_hint + cls[c].border_width*2
53         size = math.max(size_hint, size)
54
55         -- calculate the height
56         if not fact[i] then
57             fact[i] = min_fact
58         else
59             min_fact = math.min(fact[i],min_fact)
60         end
61         total_fact = total_fact + fact[i]
62     end
63     size = math.min(size, available)
64     local coord = wa[y]
65     local geom = {}
66     local used_size = 0
67     local unused = wa[height]
68     local stat_coord = wa[x]
69     --stat_coord = size
70     for c = group.first,group.last do
71         local i = c - group.first +1
72         geom[width] = size - (bw * 2)
73         geom[height] = math.floor(unused * fact[i] / total_fact) - (bw * 2)
74         geom[x] = group.coord
75         geom[y] = coord
76
77         coord = coord + geom[height] + 2 * bw
78         unused = unused - geom[height] - 2 * bw
79         total_fact = total_fact - fact[i]
80         used_size = math.max(used_size, geom[width] + 2 * bw)
81
82         -- Useless gap correction
83         geom.width = geom.width - gap
84         geom.height = geom.height - gap
85
86         geom = cls[c]:geometry(geom)
87     end
88
89     return used_size
90 end
91
92 local function tile(param, orientation)
93     local t = tag.selected(param.screen)
94     orientation = orientation or "right"
95
96     -- A useless gap (like the dwm patch) can be defined with
97     -- beautiful.useless_gap_width .
98     local useless_gap = tonumber(beautiful.useless_gap_width) or 0
99     if useless_gap < 0 then useless_gap = 0 end
100
101     -- A global border can be defined with
102     -- beautiful.global_border_width
103     local global_border = tonumber(beautiful.global_border_width) or 0
104     if global_border < 0 then global_border = 0 end
105
106     -- this handles are different orientations
107     local height = "height"
108     local width = "width"
109     local x = "x"
110     local y = "y"
111     if orientation == "top" or orientation == "bottom" then
112         height = "width"
113         width = "height"
114         x = "y"
115         y = "x"
116     end
117
118     local cls = param.clients
119     local nmaster = math.min(tag.getnmaster(t), #cls)
120     local nother = math.max(#cls - nmaster,0)
121
122     local mwfact = tag.getmwfact(t)
123     local wa = param.workarea
124     local ncol = tag.getncol(t)
125
126     -- Workarea size correction
127     wa.height = wa.height - 2 * global_border - useless_gap
128     wa.width  = wa.width -  2 * global_border - useless_gap
129     wa.x = wa.x + useless_gap + global_border
130     wa.y = wa.y + useless_gap + global_border
131
132     local data = tag.getdata(t).windowfact
133
134     if not data then
135         data = {}
136         tag.getdata(t).windowfact = data
137     end
138
139     local coord = wa[x]
140     local place_master = true
141     if orientation == "left" or orientation == "top" then
142         -- if we are on the left or top we need to render the other windows first
143         place_master = false
144     end
145
146     -- this was easier than writing functions because there is a lot of data we need
147     for d = 1,2 do
148         if place_master and nmaster > 0 then
149             local size = wa[width]
150             if nother > 0 then
151                 size = math.min(wa[width] * mwfact, wa[width] - (coord - wa[x]))
152             end
153             if not data[0] then
154                 data[0] = {}
155             end
156             coord = coord + tile_group(cls, wa, orientation, data[0], {first=1, last=nmaster, coord = coord, size = size}, useless_gap)
157         end
158
159         if not place_master and nother > 0 then
160             local last = nmaster
161
162             -- we have to modify the work area size to consider left and top views
163             local wasize = wa[width]
164             if nmaster > 0 and (orientation == "left" or orientation == "top") then
165                 wasize = wa[width] - wa[width]*mwfact
166             end
167             for i = 1,ncol do
168                 -- Try to get equal width among remaining columns
169                 local size = math.min((wasize - (coord - wa[x]))  / (ncol - i + 1)) --+ (global_border/(ncol))/(ncol+i^2)
170                 local first = last + 1
171                 last = last + math.floor((#cls - last)/(ncol - i + 1))
172                 -- tile the column and update our current x coordinate
173                 if not data[i] then
174                     data[i] = {}
175                 end
176                 coord = coord + tile_group(cls, wa, orientation, data[i], { first = first, last = last, coord = coord, size = size }, useless_gap)
177             end
178         end
179         place_master = not place_master
180     end
181
182 end
183
184 uselesstile.right = {}
185 uselesstile.right.name = "uselesstile"
186 uselesstile.right.arrange = tile
187
188 --- The main tile algo, on left.
189 -- @param screen The screen number to tile.
190 uselesstile.left = {}
191 uselesstile.left.name = "uselesstileleft"
192 function uselesstile.left.arrange(p)
193     return tile(p, "left")
194 end
195
196 --- The main tile algo, on bottom.
197 -- @param screen The screen number to tile.
198 uselesstile.bottom = {}
199 uselesstile.bottom.name = "uselesstilebottom"
200 function uselesstile.bottom.arrange(p)
201     return tile(p, "bottom")
202 end
203
204 --- The main tile algo, on top.
205 -- @param screen The screen number to tile.
206 uselesstile.top = {}
207 uselesstile.top.name = "uselesstiletop"
208 function uselesstile.top.arrange(p)
209     return tile(p, "top")
210 end
211
212 uselesstile.arrange = uselesstile.right.arrange
213 uselesstile.name = uselesstile.right.name
214
215 return uselesstile
216