tony / oxwm

Merge pull request #80 from tonybanters/bat-modularity Browse files
Bat modularity
Tony, btw. committed 2025-12-14 parents 9dfc76d 9a5ea80 commit 5bf548571484ee8d0886b3f326a6810ed60e3a89
Showing 7 changed files with 17 additions and 6 deletions. UnifiedSplit
+2 −2 justfile
@@ -23,8 +23,8 @@ test-clean:
23 23
24 24 test:
25 25 pkill Xephyr || true
26 - Xephyr -screen 1280x800 :1 & sleep 1
27 - DISPLAY=:1 cargo run --release -- --config resources/test-config.lua
26 + Xephyr -screen 1280x800 :2 & sleep 1
27 + DISPLAY=:2 cargo run --release -- --config resources/test-config.lua
28 28
29 29 test-multimon:
30 30 pkill Xephyr || true
+1 −0 resources/test-config.lua
@@ -154,6 +154,7 @@ oxwm.bar.set_blocks({
154 154 interval = 30,
155 155 color = colors.green,
156 156 underline = true,
157 + battery_name = "BAT1"
157 158 }),
158 159 -- oxwm.bar.block.battery({
159 160 -- charging = "󰂄 Bat: {}%",
+5 −1 src/bar/blocks/battery.rs
@@ -19,6 +19,7 @@ impl Battery {
19 19 format_full: &str,
20 20 interval_secs: u64,
21 21 color: u32,
22 + battery_name: Option<String>,
22 23 ) -> Self {
23 24 Self {
24 25 format_charging: format_charging.to_string(),
@@ -26,7 +27,10 @@ impl Battery {
26 27 format_full: format_full.to_string(),
27 28 interval: Duration::from_secs(interval_secs),
28 29 color,
29 - battery_path: "/sys/class/power_supply/BAT0".to_string(),
30 + battery_path: format!(
31 + "/sys/class/power_supply/{}",
32 + battery_name.unwrap_or_else(|| "BAT0".to_string())
33 + ),
30 34 }
31 35 }
32 36
+3 −0 src/bar/blocks/mod.rs
@@ -34,6 +34,7 @@ pub enum BlockCommand {
34 34 format_charging: String,
35 35 format_discharging: String,
36 36 format_full: String,
37 + battery_name: Option<String>,
37 38 },
38 39 Ram,
39 40 Static(String),
@@ -58,12 +59,14 @@ impl BlockConfig {
58 59 format_charging,
59 60 format_discharging,
60 61 format_full,
62 + battery_name,
61 63 } => Box::new(Battery::new(
62 64 format_charging,
63 65 format_discharging,
64 66 format_full,
65 67 self.interval_secs,
66 68 self.color,
69 + battery_name.clone(),
67 70 )),
68 71 BlockCommand::Ram => Box::new(Ram::new(&self.format, self.interval_secs, self.color)),
69 72 BlockCommand::Static(text) => Box::new(StaticBlock::new(
+4 −0 src/config/lua_api.rs
@@ -451,11 +451,13 @@ fn register_bar_module(
451 451 let full: String = config.get("full").map_err(|_| {
452 452 mlua::Error::RuntimeError("oxwm.bar.block.battery: 'full' field is required".into())
453 453 })?;
454 + let battery_name: Option<String> = config.get("battery_name").unwrap_or(None);
454 455
455 456 let formats_table = lua.create_table()?;
456 457 formats_table.set("charging", charging)?;
457 458 formats_table.set("discharging", discharging)?;
458 459 formats_table.set("full", full)?;
460 + formats_table.set("battery_name", battery_name)?;
459 461
460 462 create_block_config(lua, config, "Battery", Some(Value::Table(formats_table)))
461 463 })?;
@@ -594,11 +596,13 @@ fn register_bar_module(
594 596 let charging: String = formats.get("charging")?;
595 597 let discharging: String = formats.get("discharging")?;
596 598 let full: String = formats.get("full")?;
599 + let battery_name: Option<String> = formats.get("battery_name").unwrap_or(None);
597 600
598 601 BlockCommand::Battery {
599 602 format_charging: charging,
600 603 format_discharging: discharging,
601 604 format_full: full,
605 + battery_name,
602 606 }
603 607 }
604 608 _ => {
+1 −2 src/window_manager.rs
@@ -1455,8 +1455,7 @@ impl WindowManager {
1455 1455 for window in &windows {
1456 1456 self.connection.configure_window(
1457 1457 *window,
1458 - &x11rb::protocol::xproto::ConfigureWindowAux::new()
1459 - .border_width(0),
1458 + &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0),
1460 1459 )?;
1461 1460 }
1462 1461
+1 −1 templates/oxwm.lua
@@ -267,7 +267,7 @@ function oxwm.bar.block.shell(config) end
267 267 function oxwm.bar.block.static(config) end
268 268
269 269 ---Create a battery status block
270 ----@param config {format: string, charging: string, discharging: string, full: string, interval: integer, color: string|integer, underline: boolean} Block configuration
270 +---@param config {format: string, charging: string, discharging: string, full: string, interval: integer, color: string|integer, underline: boolean, battery_name: string} Block configuration
271 271 ---@return table Block configuration
272 272 function oxwm.bar.block.battery(config) end
273 273