From 216500b708a3dcf86e7c731e5714bad16c633417 Mon Sep 17 00:00:00 2001 From: Milosz Blizniak Date: Sun, 7 Dec 2025 21:39:04 +0100 Subject: [PATCH 1/3] feat(rs): fall back to sway socket Wayland seems to be constructed in such a way to preserve compatibility with i3. Which is awesome, because just by getting the socket from sway, we can treat sway exactly the same as i3. So i3 mode should support sway without any real changes. And seems to do so. --- rust/src/backend/i3/backend.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rust/src/backend/i3/backend.rs b/rust/src/backend/i3/backend.rs index 48d3a11..add4498 100644 --- a/rust/src/backend/i3/backend.rs +++ b/rust/src/backend/i3/backend.rs @@ -1,5 +1,6 @@ use crate::backend::traits::*; use crate::logging::ResultExt; +use crate::logging::OptionExt; use crate::logging; use crate::types::Windows; use super::client::{Client, Request}; @@ -13,14 +14,18 @@ pub struct Backend { root: json::Value, } +fn get_sock_path(executable: &str) -> Option { + process::Command::new(executable).arg("--get-socketpath").output() + .ok().filter(|o| o.status.success()).and_then(|o| String::from_utf8(o.stdout).ok()) + .map(|s| s.trim().to_owned()).filter(|s| !s.is_empty()) +} + impl Backend { pub fn new() -> Self { // Establish a connection to the i3 IPC server and get the tree structure - let i3_socket_path_output = process::Command::new("i3").arg("--get-socketpath").output() - .expect_log("Failed to get i3 socket path"); - let i3_path = String::from_utf8(i3_socket_path_output.stdout) - .expect_log("Failed to parse i3 socket path output"); - let mut client = Client::new(&i3_path.trim()) + let socket_path = get_sock_path("i3").or_else(|| get_sock_path("sway")) + .wanted("Failed to get socket path from i3 or sway").unwrap_or_default(); + let mut client = Client::new(&socket_path.trim()) .expect_log("Failed to connect to i3 IPC server"); let root_string = client.request(Request::GetTree, "") .expect_log("Failed to get i3 tree JSON"); From 215517f36cf0dbed1fa2346b0142817c5ea4db11 Mon Sep 17 00:00:00 2001 From: Milosz Blizniak Date: Sun, 7 Dec 2025 22:00:43 +0100 Subject: [PATCH 2/3] feat(rs): get socket paths asynchronously --- rust/src/backend/i3/backend.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rust/src/backend/i3/backend.rs b/rust/src/backend/i3/backend.rs index add4498..df95e5b 100644 --- a/rust/src/backend/i3/backend.rs +++ b/rust/src/backend/i3/backend.rs @@ -8,6 +8,7 @@ use super::compass; use serde_json as json; use std::process; +use std::thread; pub struct Backend { client: Client, @@ -20,10 +21,17 @@ fn get_sock_path(executable: &str) -> Option { .map(|s| s.trim().to_owned()).filter(|s| !s.is_empty()) } +fn get_sock_path_async() -> Option { + thread::scope(|s| { + ["i3", "sway"].iter().map(|&bin| s.spawn(move || get_sock_path(bin))) + .find_map(|h| h.join().unwrap_or(None)) + }) +} + impl Backend { pub fn new() -> Self { // Establish a connection to the i3 IPC server and get the tree structure - let socket_path = get_sock_path("i3").or_else(|| get_sock_path("sway")) + let socket_path = get_sock_path_async() .wanted("Failed to get socket path from i3 or sway").unwrap_or_default(); let mut client = Client::new(&socket_path.trim()) .expect_log("Failed to connect to i3 IPC server"); From 8a17efe603dd751410d9039073a601d104a01dde Mon Sep 17 00:00:00 2001 From: Milosz Blizniak Date: Sun, 7 Dec 2025 22:03:01 +0100 Subject: [PATCH 3/3] chore(rs): add notice about sway support --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e4b375c..1161de8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ abstraction of the manual tiling structure. For more history and motivation, see [history.md](docs/history.md). +## Sway + +Since sway is mostly compatible with i3, rust version supports sway in i3 mode, by using +sway socket for i3 IPC. + ## Preview Preview demonstrates directional switching (without touching active tabs) and tab navigation