0.2.0 - autotiling

This commit is contained in:
Alex Janka 2024-07-25 15:23:53 +10:00
parent 8bab54b524
commit 9f5ea80d52
4 changed files with 31 additions and 4 deletions

2
Cargo.lock generated
View file

@ -653,7 +653,7 @@ dependencies = [
[[package]]
name = "sway-flash-indicator"
version = "0.1.1"
version = "0.2.0"
dependencies = [
"directories",
"futures-util",

View file

@ -1,6 +1,6 @@
[package]
name = "sway-flash-indicator"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
[dependencies]

View file

@ -10,6 +10,8 @@ pub struct Config {
pub refresh_rate: u64,
#[serde(serialize_with = "lab_ser", deserialize_with = "lab_de")]
pub flash_colour: Lab,
pub autosplit_enabled: bool,
pub autosplit_ratio: f64,
}
pub fn parse_config() -> Res<()> {
@ -51,6 +53,8 @@ impl Default for Config {
a: 80.1,
b: 67.2,
},
autosplit_enabled: true,
autosplit_ratio: 1.0,
}
}
}

View file

@ -31,11 +31,15 @@ async fn main() -> Res<()> {
config::parse_config()?;
let mut event_connection = swayipc_async::Connection::new().await?;
let mut autosplit_connection = swayipc_async::Connection::new().await?;
get_sway_config(&mut event_connection).await?;
let mut events = event_connection
.subscribe([swayipc_async::EventType::Binding])
.subscribe([
swayipc_async::EventType::Binding,
swayipc_async::EventType::Window,
])
.await?;
let mut fut: Option<tokio::task::JoinHandle<()>> = None;
@ -55,7 +59,26 @@ async fn main() -> Res<()> {
}));
}
}
_ => unreachable!(),
swayipc_async::Event::Window(window)
// TODO: change on window closed also
// the node we're given is the one that closes
if window.change != swayipc_async::WindowChange::Mark =>
{
let node = window.container;
let (width, height) = (node.window_rect.width, node.window_rect.height);
let ratio = (width as f64) / (height as f64);
let autosplit_ratio =
CONFIG.get().ok_or(Error::NoMatchingConfig)?.autosplit_ratio;
if let Err(e) = if ratio > autosplit_ratio {
autosplit_connection.run_command("splith").await
} else {
autosplit_connection.run_command("splitv").await
} {
log::warn!("error {e:?} setting split");
}
}
_ => {}
}
}
}