now a cute widget with an icon and an API matching awesome-fswidget
This commit is contained in:
parent
d972b7e7fd
commit
e7352a8014
35
init.lua
35
init.lua
@ -1,3 +1,4 @@
|
|||||||
|
local longpress = require("awesome-longpress")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local gears = require("gears")
|
local gears = require("gears")
|
||||||
local beautiful = require ("beautiful")
|
local beautiful = require ("beautiful")
|
||||||
@ -6,6 +7,15 @@ local rw = {
|
|||||||
iconPath = "/home/izaya/.config/awesome/awesome-memwidget"
|
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()
|
function rw.new()
|
||||||
local stack = wibox.widget{
|
local stack = wibox.widget{
|
||||||
@ -26,6 +36,18 @@ function rw.new()
|
|||||||
valign = 'bottom',
|
valign = 'bottom',
|
||||||
widget = wibox.widget.textbox
|
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{
|
local membar = wibox.widget{
|
||||||
widget = wibox.widget.progressbar,
|
widget = wibox.widget.progressbar,
|
||||||
max_value = 1,
|
max_value = 1,
|
||||||
@ -46,14 +68,27 @@ function rw.new()
|
|||||||
local totalUsed = total - free
|
local totalUsed = total - free
|
||||||
local used = totalUsed - (buffers + cache)
|
local used = totalUsed - (buffers + cache)
|
||||||
memtext.text = (string.format("%3.0f%%", (used/total)*100))
|
memtext.text = (string.format("%3.0f%%", (used/total)*100))
|
||||||
|
memused.text = formatSize(used*1024)
|
||||||
|
memfree.text = formatSize((total-used)*1024)
|
||||||
membar.value = (used/total)
|
membar.value = (used/total)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
stack:add(bgimage)
|
stack:add(bgimage)
|
||||||
stack:add(wibox.container.place(membar,"center","bottom"))
|
stack:add(wibox.container.place(membar,"center","bottom"))
|
||||||
|
stack:add(memused)
|
||||||
|
stack:add(memfree)
|
||||||
stack:add(memtext)
|
stack:add(memtext)
|
||||||
rwidget.update()
|
rwidget.update()
|
||||||
|
longpress.add(rwidget,function()
|
||||||
|
memtext.visible = not memtext.visible
|
||||||
|
memused.visible = not memused.visible
|
||||||
|
memfree.visible = not memfree.visible
|
||||||
|
end)
|
||||||
return rwidget
|
return rwidget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rw.all()
|
||||||
|
return {rw.new()}
|
||||||
|
end
|
||||||
|
|
||||||
return rw
|
return rw
|
||||||
|
Loading…
Reference in New Issue
Block a user