From e7352a80143a42ed1262b0573b57d074e1374c26 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 12 Sep 2022 00:45:07 +1000 Subject: [PATCH] now a cute widget with an icon and an API matching awesome-fswidget --- init.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/init.lua b/init.lua index 1dbee73..0597e30 100644 --- a/init.lua +++ b/init.lua @@ -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