View difference between Paste ID: MiSDULf2 and 5V6PecHK
SHOW: | | - or go back to the newest paste.
1
---------------------------------------------------------------------------
2
-- @author Donald Ephraim Curtis <[email protected]>
3
-- @author Julien Danjou <[email protected]>
4
-- @copyright 2009 Donald Ephraim Curtis
5
-- @copyright 2008 Julien Danjou
6-
-- @release v3.4.13
6+
-- @release v3.5.1
7
---------------------------------------------------------------------------
8
9
-- Grab environment we need
10
local ipairs = ipairs
11
local math = math
12
local tonumber = tonumber
13
local beautiful = beautiful
14
local tag = require("awful.tag")
15
16
--- Tiled layouts module for awful
17-
module("awful.layout.suit.tile")
17+
-- awful.layout.suit.tile
18
local tile = {}
19
20
local function tile_group(cls, wa, orientation, fact, group)
21
    local padding = tonumber(beautiful.padding)
22
    if padding == nil then
23
        padding = 0
24
    end
25
    -- get our orientation right
26
    local height = "height"
27
    local width = "width"
28
    local x = "x"
29
    local y = "y"
30
    if orientation == "top" or orientation == "bottom" then
31
        height = "width"
32
        width = "height"
33
        x = "y"
34
        y = "x"
35
    end
36
37-
    available = wa[width] - (group.coord - wa[x])
37+
38
    local available = wa[width] - (group.coord - wa[x])
39
40
    -- find our total values
41
    local total_fact = 0
42
    local min_fact = 1
43
    local size = group.size
44
    for c = group.first,group.last do
45
        -- determine the width/height based on the size_hint
46
        local i = c - group.first +1
47
        local size_hints = cls[c].size_hints
48
        local size_hint = size_hints["min_"..width] or size_hints["base_"..width] or 0
49
        size_hint = size_hint + cls[c].border_width*2
50
        size = math.max(size_hint, size)
51
52
        -- calculate the height
53
        if not fact[i] then
54
            fact[i] = min_fact
55
        else
56
            min_fact = math.min(fact[i],min_fact)
57
        end
58
        total_fact = total_fact + fact[i]
59
    end
60
    size = math.min(size, available)
61
62
    local coord = wa[y]
63
    local geom = {}
64
    local used_size = 0
65
    local unused = wa[height]
66
    for c = group.first,group.last do
67-
        geom[width] = size - padding * (group.first == 1 and 2 or 1)
67+
	local i = c - group.first +1
68-
        geom[height] = math.floor(unused * fact[i] / total_fact) - padding * 2
68+
	geom[width] = size - cls[c].border_width * 2
69-
        geom[x] = group.coord + ((orientation ~= "right" or group.first == 1) and padding or 0)
69+
	geom[height] = math.floor(unused * fact[i] / total_fact) - cls[c].border_width * 2
70-
        geom[y] = coord + padding
70+
	geom[x] = group.coord
71-
        geom = cls[c]:geometry(geom)
71+
	geom[y] = coord
72-
        coord = coord + geom[height] + padding
72+
	coord = coord + geom[height] + cls[c].border_width * 2
73-
        unused = unused - geom[height] - padding
73+
	unused = unused - geom[height] - cls[c].border_width * 2
74-
        total_fact = total_fact - fact[i]
74+
	total_fact = total_fact - fact[i]
75-
        used_size = math.max(used_size, size)
75+
	used_size = math.max(used_size, geom[width] + cls[c].border_width * 2)
76
77
	if padding > 0 then
78-
    return used_size
78+
	    top = false
79
	    left = false
80
81-
local function tile(param, orientation)
81+
	    if geom[y] == wa[y] then
82
		top = true
83
	    end
84
85
	    if geom[x] == 0 or geom[x] == wa[x] then
86
		left = true
87
	    end
88
89
	    if top then
90
		geom[height] = geom[height] - 2 * padding
91
		geom[y] = geom[y] + padding
92
	    else
93
		geom[height] = geom[height] - padding
94
	    end
95
96
	    if left then
