Compare commits
2 commits
4abdca0ca1
...
0cb40e714e
Author | SHA1 | Date | |
---|---|---|---|
Alex Janka | 0cb40e714e | ||
Alex Janka | 0355dfb5dc |
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -931,9 +931,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.209"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
|
||||
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
@ -950,9 +950,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.209"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
|
||||
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1041,7 +1041,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sway-flash-indicator"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"futures-util",
|
||||
|
@ -1106,18 +1106,18 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.63"
|
||||
version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
|
||||
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.63"
|
||||
version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
|
||||
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sway-flash-indicator"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
@ -11,8 +11,8 @@ tokio = { version = "1.40.0", features = ["full"] }
|
|||
futures-util = "0.3.30"
|
||||
directories = "5.0.1"
|
||||
toml = "0.8.19"
|
||||
serde = { version = "1.0.209", features = ["derive"] }
|
||||
thiserror = "1.0.63"
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
thiserror = "1.0.64"
|
||||
notify-debouncer-mini = "0.4.1"
|
||||
notify = "6.1.1"
|
||||
palette = "0.7.6"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Maintainer: Alex Janka <alex@alexjanka.com>
|
||||
|
||||
pkgname=sway-flash-indicator
|
||||
pkgver=0.5.1
|
||||
pkgver=0.5.2
|
||||
pkgrel=1
|
||||
pkgdesc="flashes sway indicator border rather than always showing it"
|
||||
arch=('x86_64' 'aarch64')
|
||||
|
|
|
@ -12,6 +12,7 @@ pub struct Config {
|
|||
pub flash_colour: colour::Format,
|
||||
pub autosplit_enabled: bool,
|
||||
pub autosplit_ratio: f64,
|
||||
pub force_tabbed: Vec<String>,
|
||||
pub output_blocklist: Vec<String>,
|
||||
#[serde(default = "default_log_dir")]
|
||||
pub log_dir: std::path::PathBuf,
|
||||
|
@ -130,6 +131,7 @@ impl Default for Config {
|
|||
flash_colour: colour::parse_hex("#ff0000").unwrap(),
|
||||
autosplit_enabled: true,
|
||||
autosplit_ratio: 1.0,
|
||||
force_tabbed: Vec::new(),
|
||||
output_blocklist: Vec::new(),
|
||||
log_dir: std::path::PathBuf::new(),
|
||||
}
|
||||
|
|
64
src/main.rs
64
src/main.rs
|
@ -61,12 +61,49 @@ async fn main() -> Res<()> {
|
|||
log::warn!("error {e:?}");
|
||||
}
|
||||
}));
|
||||
} else if binding.command.starts_with("focus parent") {
|
||||
let tree = command_connection.get_tree().await?;
|
||||
|
||||
if let Some(node) = tree.find_focused_as_ref(|n| {
|
||||
n.focused && n.node_type == swayipc_async::NodeType::Con
|
||||
}) {
|
||||
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;
|
||||
if let Err(e) = if ratio > autosplit_ratio {
|
||||
command_connection.run_command("splith").await
|
||||
} else {
|
||||
command_connection.run_command("splitv").await
|
||||
} {
|
||||
log::warn!("error {e:?} setting split");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
swayipc_async::Event::Window(window)
|
||||
if window.change != swayipc_async::WindowChange::Mark =>
|
||||
{
|
||||
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| {
|
||||
config
|
||||
.force_tabbed
|
||||
.iter()
|
||||
.any(|name| name.eq_ignore_ascii_case(app_id))
|
||||
})
|
||||
{
|
||||
if let Some(parent) = tree.clone().find(|n| n.focus.contains(&node.id)) {
|
||||
if parent.layout != swayipc_async::NodeLayout::Tabbed {
|
||||
command_connection.run_command("splith").await?;
|
||||
command_connection.run_command("layout tabbed").await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if window.change == swayipc_async::WindowChange::New
|
||||
&& node.app_id == Some(String::from("code-url-handler"))
|
||||
|
@ -84,6 +121,7 @@ async fn main() -> Res<()> {
|
|||
recent_code = None;
|
||||
log::info!("focused the window we want with id {id}");
|
||||
if let Err(e) = code_trigger(
|
||||
tree,
|
||||
&mut command_connection,
|
||||
id,
|
||||
&CONFIG.get().await.output_blocklist,
|
||||
|
@ -99,7 +137,14 @@ async fn main() -> Res<()> {
|
|||
// 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 {
|
||||
if !config.autosplit_enabled
|
||||
|| config.force_tabbed.iter().any(|blocked| {
|
||||
node.app_id
|
||||
.as_ref()
|
||||
.map(|v| blocked.eq_ignore_ascii_case(v))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let (width, height) = (node.window_rect.width, node.window_rect.height);
|
||||
|
@ -129,15 +174,15 @@ async fn main() -> Res<()> {
|
|||
}
|
||||
|
||||
async fn code_trigger<T: AsRef<str> + std::cmp::PartialEq<str>>(
|
||||
tree: swayipc_async::Node,
|
||||
connection: &mut swayipc_async::Connection,
|
||||
id: i64,
|
||||
output_blocklist: &[T],
|
||||
) -> Res<()> {
|
||||
let tree = connection.get_tree().await?;
|
||||
|
||||
for workspace in connection.get_workspaces().await? {
|
||||
let width = workspace.rect.width;
|
||||
if workspace.focused {
|
||||
let width = workspace.rect.width;
|
||||
|
||||
let mut workspace = get_with_id(&tree, workspace.id)?;
|
||||
if workspace
|
||||
.output
|
||||
|
@ -150,7 +195,16 @@ async fn code_trigger<T: AsRef<str> + std::cmp::PartialEq<str>>(
|
|||
while workspace.focus.len() == 1 {
|
||||
workspace = get_with_id(workspace, workspace.focus[0])?;
|
||||
}
|
||||
if workspace.layout == swayipc_async::NodeLayout::SplitH && workspace.focus.len() == 2 {
|
||||
if workspace.layout == swayipc_async::NodeLayout::Tabbed {
|
||||
for _ in 0..workspace.nodes.len() {
|
||||
connection.run_command("move left").await?;
|
||||
}
|
||||
connection
|
||||
.run_command(format!("resize set width {}px", width - 1220))
|
||||
.await?;
|
||||
} else if workspace.layout == swayipc_async::NodeLayout::SplitH
|
||||
&& workspace.focus.len() == 2
|
||||
{
|
||||
let (code, other) = {
|
||||
let a = get_with_id(&tree, workspace.focus[0])?;
|
||||
let b = get_with_id(&tree, workspace.focus[1])?;
|
||||
|
|
Loading…
Reference in a new issue