From f7116d268aff3fae88d8de408e8c807295618a5c Mon Sep 17 00:00:00 2001 From: delta Date: Tue, 4 Apr 2023 15:43:40 +0200 Subject: restructure and improve config --- .config/awesome/ui/statusbar/widgets/wifi.lua | 64 +++++++++++---------------- 1 file changed, 26 insertions(+), 38 deletions(-) (limited to '.config/awesome/ui/statusbar/widgets/wifi.lua') diff --git a/.config/awesome/ui/statusbar/widgets/wifi.lua b/.config/awesome/ui/statusbar/widgets/wifi.lua index d0b7116..5f131b3 100644 --- a/.config/awesome/ui/statusbar/widgets/wifi.lua +++ b/.config/awesome/ui/statusbar/widgets/wifi.lua @@ -1,48 +1,36 @@ -local awful = require "awful" -local vars = require "misc.vars" +local qvars = require "quarrel.vars" local wibox = require "wibox" -local h = require "misc.helpers" +local qmath = require "quarrel.math" +local gcolor = require "gears.color" +local phosphor = require "assets.phosphor" -local wifi_inner = awful.widget.watch("awk 'NR==3 {printf(\"%.0f\", $3*10/7)}' /proc/net/wireless", 1, function(widget, stdout) - widget.font = "DejaVu Sans Mono wifi ramp Normal 8" - local icon = "" - local color = vars.colors.red +local wifi = wibox.widget { + widget = wibox.container.place, + valign = "center", + halign = "center", + { + widget = wibox.widget.imagebox, + image = gcolor.recolor_image(phosphor.wifi_x_fill, qvars.colors.red), + forced_width = qvars.icon_size, + forced_height = qvars.icon_size + } +} - if stdout == "" then - widget:set_markup("" .. icon .. "") +awesome.connect_signal("services::wifi", function(strength, connected) + if not connected then + wifi.widget.image = gcolor.recolor_image(phosphor.wifi_x_fill, qvars.colors.red) return end - local percent = tonumber(stdout) - - if percent <= 20 then - icon = "" - color = vars.colors.red - elseif percent <= 40 then - icon = "" - color = vars.colors.yellow - elseif percent <= 60 then - icon = "" - color = vars.colors.yellow - elseif percent <= 80 then - icon = "" - color = vars.colors.green - elseif percent <= 100 then - icon = "" - color = vars.colors.green - end - - - widget:set_markup("" .. icon .. "") -end) - -local wifi = wibox.widget { - widget = wibox.container.place, - wifi_inner -} + local icon_data = qmath.step_value(strength, { + { 0, { "none", "red" } }, + { 25, { "low", "yellow" } }, + { 50, { "medium", "yellow" } }, + { 75, { "high", "green" } }, + { 100 } + }) -h.tooltip({ wifi }, function() - return io.popen("iwgetid -r"):read("*a"):sub(0, -2) + wifi.widget.image = gcolor.recolor_image(phosphor["wifi_" .. icon_data[1] .. "_fill"], qvars.colors[icon_data[2]]) end) return wifi -- cgit v1.2.3