associate app ids with workspaces

This commit is contained in:
Alex Janka 2024-10-14 09:56:25 +11:00
parent 31a53cd759
commit f0c7df3167
4 changed files with 32 additions and 2 deletions

2
Cargo.lock generated
View file

@ -1154,7 +1154,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "sway-flash-indicator"
version = "0.6.6"
version = "0.7.0"
dependencies = [
"clap",
"directories",

View file

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

View file

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

View file

@ -120,6 +120,33 @@ async fn main() -> Res<()> {
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