Repository navigation
Expand file tree
/
Copy pathtag.lua.in
More file actions
292 lines (259 loc) · 7.13 KB
/
Copy pathtag.lua.in
File metadata and controls
292 lines (259 loc) · 7.13 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
---------------------------------------------------------------------------
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Julien Danjou
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
-- Grab environment we need
local util = require("awful.util")
local pairs = pairs
local ipairs = ipairs
local otable = otable
local capi =
{
hooks = hooks,
screen = screen,
mouse = mouse
}
local hooks = require("awful.hooks")
--- Tag module for awful
module("awful.tag")
-- Private data
local data = {}
data.history = {}
data.history.past = {}
data.history.current = {}
data.tags = otable()
-- History functions
history = {}
-- Compare 2 tables of tags.
-- @param a The first table.
-- @param b The second table of tags.
-- @return True if the tables are identical, false otherwise.
local function compare_select(a, b)
if not a or not b then
return false
end
-- Quick size comparison
if #a ~= #b then
return false
end
for ka, va in pairs(a) do
if b[ka] ~= va.selected then
return false
end
end
for kb, vb in pairs(b) do
if a[kb].selected ~= vb then
return false
end
end
return true
end
--- Update the tag history.
-- @param screen The screen number.
function history.update(screen)
local curtags = capi.screen[screen]:tags()
if not compare_select(curtags, data.history.current[screen]) then
data.history.past[screen] = data.history.current[screen]
data.history.current[screen] = {}
for k, v in ipairs(curtags) do
data.history.current[screen][k] = v.selected
end
end
end
-- Revert tag history.
-- @param screen The screen number.
function history.restore(screen)
local s = screen or capi.mouse.screen
local tags = capi.screen[s]:tags()
for k, t in pairs(tags) do
t.selected = data.history.past[s][k]
end
end
--- Return a table with all visible tags
-- @param s Screen number.
-- @return A table with all selected tags.
function selectedlist(s)
local screen = s or capi.mouse.screen
local tags = capi.screen[screen]:tags()
local vtags = {}
for i, t in pairs(tags) do
if t.selected then
vtags[#vtags + 1] = t
end
end
return vtags
end
--- Return only the first visible tag.
-- @param s Screen number.
function selected(s)
return selectedlist(s)[1]
end
--- Set master width factor.
-- @param mwfact Master width factor.
function setmwfact(mwfact, t)
local t = t or selected()
if mwfact >= 0 and mwfact <= 1 then
setproperty(t, "mwfact", mwfact)
capi.hooks.arrange()(t.screen)
end
end
--- Increase master width factor.
-- @param add Value to add to master width factor.
function incmwfact(add, t)
setmwfact(getmwfact(t) + add)
end
--- Get master width factor.
-- @param t Optional tag.
function getmwfact(t)
local t = t or selected()
return getproperty(t, "mwfact") or 0.5
end
--- Set the number of master windows.
-- @param nmaster The number of master windows.
-- @param t Optional tag.
function setnmaster(nmaster, t)
local t = t or selected()
if nmaster >= 0 then
setproperty(t, "nmaster", nmaster)
capi.hooks.arrange()(t.screen)
end
end
--- Get the number of master windows.
-- @param t Optional tag.
function getnmaster(t)
local t = t or selected()
return getproperty(t, "nmaster") or 1
end
--- Increase the number of master windows.
-- @param add Value to add to number of master windows.
function incnmaster(add, t)
setnmaster(getnmaster(t) + add)
end
--- Set the tag icon
-- @param icon the icon to set, either path or image object
-- @param tag the tag
function seticon(icon, tag)
local tag = tag or selected()
setproperty(tag, "icon", icon)
capi.hooks.tags()(tag.screen, tag, "modify")
end
--- Get the tag icon
-- @param t the tag
function geticon(tag)
local tag = tag or selected()
return getproperty(tag, "icon")
end
--- Set number of column windows.
-- @param ncol The number of column.
function setncol(ncol, t)
local t = t or selected()
if ncol >= 1 then
setproperty(t, "ncol", ncol)
capi.hooks.arrange()(t.screen)
end
end
--- Get number of column windows.
-- @param t Optional tag.
function getncol(t)
local t = t or selected()
return getproperty(t, "ncol") or 1
end
--- Increase number of column windows.
-- @param add Value to add to number of column windows.
function incncol(add, t)
setncol(getncol(t) + add)
end
--- View no tag.
-- @param Optional screen number.
function viewnone(screen)
local tags = capi.screen[screen or capi.mouse.screen]:tags()
for i, t in pairs(tags) do
t.selected = false
end
end
--- View a tag by its index.
-- @param i The relative index to see.
-- @param screen Optional screen number.
function viewidx(i, screen)
local tags = capi.screen[screen or capi.mouse.screen]:tags()
local sel = selected(screen)
viewnone(screen)
for k, t in ipairs(tags) do
if t == sel then
tags[util.cycle(#tags, k + i)].selected = true
end
end
end
--- View next tag. This is the same as tag.viewidx(1).
function viewnext()
return viewidx(1)
end
--- View previous tag. This is the same a tag.viewidx(-1).
function viewprev()
return viewidx(-1)
end
--- View only a tag.
-- @param t The tag object.
function viewonly(t)
viewnone(t.screen)
t.selected = true
end
--- View only a set of tags.
-- @param tags A table with tags to view only.
-- @param screen Optional screen number of the tags.
function viewmore(tags, screen)
viewnone(screen)
for i, t in pairs(tags) do
t.selected = true
end
end
local function hook_tags(screen, tag, action)
if action == "remove" then
data.tags[tag] = nil
elseif action == "add" then
data.tags[tag] = {}
end
end
--- Get a tag property.
-- @param tag The tag.
-- @param prop The property name.
-- @return The property.
function getproperty(tag, prop)
if data.tags[tag] then
return data.tags[tag][prop]
end
end
--- Set a tag property.
-- This properties are internal to awful. Some are used to draw taglist, or to
-- handle layout, etc.
-- @param tag The tag.
-- @param prop The property name.
-- @param value The value.
-- @return True if the value has been set, false otherwise.
function setproperty(tag, prop, value)
if data.tags[tag] then
data.tags[tag][prop] = value
return true
end
return false
end
--- Tag a client with the set of current tags.
-- @param c The client to tag.
-- @param startup Optional: don't do anything if true.
function withcurrent(c, startup)
if startup ~= true and c.sticky == false then
if c.transient_for then
c.screen = c.transient_for.screen
c:tags(c.transient_for:tags())
end
if #c:tags() == 0 then
c:tags(selectedlist(c.screen))
end
end
end
-- Register standards hooks
hooks.arrange.register(history.update)
hooks.tags.register(hook_tags)
hooks.manage.register(withcurrent)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80