60 lines
1.6 KiB
Lua
60 lines
1.6 KiB
Lua
local wibox = require("wibox")
|
|
local gears = require("gears")
|
|
local beautiful = require ("beautiful")
|
|
local rw = {
|
|
iconSize = 96,
|
|
iconPath = "/home/izaya/.config/awesome/awesome-memwidget"
|
|
}
|
|
|
|
|
|
function rw.new()
|
|
local stack = wibox.widget{
|
|
layout = wibox.layout.stack,
|
|
}
|
|
local bgimage = wibox.widget{
|
|
widget = wibox.widget.imagebox,
|
|
forced_width = rw.iconSize,
|
|
forced_height = rw.iconSize,
|
|
image = rw.iconPath .. "/media-memory.svg"
|
|
}
|
|
local rwidget = wibox.widget{
|
|
layout = wibox.layout.grid.horizontal,
|
|
wibox.container.constraint(stack,nil,rw.iconSize,rw.iconSize)
|
|
}
|
|
local memtext = wibox.widget{
|
|
align = 'center',
|
|
valign = 'bottom',
|
|
widget = wibox.widget.textbox
|
|
}
|
|
local membar = wibox.widget{
|
|
widget = wibox.widget.progressbar,
|
|
max_value = 1,
|
|
border_width = 1,
|
|
border_color = beautiful.border_color,
|
|
color = beautiful.bg_focus,
|
|
background_color = beautiful.bg_normal,
|
|
forced_height = rw.iconSize / 6
|
|
}
|
|
function rwidget.update()
|
|
local f = io.open("/proc/meminfo","rb")
|
|
if not f then return true end
|
|
local c = f:read("*a")
|
|
local total = tonumber(c:match("MemTotal:%s+(%d+)"))
|
|
local free = tonumber(c:match("MemFree:%s+(%d+)"))
|
|
local buffers = tonumber(c:match("Buffers:%s+(%d+)"))
|
|
local cache = tonumber(c:match("Cached:%s+(%d+)"))
|
|
local totalUsed = total - free
|
|
local used = totalUsed - (buffers + cache)
|
|
memtext.text = (string.format("%3.0f%%", (used/total)*100))
|
|
membar.value = (used/total)
|
|
return true
|
|
end
|
|
stack:add(bgimage)
|
|
stack:add(wibox.container.place(membar,"center","bottom"))
|
|
stack:add(memtext)
|
|
rwidget.update()
|
|
return rwidget
|
|
end
|
|
|
|
return rw
|