aboutsummaryrefslogtreecommitdiffstats
path: root/lib/card.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-13 11:35:00 +0200
committerDanilo M. <danix@danix.xyz>2026-10-13 11:35:00 +0200
commit3943e08dabe684b409a3ac99c9371fbeb5df5cdb (patch)
tree7dcedbb2d64a04e59ab239a8c40c04f0f0cf29aa /lib/card.lua
parentb2fe3f493efc12dd300f0e2b2ede5660ee70c193 (diff)
downloadconky-theme-udt-3943e08dabe684b409a3ac99c9371fbeb5df5cdb.tar.gz
conky-theme-udt-3943e08dabe684b409a3ac99c9371fbeb5df5cdb.zip
feat: system, gpu, disks and network move to the quickshell islandHEADmaster
The quickshell island's performance panel now shows CPU, RAM, temperatures, the GPU, disks and network, and warns from the status pill when something runs hot, fills up, or the public IP drifts from the pinned one. Two dashboards drawing the same numbers would drift apart, so the four widgets go, with the disks and public IP samplers. The island keeps writing ~/.cache/udt/pubip.txt in the same format. The freed space is left empty for the user to rearrange. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/card.lua')
-rw-r--r--lib/card.lua145
1 files changed, 1 insertions, 144 deletions
diff --git a/lib/card.lua b/lib/card.lua
index 7fd40f8..2749a6e 100644
--- a/lib/card.lua
+++ b/lib/card.lua
@@ -215,11 +215,7 @@ end
-- fontconfig alone: a missing glyph draws as an invisible blank and a wrong
-- codepoint as a plausible neighbour, so neither fails visibly.
M.ICON = {
- system = '\u{F0EE0}', -- cpu-64-bit
- gpu = '\u{F083E}', -- video-4k-box (no GPU glyph exists)
- disks = '\u{F02CA}', -- harddisk
cache = '\u{F0ABA}', -- folder-clock
- network = '\u{F0317}', -- lan
slackware = '\u{F318}', -- linux-slackware
breaktimer = '\u{F13AB}', -- timer
calendar = '\u{F0E17}', -- calendar-month
@@ -272,7 +268,7 @@ end
-- Colour for a value against two thresholds.
--
--- One function so all four system cards agree on the rule instead of each
+-- One function so the cards agree on the rule instead of each
-- re-deriving it, and so "what counts as busy" is stated in a single place.
-- `v`, `warn` and `crit` share whatever unit the caller is using: percent for
-- a filesystem, degrees for a sensor.
@@ -283,78 +279,6 @@ function M.threshold(v, warn, crit, colors)
return colors.ok
end
--- A horizontal bar: a dim full-width track with a filled portion over it.
---
--- frac is clamped rather than trusted: a filesystem at 100% and a load that
--- briefly computes above 1.0 must not draw past the track.
-function M.bar(cr, x, y, w, h, frac, colour, colors)
- frac = tonumber(frac) or 0
- if frac < 0 then frac = 0 elseif frac > 1 then frac = 1 end
-
- M.rgba(cr, colors.rule, 0.5)
- M.rounded_path(cr, x, y, w, h, h / 2)
- cairo_fill(cr)
-
- if frac > 0 then
- M.rgba(cr, colour, 1)
- M.rounded_path(cr, x, y, math.max(w * frac, h), h, h / 2)
- cairo_fill(cr)
- end
-end
-
--- A vertical bar, rising from its baseline. The equaliser's element.
-function M.vbar(cr, x, base_y, w, max_h, frac, colour, colors)
- frac = tonumber(frac) or 0
- if frac < 0 then frac = 0 elseif frac > 1 then frac = 1 end
-
- M.rgba(cr, colors.rule, 0.5)
- cairo_rectangle(cr, x, base_y - max_h, w, max_h)
- cairo_fill(cr)
-
- local h = max_h * frac
- if h > 0 then
- M.rgba(cr, colour, 1)
- cairo_rectangle(cr, x, base_y - h, w, h)
- cairo_fill(cr)
- end
-end
-
--- A ring gauge, after idea2.png: a dim full circle with an arc over it
--- covering `frac`, leaving the centre free for a glyph.
---
--- The arc starts at twelve o'clock and sweeps clockwise, which is what reads
--- as a gauge. Cairo's zero angle is at three o'clock and it sweeps clockwise
--- already, so the start is offset by -pi/2 rather than the direction being
--- reversed.
-function M.ring(cr, cx, cy, r, frac, colour, colors, width)
- frac = tonumber(frac) or 0
- if frac < 0 then frac = 0 elseif frac > 1 then frac = 1 end
- width = width or math.max(3, r * 0.18)
-
- -- Start a fresh path. A preceding card.text() leaves a current point behind,
- -- and cairo_arc() joins to it with a straight line, so without this every
- -- ring after a label is drawn with a stray chord to the text baseline.
- cairo_new_path(cr)
- local prev_width = cairo_get_line_width(cr)
- cairo_set_line_width(cr, width)
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND)
-
- M.rgba(cr, colors.rule, 0.5)
- cairo_arc(cr, cx, cy, r, 0, math.pi * 2)
- cairo_stroke(cr)
-
- if frac > 0 then
- M.rgba(cr, colour, 1)
- cairo_arc(cr, cx, cy, r, -math.pi / 2, -math.pi / 2 + math.pi * 2 * frac)
- cairo_stroke(cr)
- end
- -- Leave the line state as it was found. A later stroke inheriting ROUND gets
- -- visibly rounded ends on the card's hairlines, and one inheriting this
- -- width gets a hairline several pixels thick.
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT)
- cairo_set_line_width(cr, prev_width)
-end
-
-- The largest base size S at which every row of pieces still fits max_w,
-- measured at a reference size and scaled.
--
@@ -383,19 +307,6 @@ function M.fit_unit(cr, max_w, groups, ref)
return S
end
--- Bytes to a short human string: 1181116006 -> '1.1G'.
--- The card formats its own numbers because the samplers pass raw bytes.
-function M.human(bytes)
- local n = tonumber(bytes)
- if not n then return '--' end
- local units = { 'B', 'K', 'M', 'G', 'T', 'P' }
- local i = 1
- while n >= 1024 and i < #units do n = n / 1024; i = i + 1 end
- if i == 1 then return string.format('%d%s', math.floor(n), units[i]) end
- if n >= 100 then return string.format('%.0f%s', n, units[i]) end
- return string.format('%.1f%s', n, units[i])
-end
-
-- Shorten a string to `limit` characters, appending an ellipsis when it cuts.
--
-- By character, never by byte: Lua's string.sub counts bytes, so slicing a
@@ -417,58 +328,4 @@ function M.truncate(s, limit)
return s:sub(1, cut - 1) .. '\u{2026}'
end
--- A line chart: several series sharing one baseline and one vertical scale.
---
--- `series` is a list of { values = <array>, colour = <rgb> }. `max` is the
--- shared ceiling; passing one rather than computing per series is the whole
--- point, because two series scaled independently lie about their relative
--- size: a 200kB/s upload would draw the same height as a 40MB/s download.
---
--- Values are drawn oldest-left, one per array entry, so a caller sizing its
--- history to the pixel width gets one sample per column and no interpolation.
--- A series shorter than its buffer draws only what it has, which is what a
--- freshly started dashboard shows while the window fills.
-function M.plot(cr, x, y, w, h, series, max, colors)
- if not (w > 0 and h > 0) then return end
- max = tonumber(max) or 0
- if max <= 0 then max = 1 end -- an idle link is a flat line, not a division by zero
-
- local prev_width = cairo_get_line_width(cr)
- local prev_cap = cairo_get_line_cap(cr)
-
- -- The baseline, so an empty chart still reads as a chart rather than a gap.
- M.rgba(cr, colors.rule, 0.5)
- cairo_new_path(cr)
- cairo_set_line_width(cr, 1)
- cairo_move_to(cr, x, y + h)
- cairo_line_to(cr, x + w, y + h)
- cairo_stroke(cr)
-
- cairo_set_line_width(cr, math.max(1.5, h * 0.02))
- cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND)
-
- for _, s in ipairs(series) do
- local v = s.values
- local n = #v
- if n >= 2 then
- -- One sample per column when the caller sized its buffer to the width.
- local step = w / math.max(n - 1, 1)
- M.rgba(cr, s.colour, 1)
- cairo_new_path(cr)
- for i = 1, n do
- local frac = v[i] / max
- if frac < 0 then frac = 0 elseif frac > 1 then frac = 1 end
- local px = x + (i - 1) * step
- local py = y + h - frac * h
- if i == 1 then cairo_move_to(cr, px, py) else cairo_line_to(cr, px, py) end
- end
- cairo_stroke(cr)
- end
- end
-
- -- Leave the line state as it was found, for the same reason card.ring does.
- cairo_set_line_width(cr, prev_width)
- cairo_set_line_cap(cr, prev_cap)
-end
-
return M