-
Notifications
You must be signed in to change notification settings - Fork 5
/
awesome-buttons.lua
209 lines (180 loc) · 6.02 KB
/
awesome-buttons.lua
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
local wibox = require("wibox")
local gears = require("gears")
local buttons = {}
buttons.with_icon = function(args)
local type = args.type or 'basic'
local color = args.color or '#D8DEE9'
local icon = args.icon or 'help-circle'
local shape = args.shape or 'circle'
local icon_size = args.icon_size or 20
local icon_margin = args.icon_margin or 4
local onclick = args.onclick or function () end
if icon:sub(1, 1) ~= '/' then
icon = os.getenv("HOME") .. '/.config/awesome/awesome-buttons/icons/' .. icon .. '.svg'
end
local result = wibox.widget{
{
{
image = icon,
resize = true,
forced_height = icon_size,
forced_width = icon_size,
widget = wibox.widget.imagebox
},
margins = icon_margin,
widget = wibox.container.margin
},
bg = '#00000000',
widget = wibox.container.background
}
if type == 'outline' then
result:set_shape_border_color(color)
result:set_shape_border_width(1)
elseif type == 'flat' then
result:set_bg(color)
end
if shape == 'circle' then
result:set_shape(gears.shape.circle)
elseif shape == 'rounded_rect' then
result:set_shape(function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 4) end)
else
result:set_shape(gears.shape.rectangle)
end
local old_cursor, old_wibox
result:connect_signal("mouse::enter", function(c)
if type ~= 'flat' then
c:set_bg(color)
end
pcall(function()
local wb = mouse.current_wibox
old_cursor, old_wibox = wb.cursor, wb
wb.cursor = "hand1"
end)
end)
result:connect_signal("mouse::leave", function(c)
if type ~= 'flat' then
c:set_bg('#00000000')
end
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end)
result:connect_signal("button::press", function() onclick() end)
return result
end
buttons.with_text = function(args)
local type = args.type or 'basic'
local text = args.text
local onclick = args.onclick or function() end
local color = args.color or '#D8DEE9'
local text_size = args.text_size or 10
local result = wibox.widget{
{
{
markup = '<span size="' .. text_size .. '000" foreground="'
.. ((type == 'flat') and '#00000000' or color) .. '">' .. text ..'</span>',
widget = wibox.widget.textbox
},
top = 4, bottom = 4, left = 8, right = 8,
widget = wibox.container.margin
},
bg = '#00000000',
shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 4) end,
widget = wibox.container.background
}
if type == 'outline' then
result:set_shape_border_color(color)
result:set_shape_border_width(1)
elseif type == 'flat' then
result:set_bg(color)
end
local old_cursor, old_wibox
result:connect_signal("mouse::enter", function(c)
if type ~= 'flat' then
c:set_bg("#00000066")
end
local wb = mouse.current_wibox
old_cursor, old_wibox = wb.cursor, wb
wb.cursor = "hand1"
end)
result:connect_signal("mouse::leave", function(c)
if type ~= 'flat' then
c:set_bg('#00000000')
end
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end)
result:connect_signal("button::press", function() onclick() end)
return result
end
buttons.with_icon_and_text = function(args)
local type = args.type or 'basic'
local text = args.text
local icon = args.icon
local onclick = args.onclick or function() end
local color = args.color or '#D8DEE9'
local text_size = args.text_size or 10
if icon:sub(1, 1) ~= '/' then
icon = os.getenv("HOME") .. '/.config/awesome/awesome-buttons/icons/' .. icon .. '.svg'
end
local result = wibox.widget{
{
{
{
image = icon,
resize = true,
forced_height = 20,
widget = wibox.widget.imagebox
},
margins = 4,
widget = wibox.container.margin
},
{
{
markup = '<span size="' .. text_size .. '000" foreground="'
.. ((type == 'flat') and '#00000000' or color) .. '">' .. text ..'</span>',
widget = wibox.widget.textbox
},
top = 4, bottom = 4, right = 8,
widget = wibox.container.margin
},
layout = wibox.layout.fixed.horizontal
},
bg = '#00000000',
shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 4) end,
widget = wibox.container.background
}
if type == 'outline' then
result:set_shape_border_color(color)
result:set_shape_border_width(1)
end
if type == 'flat' then
result:set_bg(color)
end
local old_cursor, old_wibox
result:connect_signal("mouse::enter", function(c)
if type ~= 'flat' then
c:set_bg('#00000044')
end
pcall(function ()
local wb = mouse.current_wibox
old_cursor, old_wibox = wb.cursor, wb
wb.cursor = "hand1"
end)
end)
result:connect_signal("mouse::leave", function(c)
if type ~= 'flat' then
c:set_bg('#00000000')
end
if old_wibox then
old_wibox.cursor = old_cursor
old_wibox = nil
end
end)
result:connect_signal("button::press", function() onclick() end)
return result
end
return buttons