forked from material-shell/material-awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag-list.lua
More file actions
163 lines (152 loc) · 3.85 KB
/
tag-list.lua
File metadata and controls
163 lines (152 loc) · 3.85 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
local awful = require('awful')
local wibox = require('wibox')
local dpi = require('beautiful').xresources.apply_dpi
local capi = {button = _G.button}
local clickable_container = require('widget.material.clickable-container')
local modkey = require('configuration.keys.mod').modKey
--- Common method to create buttons.
-- @tab buttons
-- @param object
-- @treturn table
local function create_buttons(buttons, object)
if buttons then
local btns = {}
for _, b in ipairs(buttons) do
-- Create a proxy button object: it will receive the real
-- press and release events, and will propagate them to the
-- button object the user provided, but with the object as
-- argument.
local btn = capi.button {modifiers = b.modifiers, button = b.button}
btn:connect_signal(
'press',
function()
b:emit_signal('press', object)
end
)
btn:connect_signal(
'release',
function()
b:emit_signal('release', object)
end
)
btns[#btns + 1] = btn
end
return btns
end
end
local function list_update(w, buttons, label, data, objects)
-- update the widgets, creating them if needed
w:reset()
for i, o in ipairs(objects) do
local cache = data[o]
local ib, tb, bgb, tbm, ibm, l, bg_clickable
if cache then
ib = cache.ib
tb = cache.tb
bgb = cache.bgb
tbm = cache.tbm
ibm = cache.ibm
else
ib = wibox.widget.imagebox()
tb = wibox.widget.textbox()
bgb = wibox.container.background()
tbm = wibox.container.margin(tb, dpi(4), dpi(16))
ibm = wibox.container.margin(ib, dpi(12), dpi(12), dpi(12), dpi(12))
l = wibox.layout.fixed.horizontal()
bg_clickable = clickable_container()
-- All of this is added in a fixed widget
l:fill_space(true)
l:add(ibm)
-- l:add(tbm)
bg_clickable:set_widget(l)
-- And all of this gets a background
bgb:set_widget(bg_clickable)
bgb:buttons(create_buttons(buttons, o))
data[o] = {
ib = ib,
tb = tb,
bgb = bgb,
tbm = tbm,
ibm = ibm
}
end
local text, bg, bg_image, icon, args = label(o, tb)
args = args or {}
-- The text might be invalid, so use pcall.
if text == nil or text == '' then
tbm:set_margins(0)
else
if not tb:set_markup_silently(text) then
tb:set_markup('<i><Invalid text></i>')
end
end
bgb:set_bg(bg)
if type(bg_image) == 'function' then
-- TODO: Why does this pass nil as an argument?
bg_image = bg_image(tb, o, nil, objects, i)
end
bgb:set_bgimage(bg_image)
if icon then
ib.image = icon
else
ibm:set_margins(0)
end
bgb.shape = args.shape
bgb.shape_border_width = args.shape_border_width
bgb.shape_border_color = args.shape_border_color
w:add(bgb)
end
end
local TagList = function(s)
return awful.widget.taglist(
s,
awful.widget.taglist.filter.all,
awful.util.table.join(
awful.button(
{},
1,
function(t)
t:view_only()
end
),
awful.button(
{modkey},
1,
function(t)
if _G.client.focus then
_G.client.focus:move_to_tag(t)
t:view_only()
end
end
),
awful.button({}, 3, awful.tag.viewtoggle),
awful.button(
{modkey},
3,
function(t)
if _G.client.focus then
_G.client.focus:toggle_tag(t)
end
end
),
awful.button(
{},
4,
function(t)
awful.tag.viewprev(t.screen)
end
),
awful.button(
{},
5,
function(t)
awful.tag.viewnext(t.screen)
end
)
),
{},
list_update,
wibox.layout.fixed.vertical()
)
end
return TagList