[PR #1344] [MERGED] feat: Access ironbar variables from cairo/lua #1317

Closed
opened 2026-05-22 21:56:14 +01:00 by JakeStanger · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/JakeStanger/ironbar/pull/1344
Author: @untoldwind
Created: 1/25/2026
Status: Merged
Merged: 1/26/2026
Merged by: @JakeStanger

Base: masterHead: master


📝 Commits (10+)

📊 Changes

9 files changed (+170 additions, -29 deletions)

View changed files

📝 docs/modules/Cairo.md (+29 -11)
📝 lua/draw.lua (+2 -2)
📝 src/clients/lua.rs (+126 -3)
📝 src/clients/mod.rs (+2 -2)
📝 src/clients/sysinfo.rs (+2 -2)
📝 src/clients/upower/mod.rs (+1 -1)
📝 src/config/mod.rs (+1 -1)
📝 src/main.rs (+3 -3)
📝 src/modules/cairo.rs (+4 -4)

📄 Description

Added the following functions/fields to lua:

  • ironbar:var_get(key): Lookup an ironbar variable, if key is a namespace all variables in that namespace are returned as a lua-table
  • ironbar:log_debug(msg), ironbar:log_info(msg), ...: Just some logging helpers (better than using print in lua.
  • ironbar:unixtime(): Helper for high resolution unixtime. With this the day_ms in the clock example can be done without running an executable:
     function get_ms()
       return ironbar:unixtime().subsec_millis / 1000
     end
    
  • ironbar.config_dir: This makes it simpler to do relative file import via dofile in lua
  • Also added the width/height of the drawing area to the draw function.

Background for all of this:
I was trying to create a simple barchart for cpu load per core.
With the changes/additions this can be done with a rather simple script:

function draw(cr, area_width, area_height)
    local num_cores = 32 -- there is probably a better way than to hardcode this
    local bar_width = area_width / num_cores
    local bar_height = area_height - 2
    local cpu_percent = ironbar:var_get("sysinfo.cpu_percent")

    cr:set_source_rgb(1.0, 1.0, 1.0)

    for i = 0, num_cores - 1 do
      local core_percent = cpu_percent["cpu" .. i]
      local height = math.max(math.ceil(core_percent * bar_height / 100.0), 1)

      cr:rectangle(i * bar_width, area_height - height - 1, bar_width, height)
      cr:fill()
    end
end


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/JakeStanger/ironbar/pull/1344 **Author:** [@untoldwind](https://github.com/untoldwind) **Created:** 1/25/2026 **Status:** ✅ Merged **Merged:** 1/26/2026 **Merged by:** [@JakeStanger](https://github.com/JakeStanger) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (10+) - [`8530515`](https://github.com/JakeStanger/ironbar/commit/8530515ee0f5c843521afaa9a4cea5c3302293aa) Access ironbar variables from lua - [`1cb697a`](https://github.com/JakeStanger/ironbar/commit/1cb697ad4b6898769524520c69db985a5999b48b) Add config_dir field - [`b44e21a`](https://github.com/JakeStanger/ironbar/commit/b44e21a9c641a5b867cc299bd78328913d5d81f1) Add log helpers - [`68b76ea`](https://github.com/JakeStanger/ironbar/commit/68b76ea136434de11ddff153707b70c23e9d7acd) Add high resolution unixtime - [`19aa5fc`](https://github.com/JakeStanger/ironbar/commit/19aa5fc295b22ce83bc9cc82cbc087f24fb6088b) Add draw width/heigh parameters - [`4ab37cf`](https://github.com/JakeStanger/ironbar/commit/4ab37cff63de0e2b217246c0adf9b77ee1c82f9a) Split var_get into var_get/var_list - [`505e60d`](https://github.com/JakeStanger/ironbar/commit/505e60da1879fff140f5d87f75181b57d3369f0d) Add documentation - [`a4308e2`](https://github.com/JakeStanger/ironbar/commit/a4308e2370b769a2ae189725f0c672f41e49e987) Update docs/modules/Cairo.md - [`1a6ccc1`](https://github.com/JakeStanger/ironbar/commit/1a6ccc11062a39b9e6f01724ec1eb084064c0f68) Refactor feature flag - [`685f088`](https://github.com/JakeStanger/ironbar/commit/685f088a75cf33ea29f74bf28fca11bb4cf27bb4) Tweak doc ### 📊 Changes **9 files changed** (+170 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `docs/modules/Cairo.md` (+29 -11) 📝 `lua/draw.lua` (+2 -2) 📝 `src/clients/lua.rs` (+126 -3) 📝 `src/clients/mod.rs` (+2 -2) 📝 `src/clients/sysinfo.rs` (+2 -2) 📝 `src/clients/upower/mod.rs` (+1 -1) 📝 `src/config/mod.rs` (+1 -1) 📝 `src/main.rs` (+3 -3) 📝 `src/modules/cairo.rs` (+4 -4) </details> ### 📄 Description Added the following functions/fields to lua: * `ironbar:var_get(key)`: Lookup an ironbar variable, if `key` is a namespace all variables in that namespace are returned as a lua-table * `ironbar:log_debug(msg)`, `ironbar:log_info(msg)`, ...: Just some logging helpers (better than using `print` in lua. * `ironbar:unixtime()`: Helper for high resolution unixtime. With this the `day_ms` in the clock example can be done without running an executable: ```lua function get_ms() return ironbar:unixtime().subsec_millis / 1000 end ``` * `ironbar.config_dir`: This makes it simpler to do relative file import via `dofile` in lua * Also added the width/height of the drawing area to the draw function. Background for all of this: I was trying to create a simple barchart for cpu load per core. With the changes/additions this can be done with a rather simple script: ```lua function draw(cr, area_width, area_height) local num_cores = 32 -- there is probably a better way than to hardcode this local bar_width = area_width / num_cores local bar_height = area_height - 2 local cpu_percent = ironbar:var_get("sysinfo.cpu_percent") cr:set_source_rgb(1.0, 1.0, 1.0) for i = 0, num_cores - 1 do local core_percent = cpu_percent["cpu" .. i] local height = math.max(math.ceil(core_percent * bar_height / 100.0), 1) cr:rectangle(i * bar_width, area_height - height - 1, bar_width, height) cr:fill() end end ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
JakeStanger 2026-05-22 21:56:14 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JakeStanger/ironbar#1317
No description provided.