Compare commits

...

2 commits

Author SHA1 Message Date
Alex Janka f0c7df3167 associate app ids with workspaces 2024-10-14 09:56:25 +11:00
Alex Janka 31a53cd759 "--print-default-config" option 2024-10-14 09:39:16 +11:00
4 changed files with 168 additions and 2 deletions

122
Cargo.lock generated
View file

@ -32,6 +32,55 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anstream"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]]
name = "anstyle-parse"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.89" version = "1.0.89"
@ -177,6 +226,52 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "clap"
version = "4.5.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.79",
]
[[package]]
name = "clap_lex"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
[[package]]
name = "colorchoice"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]] [[package]]
name = "concurrent-queue" name = "concurrent-queue"
version = "2.5.0" version = "2.5.0"
@ -400,6 +495,12 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.9" version = "0.3.9"
@ -471,6 +572,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.11" version = "1.0.11"
@ -1039,10 +1146,17 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "sway-flash-indicator" name = "sway-flash-indicator"
version = "0.6.6" version = "0.7.0"
dependencies = [ dependencies = [
"clap",
"directories", "directories",
"futures-util", "futures-util",
"log", "log",
@ -1243,6 +1357,12 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "walkdir" name = "walkdir"
version = "2.5.0" version = "2.5.0"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "sway-flash-indicator" name = "sway-flash-indicator"
version = "0.6.6" version = "0.7.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
@ -16,3 +16,4 @@ thiserror = "1.0.64"
notify-debouncer-mini = "0.4.1" notify-debouncer-mini = "0.4.1"
notify = "6.1.1" notify = "6.1.1"
palette = "0.7.6" palette = "0.7.6"
clap = { version = "4.5.20", features = ["derive"] }

View file

@ -1,5 +1,6 @@
use crate::prelude::*; use crate::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(default)] #[serde(default)]
@ -14,6 +15,7 @@ pub struct Config {
pub force_stacking: Vec<String>, 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>,
pub associate_id_to_workspace: HashMap<String, String>,
#[serde(default = "default_log_dir")] #[serde(default = "default_log_dir")]
pub log_dir: std::path::PathBuf, pub log_dir: std::path::PathBuf,
} }
@ -134,6 +136,7 @@ impl Default for Config {
force_stacking: Vec::new(), force_stacking: Vec::new(),
force_tabbed: Vec::new(), force_tabbed: Vec::new(),
output_blocklist: Vec::new(), output_blocklist: Vec::new(),
associate_id_to_workspace: HashMap::new(),
log_dir: std::path::PathBuf::new(), log_dir: std::path::PathBuf::new(),
} }
} }

View file

@ -1,3 +1,4 @@
use clap::Parser;
use futures_util::StreamExt; use futures_util::StreamExt;
mod colour; mod colour;
@ -19,8 +20,22 @@ static DEFAULT_COLOURS_NO_INDICATOR: tokio::sync::OnceCell<String> =
tokio::sync::OnceCell::const_new(); tokio::sync::OnceCell::const_new();
static DEFAULT_BORDER: tokio::sync::OnceCell<colour::Format> = tokio::sync::OnceCell::const_new(); static DEFAULT_BORDER: tokio::sync::OnceCell<colour::Format> = tokio::sync::OnceCell::const_new();
#[derive(Parser)]
struct Args {
#[arg(long)]
print_default_config: bool,
}
#[tokio::main] #[tokio::main]
async fn main() -> Res<()> { async fn main() -> Res<()> {
let args = Args::parse();
if args.print_default_config {
let default_config = config::Config::default();
let pretty = toml::to_string_pretty(&default_config)?;
println!("{pretty}");
return Ok(());
}
let _watch_handle = config::parse_config().await?; let _watch_handle = config::parse_config().await?;
// only log to file in release builds // only log to file in release builds
logger::init_logger(!cfg!(debug_assertions)).await?; logger::init_logger(!cfg!(debug_assertions)).await?;
@ -105,6 +120,33 @@ async fn main() -> Res<()> {
command_connection.run_command("layout stacking").await?; command_connection.run_command("layout stacking").await?;
} }
} }
} else if let Some(workspace) = node
.app_id
.as_ref()
.and_then(|id| config.associate_id_to_workspace.get(id))
{
// TODO: case-insensitive app_id match?
let mut last_node = &node;
let v = 'ws: loop {
// find the workspace containing this node
let Some(parent) =
tree.find_as_ref(|n| n.focus.contains(&last_node.id))
else {
break 'ws None;
};
if parent.node_type == swayipc_async::NodeType::Workspace {
break 'ws parent.name.clone();
}
last_node = &parent;
};
if !v.is_some_and(|w| w.eq_ignore_ascii_case(&workspace)) {
// only run the command if we're on a different workspace
command_connection
.run_command(format!("move container to workspace {workspace}"))
.await?;
}
} }
if node if node