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]]
name = "sway-flash-indicator"
version = "0.6.2"
version = "0.6.3"
dependencies = [
"directories",
"futures-util",

View file

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

View file

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

View file

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

View file

@ -77,33 +77,49 @@ async fn main() -> Res<()> {
let node = window.container;
let tree = command_connection.get_tree().await?;
let config = CONFIG.get().await;
if window.change == swayipc_async::WindowChange::New
&& node.app_id.as_ref().is_some_and(|app_id| {
if window.change == swayipc_async::WindowChange::New {
if node.app_id.as_ref().is_some_and(|app_id| {
config
.force_tabbed
.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 tabbed").await?;
}) {
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 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
&& node.app_id == Some(String::from("code-url-handler"))
{
recent_code = Some((std::time::Instant::now(), node.id));
} else if recent_code.is_some_and(|(t, _)| {
std::time::Instant::now().duration_since(t)
> std::time::Duration::from_millis(200)
}) {
recent_code = None;
if node
.app_id
.as_ref()
.is_some_and(|app_id| app_id.eq_ignore_ascii_case("code-url-handler"))
{
recent_code = Some((std::time::Instant::now(), node.id));
} else if recent_code.is_some_and(|(t, _)| {
std::time::Instant::now().duration_since(t)
> std::time::Duration::from_millis(200)
}) {
recent_code = None;
}
}
if let Some((_, id)) = recent_code {