From b5faff6871971aa71d97f155dab3908cb2811cdc Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 24 Jul 2024 16:05:53 +1000 Subject: [PATCH] use colours from sway config while interpolating --- src/main.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6e25327..42aa718 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,8 @@ fn lab_de<'a, D: serde::Deserializer<'a>>(deserializer: D) -> Result = tokio::sync::OnceCell::const_new(); static DEFAULT_COLOURS: tokio::sync::OnceCell = tokio::sync::OnceCell::const_new(); +static DEFAULT_COLOURS_NO_INDICATOR: tokio::sync::OnceCell = + tokio::sync::OnceCell::const_new(); static DEFAULT_BORDER: tokio::sync::OnceCell = tokio::sync::OnceCell::const_new(); #[tokio::main] @@ -153,6 +155,10 @@ async fn get_sway_config( DEFAULT_BORDER.set(parse_hex(default_border)?)?; DEFAULT_COLOURS.set(default_colours.to_string())?; + let mut split = default_colours.split_whitespace().collect::>(); + split.pop(); + DEFAULT_COLOURS_NO_INDICATOR.set(split.join(" "))?; + Ok(()) } @@ -177,7 +183,10 @@ async fn interpolate_task() -> Result<(), Box> { ); let mut c = config.flash_colour; - connection.run_command(set_command(&c)).await?; + { + let command = set_command(&c)?; + connection.run_command(command).await?; + } let dur_per_frame = std::time::Duration::from_secs_f64(1.0 / config.refresh_rate as f64); tokio::time::sleep(dur_per_frame * config.frames_delay).await; @@ -185,7 +194,10 @@ async fn interpolate_task() -> Result<(), Box> { c.l += d_l; c.a += d_a; c.b += d_b; - connection.run_command(set_command(&c)).await?; + { + let command = set_command(&c)?; + connection.run_command(command).await?; + } tokio::time::sleep(dur_per_frame).await; } connection @@ -194,7 +206,10 @@ async fn interpolate_task() -> Result<(), Box> { Ok(()) } -fn set_command(colour: &Lab) -> String { +fn set_command(colour: &Lab) -> Result> { let [r, g, b] = colour.to_rgb(); - format!("client.focused #000000 #88c0d0 #000000 #{r:02x}{g:02x}{b:02x}") + Ok(format!( + "{} #{r:02x}{g:02x}{b:02x}", + DEFAULT_COLOURS_NO_INDICATOR.get().ok_or(NoMatchingConfig)? + )) }