From 1403c8f3b10149461f9319c75a69a1254f3cb273 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Fri, 6 Jan 2023 15:22:34 +0100 Subject: awesome: rework info widgets use graph for cpu, add memory widget --- awesome/rc.lua | 75 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 20 deletions(-) (limited to 'awesome') diff --git a/awesome/rc.lua b/awesome/rc.lua index 4b612b0..0e4cbb3 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -132,30 +132,64 @@ mytextclock = wibox.widget.textclock(' %H:%M ') mycalendar = awful.widget.calendar_popup.month({ position = 'tr', spacing = 1, }) mycalendar:attach(mytextclock) - -function bat_string(widget, state) - local charge = ' Bat:' .. state[2] .. '% ' - - if state[2] < 10 then - charge = '' .. charge .. '' +function create_bat_widget() + local bat_name = "BAT0" + local fd = io.open("/sys/class/power_supply/" .. bat_name .. "/status") + if fd == nil then + return nil + else + io.close(fd) end - - return charge -end - -batwidget = wibox.widget.textbox() -vicious.register(batwidget, vicious.widgets.bat, bat_string, 60, "BAT0") - -function cpu_string(widget, loads) - local result = " CPU:" .. loads[2] .. "%" - for cpu = 3, #loads do - result = result .. "/" .. loads[cpu] .. "%" + function bat_string(widget, state) + local charge = ' 🔋' .. state[2] .. '% ' + if state[2] < 10 then + charge = '' .. charge .. '' + end + return charge end - return result .. " " + local text = wibox.widget.textbox() + vicious.register(text, vicious.widgets.bat, bat_string, 60, bat_name) + return text end +local batwidget = create_bat_widget() -cpuwidget = wibox.widget.textbox() -vicious.register(cpuwidget, vicious.widgets.cpu, cpu_string, 2) +function create_cpu_widget() + local graph = wibox.widget { + color = beautiful.fg_normal, + background_color = beautiful.bg_normal, + widget = wibox.widget.graph + } + graph:set_width(50) + vicious.register(graph, vicious.widgets.cpu, "$1", 2) + return wibox.widget { + wibox.container.mirror(graph, { horizontal = true }), + wibox.widget.textbox(" CPU"), + layout = wibox.layout.stack + } +end +local cpuwidget = create_cpu_widget() + +function create_mem_widget() + local bar = wibox.widget { + color = beautiful.fg_normal, + background_color = beautiful.bg_normal, + border_width = beautiful.border_width, + border_color = beautiful.border_focus, + widget = wibox.widget.progressbar + } + vicious.register(bar, vicious.widgets.mem, "$1", 5) + local rotated_bar = wibox.widget { + wibox.container.constraint(bar, 'max', 0, 10), + direction = 'east', + layout = wibox.container.rotate + } + return wibox.widget { + wibox.widget.textbox(" Mem "), + rotated_bar, + layout = wibox.layout.fixed.horizontal + } +end +local memwidget = create_mem_widget() -- Create a wibox for each screen and add it local taglist_buttons = gears.table.join( @@ -263,6 +297,7 @@ awful.screen.connect_for_each_screen(function(s) layout = wibox.layout.fixed.horizontal, --mykeyboardlayout, cpuwidget, + memwidget, batwidget, s.mylayoutbox, wibox.widget.systray(), -- cgit v1.2.3