Skip to content

Add optional swap bar next to the memory chart - #148

Open
glima wants to merge 1 commit into
cosmic-utils:mainfrom
glima:memory-swap-bar
Open

Add optional swap bar next to the memory chart#148
glima wants to merge 1 commit into
cosmic-utils:mainfrom
glima:memory-swap-bar

Conversation

@glima

@glima glima commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problem

The memory sensor only reports RAM. update() refreshed with MemoryRefreshKind::nothing().with_ram() and sampled used_memory() / free_memory(), so swap usage was not visible anywhere in the panel.

Change

Adds a Show swap bar next to chart toggle to the memory settings (off by default). When enabled, a narrow fill bar is drawn beside the memory chart showing the share of swap in use:

  • Half the size of a regular chart along the panel's flow direction, so it reads as a companion to the memory chart rather than a second full-size element.
  • No text. The memory chart beside it already carries the numbers, and there is not enough room at half width.
  • Aspect ratio flips (21×42 / 42×21) for vertical panels so it stays half-size in the direction items are stacked.
  • Reuses the memory chart colors (background / graph1 / frame).
  • Omitted entirely when the system has no swap configured, so nothing changes for those users.

Swap usage (used / total GB) is also listed on the memory settings page while the toggle is on.

Implementation notes

  • svg_graph::bar() is a new standalone renderer: rounded rect, bottom-up fill clipped to the corner radius, 1px frame.
  • Memory now also tracks total_swap / swap_used, refreshed via .with_swap() alongside the existing RAM refresh, so no extra syscall pass is added.
  • MemoryConfig::show_swap defaults to false, so existing configs deserialize unchanged and the panel looks the same until the toggle is flipped.

Translations

memory-show-swap and swap-explanation were added to every locale file, since all locales in this repo currently carry the full key set. The non-English files get the English string as a placeholder for translators to replace.

Testing

cargo build and cargo clippy are clean (only pre-existing warnings). Verified on a machine with 68 GB of swap that the bar tracks usage, and checked the rendered SVG geometry standalone.

The memory sensor only ever reported RAM: it refreshed with
MemoryRefreshKind::nothing().with_ram() and sampled used/free memory, so
swap usage was invisible in the panel.

Add a "Show swap bar next to chart" toggle to the memory settings. When
enabled, a narrow fill bar is drawn beside the memory chart showing the
share of swap in use. The bar is half the size of a regular chart along
the panel's flow direction and carries no text, since the memory chart
next to it already shows the numbers. Its aspect ratio flips for vertical
panels so it stays half-size in the direction items are stacked.

The bar reuses the memory chart colors and is omitted entirely on systems
without swap configured. Swap usage is also listed on the memory settings
page when the toggle is on.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Hyperchaotic

Copy link
Copy Markdown
Collaborator

Thank you for this PR. I'm thinking about how it looks. I'm wondering if it should be a full secondary chart, like temp is to CPU, the user can then choose between line/ring. @CarsonBurke thoughts?

(In the future, not in the scope of this PR, it would be nice to be able to adjust chart width for line/bar charts and corner radius.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants