Compare commits

..

No commits in common. "f49bf7b949f1574b34d99430f2ec6820c26a6e90" and "b50f75d86877397ae4567baa0bc7f46d7fc6ded9" have entirely different histories.

7 changed files with 58 additions and 155 deletions

149
Cargo.lock generated
View file

@ -38,15 +38,6 @@ version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "1.7.1" version = "1.7.1"
@ -132,12 +123,6 @@ version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "by_address"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64fa3c856b712db6612c019f14756e64e4bcea13337a6b33b696333a9eaa2d06"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.5.0" version = "1.5.0"
@ -152,9 +137,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.16" version = "1.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6"
dependencies = [ dependencies = [
"shlex", "shlex",
] ]
@ -282,12 +267,6 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "fast-srgb8"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.1.1" version = "2.1.1"
@ -296,9 +275,9 @@ checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
[[package]] [[package]]
name = "filetime" name = "filetime"
version = "0.2.25" version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" checksum = "bf401df4a4e3872c4fe8151134cf483738e74b67fc934d6532c882b3d24a4550"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@ -354,7 +333,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
] ]
[[package]] [[package]]
@ -443,9 +422,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.5.0" version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@ -506,6 +485,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "lab"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf36173d4167ed999940f804952e6b08197cae5ad5d572eb4db150ce8ad5d58f"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.158" version = "0.2.158"
@ -662,9 +647,9 @@ dependencies = [
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.4" version = "0.36.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -690,30 +675,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "palette"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cbf71184cc5ecc2e4e1baccdb21026c20e5fc3dcf63028a086131b3ab00b6e6"
dependencies = [
"approx",
"fast-srgb8",
"palette_derive",
"phf",
]
[[package]]
name = "palette_derive"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5030daf005bface118c096f510ffb781fc28f9ab6a32ab224d8631be6851d30"
dependencies = [
"by_address",
"proc-macro2",
"quote",
"syn 2.0.77",
]
[[package]] [[package]]
name = "parking" name = "parking"
version = "2.2.0" version = "2.2.0"
@ -743,48 +704,6 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [
"phf_macros",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_macros"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
dependencies = [
"phf_generator",
"phf_shared",
"proc-macro2",
"quote",
"syn 2.0.77",
]
[[package]]
name = "phf_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.14" version = "0.2.14"
@ -897,9 +816,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.35" version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"errno", "errno",
@ -956,14 +875,14 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
] ]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.128" version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -1008,12 +927,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.9" version = "0.4.9"
@ -1041,15 +954,15 @@ dependencies = [
[[package]] [[package]]
name = "sway-flash-indicator" name = "sway-flash-indicator"
version = "0.5.0" version = "0.4.3"
dependencies = [ dependencies = [
"directories", "directories",
"futures-util", "futures-util",
"lab",
"log", "log",
"log4rs", "log4rs",
"notify", "notify",
"notify-debouncer-mini", "notify-debouncer-mini",
"palette",
"serde", "serde",
"swayipc-async", "swayipc-async",
"thiserror", "thiserror",
@ -1095,9 +1008,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.77" version = "2.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1121,7 +1034,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
] ]
[[package]] [[package]]
@ -1136,9 +1049,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.40.0" version = "1.39.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
@ -1160,7 +1073,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
] ]
[[package]] [[package]]
@ -1281,7 +1194,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1303,7 +1216,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -1529,5 +1442,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.77", "syn 2.0.76",
] ]

View file

@ -1,18 +1,18 @@
[package] [package]
name = "sway-flash-indicator" name = "sway-flash-indicator"
version = "0.5.0" version = "0.4.3"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
log = "0.4.22" log = "0.4.22"
log4rs = "1.3.0" log4rs = "1.3.0"
swayipc-async = "2.0.3" swayipc-async = "2.0.3"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.39.3", features = ["full"] }
futures-util = "0.3.30" futures-util = "0.3.30"
lab = "0.11.0"
directories = "5.0.1" directories = "5.0.1"
toml = "0.8.19" toml = "0.8.19"
serde = { version = "1.0.209", features = ["derive"] } serde = { version = "1.0.209", features = ["derive"] }
thiserror = "1.0.63" thiserror = "1.0.63"
notify-debouncer-mini = "0.4.1" notify-debouncer-mini = "0.4.1"
notify = "6.1.1" notify = "6.1.1"
palette = "0.7.6"

View file

@ -1,7 +1,7 @@
# Maintainer: Alex Janka <alex@alexjanka.com> # Maintainer: Alex Janka <alex@alexjanka.com>
pkgname=sway-flash-indicator pkgname=sway-flash-indicator
pkgver=0.5.0 pkgver=0.4.3
pkgrel=1 pkgrel=1
pkgdesc="flashes sway indicator border rather than always showing it" pkgdesc="flashes sway indicator border rather than always showing it"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')

View file

@ -1,23 +1,11 @@
use palette::FromColor; use lab::Lab;
use crate::prelude::*; use crate::prelude::*;
pub type Format = palette::Oklab; pub fn parse_hex(hex: &str) -> Res<Lab> {
pub type RgbFormat = palette::Srgb<u8>;
pub fn parse_hex(hex: &str) -> Res<Format> {
let hex = hex.strip_prefix('#').unwrap_or(hex); let hex = hex.strip_prefix('#').unwrap_or(hex);
let r = u8::from_str_radix(&hex[..2], 16).map_err(|_| Error::HexParse)?; let r = u8::from_str_radix(&hex[..2], 16).map_err(|_| Error::HexParse)?;
let g = u8::from_str_radix(&hex[2..4], 16).map_err(|_| Error::HexParse)?; let g = u8::from_str_radix(&hex[2..4], 16).map_err(|_| Error::HexParse)?;
let b = u8::from_str_radix(&hex[4..], 16).map_err(|_| Error::HexParse)?; let b = u8::from_str_radix(&hex[4..], 16).map_err(|_| Error::HexParse)?;
let rgb_u8 = palette::rgb::Srgb::new(r, g, b); Ok(Lab::from_rgb(&[r, g, b]))
let rgb_f32 = palette::rgb::Srgb::<f32>::from(rgb_u8);
let oklab = palette::Oklab::from_color(rgb_f32);
Ok(oklab)
}
pub fn oklab_to_hex(oklab: &Format) -> String {
let (r, g, b) = RgbFormat::from(palette::Srgb::from_color(*oklab)).into_components();
format!("#{r:02x}{g:02x}{b:02x}")
} }

View file

@ -1,3 +1,4 @@
use lab::Lab;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::prelude::*; use crate::prelude::*;
@ -9,7 +10,7 @@ pub struct Config {
pub frames_anim: u32, pub frames_anim: u32,
pub refresh_rate: u64, pub refresh_rate: u64,
#[serde(serialize_with = "lab_ser", deserialize_with = "lab_de")] #[serde(serialize_with = "lab_ser", deserialize_with = "lab_de")]
pub flash_colour: colour::Format, pub flash_colour: Lab,
pub autosplit_enabled: bool, pub autosplit_enabled: bool,
pub autosplit_ratio: f64, pub autosplit_ratio: f64,
pub output_blocklist: Vec<String>, pub output_blocklist: Vec<String>,
@ -127,7 +128,11 @@ impl Default for Config {
frames_delay: 10, frames_delay: 10,
frames_anim: 20, frames_anim: 20,
refresh_rate: 60, refresh_rate: 60,
flash_colour: colour::parse_hex("#ff0000").unwrap(), flash_colour: Lab {
l: 53.2,
a: 80.1,
b: 67.2,
},
autosplit_enabled: true, autosplit_enabled: true,
autosplit_ratio: 1.0, autosplit_ratio: 1.0,
output_blocklist: Vec::new(), output_blocklist: Vec::new(),
@ -136,16 +141,14 @@ impl Default for Config {
} }
} }
fn lab_ser<S: serde::Serializer>( fn lab_ser<S: serde::Serializer>(colour: &Lab, serializer: S) -> Result<S::Ok, S::Error> {
colour: &colour::Format, let [r, g, b] = colour.to_rgb();
serializer: S, format!("#{r:02x}{g:02x}{b:02x}").serialize(serializer)
) -> Result<S::Ok, S::Error> {
colour::oklab_to_hex(colour).serialize(serializer)
} }
fn lab_de<'a, D: serde::Deserializer<'a>>(deserializer: D) -> Result<colour::Format, D::Error> { fn lab_de<'a, D: serde::Deserializer<'a>>(deserializer: D) -> Result<Lab, D::Error> {
use serde::de::Error; use serde::de::Error;
let hex = String::deserialize(deserializer)?; let hex = String::deserialize(deserializer)?;
colour::parse_hex(&hex).map_err(|_| D::Error::custom("couldn't parse hex")) crate::colour::parse_hex(&hex).map_err(|_| D::Error::custom("couldn't parse hex"))
} }

View file

@ -6,7 +6,7 @@ pub async fn interpolate_task() -> Res<()> {
let to = crate::DEFAULT_BORDER.get().ok_or(Error::NoMatchingConfig)?; let to = crate::DEFAULT_BORDER.get().ok_or(Error::NoMatchingConfig)?;
let config = CONFIG.get().await; let config = CONFIG.get().await;
let per_frame = 1.0 / config.frames_anim as f32; let per_frame = 1.0 / config.frames_anim as f32;
let (d_l, d_chroma, d_hue) = ( let (d_l, d_a, d_b) = (
(to.l - config.flash_colour.l) * per_frame, (to.l - config.flash_colour.l) * per_frame,
(to.a - config.flash_colour.a) * per_frame, (to.a - config.flash_colour.a) * per_frame,
(to.b - config.flash_colour.b) * per_frame, (to.b - config.flash_colour.b) * per_frame,
@ -20,8 +20,8 @@ pub async fn interpolate_task() -> Res<()> {
tokio::time::sleep(dur_per_frame * config.frames_delay).await; tokio::time::sleep(dur_per_frame * config.frames_delay).await;
for _ in 0..config.frames_anim { for _ in 0..config.frames_anim {
c.l += d_l; c.l += d_l;
c.a += d_chroma; c.a += d_a;
c.b += d_hue; c.b += d_b;
connection.run_command(set_command(&c)?).await?; connection.run_command(set_command(&c)?).await?;
@ -37,11 +37,10 @@ pub async fn interpolate_task() -> Res<()> {
Ok(()) Ok(())
} }
fn set_command(colour: &colour::Format) -> Res<String> { fn set_command(colour: &lab::Lab) -> Res<String> {
let hex = colour::oklab_to_hex(colour); let [r, g, b] = colour.to_rgb();
Ok(format!( Ok(format!(
"{} {hex}", "{} #{r:02x}{g:02x}{b:02x}",
crate::DEFAULT_COLOURS_NO_INDICATOR crate::DEFAULT_COLOURS_NO_INDICATOR
.get() .get()
.ok_or(Error::NoMatchingConfig)? .ok_or(Error::NoMatchingConfig)?

View file

@ -1,4 +1,5 @@
use futures_util::StreamExt; use futures_util::StreamExt;
use lab::Lab;
mod colour; mod colour;
mod config; mod config;
@ -7,7 +8,6 @@ mod flash;
mod logger; mod logger;
pub mod prelude { pub mod prelude {
pub(crate) use crate::colour;
pub use crate::error::*; pub use crate::error::*;
pub use crate::CONFIG; pub use crate::CONFIG;
} }
@ -18,7 +18,7 @@ pub static CONFIG: config::ConfigHandle = config::ConfigHandle::new();
static DEFAULT_COLOURS: tokio::sync::OnceCell<String> = tokio::sync::OnceCell::const_new(); static DEFAULT_COLOURS: tokio::sync::OnceCell<String> = tokio::sync::OnceCell::const_new();
static DEFAULT_COLOURS_NO_INDICATOR: tokio::sync::OnceCell<String> = static DEFAULT_COLOURS_NO_INDICATOR: tokio::sync::OnceCell<String> =
tokio::sync::OnceCell::const_new(); tokio::sync::OnceCell::const_new();
static DEFAULT_BORDER: tokio::sync::OnceCell<colour::Format> = tokio::sync::OnceCell::const_new(); static DEFAULT_BORDER: tokio::sync::OnceCell<Lab> = tokio::sync::OnceCell::const_new();
#[tokio::main] #[tokio::main]
async fn main() -> Res<()> { async fn main() -> Res<()> {