now a cute widget with an icon and an API matching awesome-fswidget

This commit is contained in:
Izaya 2022-09-12 00:45:07 +10:00
parent d972b7e7fd
commit e7352a8014
1 changed files with 35 additions and 0 deletions

View File

@ -1,3 +1,4 @@
local longpress = require("awesome-longpress")
local wibox = require("wibox")
local gears = require("gears")
local beautiful = require ("beautiful")
@ -6,6 +7,15 @@ local rw = {
iconPath = "/home/izaya/.config/awesome/awesome-memwidget"
}
local sizeTable = {[0] = "B", "K","M","G","T","P"}
local function formatSize(n)
local i = 0
while n > 1024 do
n = n / 1024
i = i + 1
end
return string.format("%0.1f%s",n,sizeTable[i])
end
function rw.new()
local stack = wibox.widget{
@ -26,6 +36,18 @@ function rw.new()
valign = 'bottom',
widget = wibox.widget.textbox
}
local memused = wibox.widget{
align = 'left',
valign = 'bottom',
visible = false,
widget = wibox.widget.textbox
}
local memfree = wibox.widget{
align = 'right',
valign = 'bottom',
visible = false,
widget = wibox.widget.textbox
}
local membar = wibox.widget{
widget = wibox.widget.progressbar,
max_value = 1,
@ -46,14 +68,27 @@ function rw.new()
local totalUsed = total - free
local used = totalUsed - (buffers + cache)
memtext.text = (string.format("%3.0f%%", (used/total)*100))
memused.text = formatSize(used*1024)
memfree.text = formatSize((total-used)*1024)
membar.value = (used/total)
return true
end
stack:add(bgimage)
stack:add(wibox.container.place(membar,"center","bottom"))
stack:add(memused)
stack:add(memfree)
stack:add(memtext)
rwidget.update()
longpress.add(rwidget,function()
memtext.visible = not memtext.visible
memused.visible = not memused.visible
memfree.visible = not memfree.visible
end)
return rwidget
end
function rw.all()
return {rw.new()}
end
return rw