0.2.0 - autotiling
This commit is contained in:
parent
8bab54b524
commit
9f5ea80d52
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -653,7 +653,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sway-flash-indicator"
|
name = "sway-flash-indicator"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"directories",
|
"directories",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "sway-flash-indicator"
|
name = "sway-flash-indicator"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -10,6 +10,8 @@ pub struct Config {
|
||||||
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: Lab,
|
pub flash_colour: Lab,
|
||||||
|
pub autosplit_enabled: bool,
|
||||||
|
pub autosplit_ratio: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_config() -> Res<()> {
|
pub fn parse_config() -> Res<()> {
|
||||||
|
@ -51,6 +53,8 @@ impl Default for Config {
|
||||||
a: 80.1,
|
a: 80.1,
|
||||||
b: 67.2,
|
b: 67.2,
|
||||||
},
|
},
|
||||||
|
autosplit_enabled: true,
|
||||||
|
autosplit_ratio: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -31,11 +31,15 @@ async fn main() -> Res<()> {
|
||||||
config::parse_config()?;
|
config::parse_config()?;
|
||||||
|
|
||||||
let mut event_connection = swayipc_async::Connection::new().await?;
|
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?;
|
get_sway_config(&mut event_connection).await?;
|
||||||
|
|
||||||
let mut events = event_connection
|
let mut events = event_connection
|
||||||
.subscribe([swayipc_async::EventType::Binding])
|
.subscribe([
|
||||||
|
swayipc_async::EventType::Binding,
|
||||||
|
swayipc_async::EventType::Window,
|
||||||
|
])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut fut: Option<tokio::task::JoinHandle<()>> = None;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue