-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
96 lines (76 loc) · 2.1 KB
/
Copy pathinit.lua
File metadata and controls
96 lines (76 loc) · 2.1 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
local setmetatable = setmetatable
local math = math
local table = table
local lgi = require "lgi"
local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local GTop = lgi.GTop
local disk = require("awesome-disk-widget.disk")
local disk_widget = { mt = {} }
local function round(value)
return math.floor(value + 0.5)
end
local function format_size(b)
local bytes = b
if bytes == 0 then return "0 B" end
local i, units = 1, { "B", "KB", "MB", "GB", "TB", "PB", "EB", "YB" }
while bytes >= 1024 do
bytes = bytes / 1024
i = i + 1
end
local unit = units[ i ] or "?"
return string.format("%s %s", round(bytes), unit)
end
function disk_widget:update_text()
local text_parts = {}
for _, d in ipairs(self._private.disks) do
local disk_state = d:get_state()
local text = string.format("%s %s", disk_state.mountpoint, format_size(disk_state.free))
table.insert(text_parts, text)
end
self.textbox:set_text(table.concat(text_parts, " "))
end
function disk_widget:update_tooltip()
end
function disk_widget:update()
self:update_text()
self:update_tooltip()
end
local function new(args)
local w = wibox.widget {
layout = wibox.layout.fixed.horizontal,
spacing = 4,
{
id = "iconbox",
widget = wibox.widget.textbox,
font = "FontAwesome 12",
text = ""
},
{
id = "textbox",
widget = wibox.widget.textbox,
}
}
GTop.glibtop_init()
w._private.disks = {}
for _, mp in ipairs(args.mountpoints) do
local d = disk({
mountpoint=mp
})
table.insert(w._private.disks, d)
end
w.tooltip = awful.tooltip({ objects = { w },})
gears.table.crush(w, disk_widget, true)
local update_timer = gears.timer {
timeout = 15,
callback = function() w:update() end
}
update_timer:start()
w:update()
return w
end
function disk_widget.mt:__call(...)
return new(...)
end
return setmetatable(disk_widget, disk_widget.mt)