97
		geom[width] = geom[width] - 2 * padding
98
		geom[x] = geom[x] + padding
99
	    else
100
		geom[width] = geom[width] - padding
101
	    end
102
	end
103
104
	geom = cls[c]:geometry(geom)
105
     end
106
107
     return used_size
108
end
109
110
local function do_tile(param, orientation)
111
    local t = tag.selected(param.screen)
112
    orientation = orientation or "right"
113
114
    -- this handles are different orientations
115
    local height = "height"
116
    local width = "width"
117
    local x = "x"
118
    local y = "y"
119
    if orientation == "top" or orientation == "bottom" then
120
        height = "width"
121
        width = "height"
122
        x = "y"
123
        y = "x"
124
    end
125
126
    local cls = param.clients
127
    local nmaster = math.min(tag.getnmaster(t), #cls)
128
    local nother = math.max(#cls - nmaster,0)
129-
            coord = coord + tile_group(cls, wa, orientation, data[0], { first = 1, last = nmaster, coord = coord, size = size })
129+
130
    local mwfact = tag.getmwfact(t)
131
    local wa = param.workarea
132
    local ncol = tag.getncol(t)
133
134
    local data = tag.getdata(t).windowfact
135
136
    if not data then
137
        data = {}
138
        tag.getdata(t).windowfact = data
139
    end
140
141
    local coord = wa[x]
142
    local place_master = true
143
    if orientation == "left" or orientation == "top" then
144
        -- if we are on the left or top we need to render the other windows first
145
        place_master = false
146
    end
147
148
    -- this was easier than writing functions because there is a lot of data we need
149
    for d = 1,2 do
150
        if place_master and nmaster > 0 then
151
            local size = wa[width]
152
            if nother > 0 then
153
                size = math.min(wa[width] * mwfact, wa[width] - (coord - wa[x]))
154
            end
155
            if not data[0] then
156
                data[0] = {}
157-
right = {}
157+
158-
right.name = "tile"
158+
            coord = coord + tile_group(cls, wa, orientation, data[0], {first=1, last=nmaster, coord = coord, size = size})
159-
right.arrange = tile
159+
160
161
        if not place_master and nother > 0 then
162
            local last = nmaster
163-
left = {}
163+
164-
left.name = "tileleft"
164+
165-
function left.arrange(p)
165+
166-
    return tile(p, "left")
166+
167
                wasize = wa[width] - wa[width]*mwfact
168
            end
169
            for i = 1,ncol do
170
                -- Try to get equal width among remaining columns
171-
bottom = {}
171+
172-
bottom.name = "tilebottom"
172+
173-
function bottom.arrange(p)
173+
174-
    return tile(p, "bottom")
174+
175
                if not data[i] then
176
                    data[i] = {}
177
                end
178
                coord = coord + tile_group(cls, wa, orientation, data[i], { first = first, last = last, coord = coord, size = size })
179-
top = {}
179+
180-
top.name = "tiletop"
180+
181-
function top.arrange(p)
181+
182-
    return tile(p, "top")
182+
183
184
end
185-
arrange = right.arrange
185+
186-
name = right.name
186+
tile.right = {}
187
tile.right.name = "tile"
188
tile.right.arrange = do_tile
189
190
--- The main tile algo, on left.
191
-- @param screen The screen number to tile.
192
tile.left = {}
193
tile.left.name = "tileleft"
194
function tile.left.arrange(p)
195
    return do_tile(p, "left")
196
end
197
198
--- The main tile algo, on bottom.
199
-- @param screen The screen number to tile.
200
tile.bottom = {}
201
tile.bottom.name = "tilebottom"
202
function tile.bottom.arrange(p)
203
    return do_tile(p, "bottom")
204
end
205
206
--- The main tile algo, on top.
207
-- @param screen The screen number to tile.
208
tile.top = {}
209
tile.top.name = "tiletop"
210
function tile.top.arrange(p)
211
    return do_tile(p, "top")
212
end
213
214
tile.arrange = tile.right.arrange
215
tile.name = tile.right.name
216
217
return tile