diff options
| author | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-18 23:26:17 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar@gmail.com> | 2026-09-18 23:26:17 +0530 |
| commit | 6b0161b2639bb49e270754e90f4f8a47311c5198 (patch) | |
| tree | fc0f4a138b311061daad5ddeb6ed50314f1f5a1a /modules/desktop/eww/bar | |
| parent | 53eac37422f77750adbc801f71b85ab04cf2b7f9 (diff) | |
| download | home-manager-config-6b0161b2639bb49e270754e90f4f8a47311c5198.tar.gz home-manager-config-6b0161b2639bb49e270754e90f4f8a47311c5198.zip | |
chore: projectwide refactoring
- Using more consistent naming conventions across the project. Using java style super
descriptive variable names.
- Removed slop comments in favor of using more descriptive naming conventions.
Diffstat (limited to 'modules/desktop/eww/bar')
| -rw-r--r-- | modules/desktop/eww/bar/bar.nix | 20 | ||||
| -rw-r--r-- | modules/desktop/eww/bar/bar.yuck | 109 | ||||
| -rw-r--r-- | modules/desktop/eww/bar/system-stats.lua | 25 |
3 files changed, 106 insertions, 48 deletions
diff --git a/modules/desktop/eww/bar/bar.nix b/modules/desktop/eww/bar/bar.nix index 70bfbac..252811f 100644 --- a/modules/desktop/eww/bar/bar.nix +++ b/modules/desktop/eww/bar/bar.nix @@ -63,12 +63,10 @@ name = "eww-system-stats"; path = ./system-stats.lua; description = "Emit {cpu, ram, net} as JSON."; - luaPackages = ( - ps: [ - ps.lua-cjson - ps.luaposix - ] - ); + luaPackages = ps: [ + ps.lua-cjson + ps.luaposix + ]; deps = [ pkgs.iw pkgs.iproute2 @@ -82,12 +80,10 @@ name = "niri-status"; path = ./niri-status.lua; description = "Emit workspace and active window information list."; - luaPackages = ( - ps: [ - ps.lgi - ps.lua-cjson - ] - ); + luaPackages = ps: [ + ps.lgi + ps.lua-cjson + ]; deps = [ config.desktop.niri.package ]; gobjectIntrospection = true; }; diff --git a/modules/desktop/eww/bar/bar.yuck b/modules/desktop/eww/bar/bar.yuck index f8f48d0..dc2d575 100644 --- a/modules/desktop/eww/bar/bar.yuck +++ b/modules/desktop/eww/bar/bar.yuck @@ -29,61 +29,122 @@ (system-widget))) (defwidget workspaces-widget [workspaces] - (box :orientation "v" :space-evenly false :spacing 4 :halign "fill" :class "workspaces" + (box :orientation "v" + :space-evenly false + :spacing 4 + :halign "fill" + :class "workspaces" (for ws in workspaces (eventbox :onclick "niri msg action focus-workspace ${ws.idx}" - :cursor "pointer" :halign "fill" + :cursor "pointer" + :halign "fill" :tooltip "${ws.tooltip}" - (box :class "workspace-button ${ws.is_active ? 'active' : ''}" :halign "fill" + (box :class "workspace-button ${ws.is_active ? 'active' : ''}" + :halign "fill" (overlay :halign "fill" (image :class "workspace-icon" :path "${ws.icon}" - :image-width 20 :image-height 20) - (label :class "workspace-idx" :text "${ws.idx}" :halign "end" :valign "end"))))))) + :image-width 20 + :image-height 20) + (label :class "workspace-idx" + :text "${ws.idx}" + :halign "end" + :valign "end"))))))) (defwidget windows-widget [windows] - (box :orientation "v" :space-evenly false :spacing 4 :halign "center" :class "windows" :vexpand true + (box :orientation "v" + :space-evenly false + :spacing 4 + :halign "center" + :class "windows" + :vexpand true (for w in windows (eventbox :onclick "niri msg action focus-window --id ${w.id}" :cursor "pointer" :halign "fill" :tooltip "${w.app_id}: ${w.title != '' ? ' ' : ''}${w.title}" - (box :halign "fill" :class "window-button ${w.is_focused ? 'focused' : ''}" - (image :class "window-icon" :path "${w.icon}" :image-width 20 :image-height 20)))))) + (box :halign "fill" + :class "window-button ${w.is_focused ? 'focused' : ''}" + (image :class "window-icon" + :path "${w.icon}" + :image-width 20 + :image-height 20)))))) (defwidget system-widget [] - (box :orientation "v" :space-evenly false :spacing 6 :halign "fill" :class "system" - (box :orientation "v" :class "system-item" :halign "fill" :space-evenly false :spacing 4 + (box :orientation "v" + :space-evenly false + :spacing 6 + :halign "fill" + :class "system" + (box :orientation "v" + :class "system-item" + :halign "fill" + :space-evenly false + :spacing 4 :tooltip "${system_stats.net.tooltip}" (image :class "system-icon" :path "${system_stats.net.status == 'down' ? '@@icon-offline@@' : system_stats.net.routes[0].type == 'wifi' ? '@@icon-wifi@@' : system_stats.net.routes[0].type == 'ethernet' ? '@@icon-ethernet@@' : system_stats.net.routes[0].type == 'tun' ? '@@icon-proxy@@' : '@@icon-offline@@'}" - :image-width 24 :image-height 24) + :image-width 24 + :image-height 24) (label :class "system-label small" :text "${system_stats.net.status == 'down' ? '-' : system_stats.net.routes[0].tx}") (label :class "system-label small" :text "${system_stats.net.status == 'down' ? '-' : system_stats.net.routes[0].rx}")) - (box :orientation "v" :class "system-item" :space-evenly false :spacing 4 + (box :orientation "v" + :class "system-item" + :space-evenly false + :spacing 4 :tooltip "${system_stats.cpu.tooltip}" - (image :class "system-icon" :path "@@icon-cpu@@" :image-width 24 :image-height 24) + (image :class "system-icon" + :path "@@icon-cpu@@" + :image-width 24 + :image-height 24) (label :class "system-label" :text "${system_stats.cpu.percent}%")) - (box :orientation "v" :class "system-item" :space-evenly false :spacing 4 + (box :orientation "v" + :class "system-item" + :space-evenly false + :spacing 4 :tooltip "${system_stats.ram.tooltip}" - (image :class "system-icon" :path "@@icon-ram@@" :image-width 24 :image-height 24) + (image :class "system-icon" + :path "@@icon-ram@@" + :image-width 24 + :image-height 24) (label :class "system-label" :text "${system_stats.ram.percent}%")) - (box :orientation "v" :class "system-item" :space-evenly false :spacing 4 + (box :orientation "v" + :class "system-item" + :space-evenly false + :spacing 4 :tooltip "${system_stats.battery.tooltip}" - (image :class "system-icon" :path "@@icon-battery@@" :image-width 24 :image-height 24) - (label :class "system-label" :text "${system_stats.battery.present ? (system_stats.battery.percent + '%') : '-'}")) + (image :class "system-icon" + :path "@@icon-battery@@" + :image-width 24 + :image-height 24) + (label :class "system-label" + :text "${system_stats.battery.present ? (system_stats.battery.percent + '%') : '-'}")) (eventbox :onclick "pamixer --toggle-mute" :onscroll "bash -c '[ \"{}\" = \"up\" ] && pamixer --increase 5 --unmute || pamixer --decrease 5'" - :cursor "pointer" :halign "fill" - (box :orientation "v" :space-evenly false :spacing 4 :class "system-item" + :cursor "pointer" + :halign "fill" + (box :orientation "v" + :space-evenly false + :spacing 4 + :class "system-item" :tooltip "${system_stats.sound.tooltip}" - (image :class "system-icon" :path "@@icon-audio@@" :image-width 24 :image-height 24) - (label :class "system-label" :text "${system_stats.sound.mute ? '-' : (system_stats.sound.percent + '%')}"))) - (box :orientation "v" :class "system-item" :space-evenly false :spacing 4 + (image :class "system-icon" + :path "@@icon-audio@@" + :image-width 24 + :image-height 24) + (label :class "system-label" + :text "${system_stats.sound.mute ? '-' : (system_stats.sound.percent + '%')}"))) + (box :orientation "v" + :class "system-item" + :space-evenly false + :spacing 4 :tooltip "${full_date} ${time} (${date})" - (image :class "system-icon" :path "@@icon-calendar@@" :image-width 24 :image-height 24) + (image :class "system-icon" + :path "@@icon-calendar@@" + :image-width 24 + :image-height 24) (label :class "system-label small" :text time) (label :class "system-label small" :text ampm) (label :class "system-label small" :text date)))) diff --git a/modules/desktop/eww/bar/system-stats.lua b/modules/desktop/eww/bar/system-stats.lua index bc9cc90..9571d26 100644 --- a/modules/desktop/eww/bar/system-stats.lua +++ b/modules/desktop/eww/bar/system-stats.lua @@ -4,6 +4,7 @@ -- Single-threaded LuaJIT port of the original Python script. Instead of -- OS threads, a single supervisor loop schedules the periodic cpu/ram and -- sound refreshes and polls an inotifywait child for link-state changes. + local cjson = require("cjson") local posix = require("posix") local unistd = require("posix.unistd") @@ -23,13 +24,13 @@ end local net_last_time = nil local net_last_bytes = {} --- ------------------------------------------------ time +-- TIME local function mono_sec() local g = gettimeofday() return g.tv_sec + g.tv_usec / 1e6 end --- ------------------------------------------------ process helpers +-- PROCESS HELPERS local function sh(cmd) local h = io.popen(cmd) if not h then @@ -40,7 +41,7 @@ local function sh(cmd) return out end --- ------------------------------------------------ formatting +-- FORMATTING local function format_rate(bytes_per_sec) if bytes_per_sec == nil or bytes_per_sec < 0 then return "0B" @@ -77,7 +78,7 @@ local function format_bytes(kib) return string.format("%.1f%s", val, unit) end --- ------------------------------------------------ /proc readers +-- /proc READERS local function read_cpu_times() local times = {} local f = io.open("/proc/stat") @@ -192,7 +193,7 @@ local function get_ram_speed_mhz() return mx end --- ------------------------------------------------ network helpers +-- NETWORK HELPERS local function get_all_default_ifaces() local out = sh("ip -o route show default 2>/dev/null") if not out then @@ -305,7 +306,7 @@ local function get_iface_io_bytes(iface) return rx, tx end --- ------------------------------------------------ tooltips +-- TOOLTIPS local function build_cpu_tooltip(overall_pct, per_core_list, freq_mhz, load_avg) local lines = { string.format("CPU: %d%%", overall_pct) } if freq_mhz ~= nil then @@ -337,7 +338,7 @@ local function build_ram_tooltip(ram_pct, used, total, available, swap_pct, swap return table.concat(lines, "\n") end --- ------------------------------------------------ state collectors +-- STATE COLLECTORS -- get_all_default_ifaces (`ip route`), get_iface_ip (`ip addr`), and the -- wifi branch of get_speed_mbps (`iw dev link`) each spawn a subprocess. -- Those three rarely change second-to-second, so they're only re-probed @@ -530,7 +531,7 @@ local function get_sound_state() } end --- ------------------------------------------------ battery +-- BATTERY local function find_battery_path() local handle = io.popen("ls /sys/class/power_supply/ 2>/dev/null") if not handle then @@ -608,7 +609,7 @@ end local battery_path = find_battery_path() --- ------------------------------------------------ state + emit +-- state + emit local state = { cpu = { percent = 0, @@ -657,7 +658,7 @@ local CPU_INTERVAL = 2.0 local SOUND_INTERVAL = 1.0 local INOTIFY_RETRY_INTERVAL = 30.0 -- backoff between (re)spawn attempts --- ------------------------------------------------ inotifywait child +-- inotifywait child -- Returns pid, read_fd on success, or nil, nil if the fork/exec setup -- itself failed outright (pipe/fork syscall failure, not inotifywait -- failing later). @@ -694,7 +695,7 @@ local function spawn_inotify() return pid, r end --- ------------------------------------------------ main loop +-- MAIN LOOP local function main() local ram_speed_mhz = get_ram_speed_mhz() @@ -878,7 +879,7 @@ local function main() -- Empty read on a "ready" fd means the write end closed, i.e. -- the inotifywait child exited (crashed, watched path missing, -- binary not found, etc). Reap it, drop the fd, and don't - -- touch it again until the next backed-off retry -- this is + -- touch it again until the next backed-off retry; this is -- the fix for the tight busy-loop: without this branch, poll() -- would report this dead fd as "ready" forever, on every -- single iteration, with an effectively-zero timeout. |
