add force_stacking

This commit is contained in:
Alex Janka 2024-09-25 14:50:22 +10:00
parent b47d623a05
commit 5e236b2d3d
5 changed files with 41 additions and 23 deletions

2
Cargo.lock generated
View file

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

View file

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

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.6.2 pkgver=0.6.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

@ -12,6 +12,7 @@ pub struct Config {
pub flash_colour: colour::Format, pub flash_colour: colour::Format,
pub autosplit_enabled: bool, pub autosplit_enabled: bool,
pub autosplit_ratio: f64, pub autosplit_ratio: f64,
pub force_stacking: Vec<String>,
pub force_tabbed: Vec<String>, pub force_tabbed: Vec<String>,
pub output_blocklist: Vec<String>, pub output_blocklist: Vec<String>,
#[serde(default = "default_log_dir")] #[serde(default = "default_log_dir")]
@ -131,6 +132,7 @@ impl Default for Config {
flash_colour: colour::parse_hex("#ff0000").unwrap(), flash_colour: colour::parse_hex("#ff0000").unwrap(),
autosplit_enabled: true, autosplit_enabled: true,
autosplit_ratio: 1.0, autosplit_ratio: 1.0,
force_stacking: Vec::new(),
force_tabbed: Vec::new(), force_tabbed: Vec::new(),
output_blocklist: Vec::new(), output_blocklist: Vec::new(),
log_dir: std::path::PathBuf::new(), log_dir: std::path::PathBuf::new(),

View file

@ -77,33 +77,49 @@ async fn main() -> Res<()> {
let node = window.container; let node = window.container;
let tree = command_connection.get_tree().await?; let tree = command_connection.get_tree().await?;
let config = CONFIG.get().await; let config = CONFIG.get().await;
if window.change == swayipc_async::WindowChange::New if window.change == swayipc_async::WindowChange::New {
&& node.app_id.as_ref().is_some_and(|app_id| { if node.app_id.as_ref().is_some_and(|app_id| {
config config
.force_tabbed .force_tabbed
.iter() .iter()
.any(|name| name.eq_ignore_ascii_case(app_id)) .any(|name| name.eq_ignore_ascii_case(app_id))
}) }) {
{ if let Some(parent) = tree.find_as_ref(|n| n.focus.contains(&node.id)) {
if let Some(parent) = tree.find_as_ref(|n| n.focus.contains(&node.id)) { if parent.layout == swayipc_async::NodeLayout::SplitH
if parent.layout == swayipc_async::NodeLayout::SplitH || parent.layout == swayipc_async::NodeLayout::SplitV
|| parent.layout == swayipc_async::NodeLayout::SplitV {
{ command_connection.run_command("splith").await?;
command_connection.run_command("splith").await?; command_connection.run_command("layout tabbed").await?;
command_connection.run_command("layout tabbed").await?; }
}
} else if node.app_id.as_ref().is_some_and(|app_id| {
config
.force_stacking
.iter()
.any(|name| name.eq_ignore_ascii_case(app_id))
}) {
if let Some(parent) = tree.find_as_ref(|n| n.focus.contains(&node.id)) {
if parent.layout == swayipc_async::NodeLayout::SplitH
|| parent.layout == swayipc_async::NodeLayout::SplitV
{
command_connection.run_command("splith").await?;
command_connection.run_command("layout stacking").await?;
}
} }
} }
}
if window.change == swayipc_async::WindowChange::New if node
&& node.app_id == Some(String::from("code-url-handler")) .app_id
{ .as_ref()
recent_code = Some((std::time::Instant::now(), node.id)); .is_some_and(|app_id| app_id.eq_ignore_ascii_case("code-url-handler"))
} else if recent_code.is_some_and(|(t, _)| { {
std::time::Instant::now().duration_since(t) recent_code = Some((std::time::Instant::now(), node.id));
> std::time::Duration::from_millis(200) } else if recent_code.is_some_and(|(t, _)| {
}) { std::time::Instant::now().duration_since(t)
recent_code = None; > std::time::Duration::from_millis(200)
}) {
recent_code = None;
}
} }
if let Some((_, id)) = recent_code { if let Some((_, id)) = recent_code {