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 test: 24 test:
25 pkill Xephyr || true 25 pkill Xephyr || true
26 - Xephyr -screen 1280x800 :1 & sleep 1 26 + Xephyr -screen 1280x800 :2 & sleep 1
27 - DISPLAY=:1 cargo run --release -- --config resources/test-config.lua 27 + DISPLAY=:2 cargo run --release -- --config resources/test-config.lua
28 28
29 test-multimon: 29 test-multimon:
30 pkill Xephyr || true 30 pkill Xephyr || true
+1 −0 resources/test-config.lua
@@ -154,6 +154,7 @@ oxwm.bar.set_blocks({
154 interval = 30, 154 interval = 30,
155 color = colors.green, 155 color = colors.green,
156 underline = true, 156 underline = true,
157 + battery_name = "BAT1"
157 }), 158 }),
158 -- oxwm.bar.block.battery({ 159 -- oxwm.bar.block.battery({
159 -- charging = "󰂄 Bat: {}%", 160 -- charging = "󰂄 Bat: {}%",
+5 −1 src/bar/blocks/battery.rs
@@ -19,6 +19,7 @@ impl Battery {
19 format_full: &str, 19 format_full: &str,
20 interval_secs: u64, 20 interval_secs: u64,
21 color: u32, 21 color: u32,
22 + battery_name: Option<String>,
22 ) -> Self { 23 ) -> Self {
23 Self { 24 Self {
24 format_charging: format_charging.to_string(), 25 format_charging: format_charging.to_string(),
@@ -26,7 +27,10 @@ impl Battery {
26 format_full: format_full.to_string(), 27 format_full: format_full.to_string(),
27 interval: Duration::from_secs(interval_secs), 28 interval: Duration::from_secs(interval_secs),
28 color, 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 format_charging: String, 34 format_charging: String,
35 format_discharging: String, 35 format_discharging: String,
36 format_full: String, 36 format_full: String,
37 + battery_name: Option<String>,
37 }, 38 },
38 Ram, 39 Ram,
39 Static(String), 40 Static(String),
@@ -58,12 +59,14 @@ impl BlockConfig {
58 format_charging, 59 format_charging,
59 format_discharging, 60 format_discharging,
60 format_full, 61 format_full,
62 + battery_name,
61 } => Box::new(Battery::new( 63 } => Box::new(Battery::new(
62 format_charging, 64 format_charging,
63 format_discharging, 65 format_discharging,
64 format_full, 66 format_full,
65 self.interval_secs, 67 self.interval_secs,
66 self.color, 68 self.color,
69 + battery_name.clone(),
67 )), 70 )),
68 BlockCommand::Ram => Box::new(Ram::new(&self.format, self.interval_secs, self.color)), 71 BlockCommand::Ram => Box::new(Ram::new(&self.format, self.interval_secs, self.color)),
69 BlockCommand::Static(text) => Box::new(StaticBlock::new( 72 BlockCommand::Static(text) => Box::new(StaticBlock::new(
+4 −0 src/config/lua_api.rs
@@ -451,11 +451,13 @@ fn register_bar_module(
451 let full: String = config.get("full").map_err(|_| { 451 let full: String = config.get("full").map_err(|_| {
452 mlua::Error::RuntimeError("oxwm.bar.block.battery: 'full' field is required".into()) 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 let formats_table = lua.create_table()?; 456 let formats_table = lua.create_table()?;
456 formats_table.set("charging", charging)?; 457 formats_table.set("charging", charging)?;
457 formats_table.set("discharging", discharging)?; 458 formats_table.set("discharging", discharging)?;
458 formats_table.set("full", full)?; 459 formats_table.set("full", full)?;
460 + formats_table.set("battery_name", battery_name)?;
459 461
460 create_block_config(lua, config, "Battery", Some(Value::Table(formats_table))) 462 create_block_config(lua, config, "Battery", Some(Value::Table(formats_table)))
461 })?; 463 })?;
@@ -594,11 +596,13 @@ fn register_bar_module(
594 let charging: String = formats.get("charging")?; 596 let charging: String = formats.get("charging")?;
595 let discharging: String = formats.get("discharging")?; 597 let discharging: String = formats.get("discharging")?;
596 let full: String = formats.get("full")?; 598 let full: String = formats.get("full")?;
599 + let battery_name: Option<String> = formats.get("battery_name").unwrap_or(None);
597 600
598 BlockCommand::Battery { 601 BlockCommand::Battery {
599 format_charging: charging, 602 format_charging: charging,
600 format_discharging: discharging, 603 format_discharging: discharging,
601 format_full: full, 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 for window in &windows { 1455 for window in &windows {
1456 self.connection.configure_window( 1456 self.connection.configure_window(
1457 *window, 1457 *window,
1458 - &x11rb::protocol::xproto::ConfigureWindowAux::new() 1458 + &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0),
1459 - .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 function oxwm.bar.block.static(config) end 267 function oxwm.bar.block.static(config) end
268 268
269 ---Create a battery status block 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 ---@return table Block configuration 271 ---@return table Block configuration
272 function oxwm.bar.block.battery(config) end 272 function oxwm.bar.block.battery(config) end
273 273