-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgets.lua
153 lines (133 loc) · 4.06 KB
/
widgets.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
-- ===================================================================
-- Functions and utilities for setting up widgets
-- ===================================================================
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local lain = require("lain")
-- Module table.
local widgets = {}
local widget_table = {}
-- Facilitates text customization.
local markup = lain.util.markup
-- Function to generate arrow separators.
local arrow = lain.util.separators.arrow_left
-- MEM
local memicon = wibox.widget.imagebox(beautiful.widget_mem)
local mem = lain.widget.mem({
settings = function()
widget:set_markup(
markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal,
" " .. mem_now.used .. "MB "
)
)
end
})
widget_table.mem = { icon = memicon, widget = mem.widget }
-- CPU
local cpuicon = wibox.widget.imagebox(beautiful.widget_cpu)
local cpu = lain.widget.cpu({
settings = function()
widget:set_markup(
markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal,
" " .. cpu_now.usage .. "% "
)
)
end
})
widget_table.cpu = { icon = cpuicon, widget = cpu.widget }
-- System Temperature
local tempicon = wibox.widget.imagebox(beautiful.widget_temp)
local temp = lain.widget.temp({
settings = function()
widget:set_markup(
markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal,
" " .. coretemp_now .. "°C "
)
)
end
})
widget_table.temp = { icon = tempicon, widget = temp.widget }
-- Space available on filesystem
local fsicon = wibox.widget.imagebox(beautiful.widget_hdd)
local fs = lain.widget.fs({
options = "--exclude-type=tmpfs",
notification_preset = {
fg = beautiful.fg_normal,
bg = beautiful.bg_normal,
font = beautiful.font
},
settings = function()
widget:set_markup(
markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal,
" " .. string.format(
"%.0f ", fs_now["/"].free
) .. fs_now["/"].units .. " "
)
)
end
})
widget_table.fs = { icon = fsicon, widget = fs.widget }
-- Network Down/Up status
local neticon = wibox.widget.imagebox(beautiful.widget_net)
local net = lain.widget.net({
settings = function()
widget:set_markup(
markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal,
" " .. net_now.received .. " ↓↑ " .. net_now.sent .. " "
)
)
end
})
widget_table.net = { icon = neticon, widget = net.widget }
-- Textclock
local clock = awful.widget.watch(
"date +'%a %d %b %R'", 60,
function(widget, stdout)
widget:set_markup(
" " .. markup.fontfg(
beautiful.font,
beautiful.widget_fg_normal, stdout)
)
end
)
widget_table.clock = { icon = nil, widget = clock }
-- Wraps widgets into a "cute" box with margins and backgrounds. The must be a
-- better way of doing this. TODO refactor
function widgets.wrap_widget(icon, widget, bg_color, left_margin, right_margin)
if (icon ~= nil) then
widget = wibox.widget {
icon,
widget,
layout = wibox.layout.align.horizontal
}
end
widget = wibox.container.margin(widget, left_margin, right_margin)
widget = wibox.container.background(widget, bg_color)
return widget
end
-- Get widget with configurable background and margins.
function widgets.get_widget(widget_name, bg_color, left_margin, right_margin)
return widgets.wrap_widget(
widget_table[widget_name].icon,
widget_table[widget_name].widget,
bg_color,
left_margin,
right_margin
)
end
-- Gets a left arrow. What a shock.
function widgets.get_left_arrow(background, tip)
return arrow(background, tip)
end
return widgets