respect config.autosplit_enabled

This commit is contained in:
Alex Janka 2024-09-24 12:42:18 +10:00
parent 0ced792b8c
commit 4abdca0ca1
4 changed files with 12 additions and 8 deletions

2
Cargo.lock generated
View file

@ -1041,7 +1041,7 @@ dependencies = [
[[package]]
name = "sway-flash-indicator"
version = "0.5.0"
version = "0.5.1"
dependencies = [
"directories",
"futures-util",

View file

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

View file

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

View file

@ -27,7 +27,7 @@ async fn main() -> Res<()> {
logger::init_logger(!cfg!(debug_assertions)).await?;
let mut event_connection = swayipc_async::Connection::new().await?;
let mut autosplit_connection = swayipc_async::Connection::new().await?;
let mut command_connection = swayipc_async::Connection::new().await?;
get_sway_config(&mut event_connection).await?;
@ -84,7 +84,7 @@ async fn main() -> Res<()> {
recent_code = None;
log::info!("focused the window we want with id {id}");
if let Err(e) = code_trigger(
&mut autosplit_connection,
&mut command_connection,
id,
&CONFIG.get().await.output_blocklist,
)
@ -98,16 +98,20 @@ async fn main() -> Res<()> {
// TODO: also change on window closed -
// the node we're given is the one that closes
if node.node_type == swayipc_async::NodeType::Con {
let config = CONFIG.get().await;
if !config.autosplit_enabled {
continue;
}
let (width, height) = (node.window_rect.width, node.window_rect.height);
if width == 0 || height == 0 {
continue;
}
let ratio = (width as f64) / (height as f64);
let autosplit_ratio = CONFIG.get().await.autosplit_ratio;
let autosplit_ratio = config.autosplit_ratio;
if let Err(e) = if ratio > autosplit_ratio {
autosplit_connection.run_command("splith").await
command_connection.run_command("splith").await
} else {
autosplit_connection.run_command("splitv").await
command_connection.run_command("splitv").await
} {
log::warn!("error {e:?} setting split");
}