Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions rust/src/backend/i3/backend.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
use crate::backend::traits::*;
use crate::logging::ResultExt;
use crate::logging::OptionExt;
use crate::logging;
use crate::types::Windows;
use super::client::{Client, Request};
use super::compass;

use serde_json as json;
use std::process;
use std::thread;

pub struct Backend {
client: Client,
root: json::Value,
}

fn get_sock_path(executable: &str) -> Option<String> {
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())
}

fn get_sock_path_async() -> Option<String> {
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 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_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");
let root_string = client.request(Request::GetTree, "")
.expect_log("Failed to get i3 tree JSON");
Expand Down
Loading