diff --git a/Cargo.lock b/Cargo.lock index c289657..9f2358d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,12 +40,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - [[package]] name = "cairo-rs" version = "0.14.9" @@ -111,11 +105,11 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.0.0" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1b9752c030a14235a0bd5ef3ad60a1dcac8468c30921327fc8af36b20c790b9" +checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" dependencies = [ - "heck", + "heck 0.4.0", "proc-macro-error", "proc-macro2", "quote", @@ -124,9 +118,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.46" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b858541263efe664aead4a5209a4ae5c5d2811167d4ed4ee0944503f8d2089" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" dependencies = [ "cc", ] @@ -263,24 +257,24 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" [[package]] name = "futures-executor" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97" +checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" dependencies = [ "futures-core", "futures-task", @@ -289,15 +283,15 @@ dependencies = [ [[package]] name = "futures-task" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" [[package]] name = "futures-util" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" dependencies = [ "futures-core", "futures-task", @@ -332,7 +326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" dependencies = [ "anyhow", - "heck", + "heck 0.3.3", "proc-macro-crate", "proc-macro-error", "proc-macro2", @@ -376,6 +370,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -394,23 +394,11 @@ dependencies = [ "quick-error", ] -[[package]] -name = "i3ipc" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63f3dac00c473fae88cb3114f35312204469a32ffb20874264a5214d6c8c927e" -dependencies = [ - "byteorder", - "log", - "serde", - "serde_json", -] - [[package]] name = "indexmap" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" dependencies = [ "autocfg", "hashbrown", @@ -427,9 +415,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "lazy_static" @@ -445,9 +433,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.109" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "log" @@ -466,9 +454,9 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "os_str_bytes" @@ -481,9 +469,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "pin-utils" @@ -493,9 +481,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.23" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1a3ea4f0dd7f1f3e512cf97bf100819aa547f36a6eccac8dbaae839eb92363e" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" [[package]] name = "pretty_env_logger" @@ -543,9 +531,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] @@ -567,9 +555,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -593,21 +581,35 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "ryu" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "serde" -version = "1.0.131" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ad69dfbd3e45369132cc64e6748c2d65cdfb001a2b1c232d128b4ad60561c1" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" -version = "1.0.72" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ "itoa", "ryu", @@ -643,9 +645,9 @@ checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "strsim" @@ -665,17 +667,39 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro2", "quote", "syn", ] +[[package]] +name = "swayipc" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40cc7e2bba9f31e7c46b119d9c542496806b9114676d8f46aa5c9c950ececaec" +dependencies = [ + "serde", + "serde_json", + "swayipc-types", +] + +[[package]] +name = "swayipc-types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d63c88513504fd598a6c2218bd83d19e1f8cc6dd1a9892f2f982b223f01a803" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "syn" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -690,7 +714,7 @@ checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6" dependencies = [ "anyhow", "cfg-expr", - "heck", + "heck 0.3.3", "itertools", "pkg-config", "strum", @@ -777,9 +801,9 @@ checksum = "1c18c859eead79d8b95d09e4678566e8d70105c4e7b251f707a03df32442661b" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "winapi" @@ -822,11 +846,11 @@ dependencies = [ "clap", "css-color-parser", "font-loader", - "i3ipc", "itertools", "log", "pretty_env_logger", "regex", + "swayipc", "x11", "xcb", "xcb-util", diff --git a/Cargo.toml b/Cargo.toml index 77c1c24..bc3d878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,14 @@ lto = true codegen-units = 1 [features] -i3 = ["i3ipc"] +i3 = ["swayipc"] [dependencies] cairo-sys-rs = "0.14" css-color-parser = "0.1" font-loader = "0.11" -i3ipc = { version = "0.10", optional = true } itertools = "0.10" +swayipc = { version = "3.0.0", optional = true } log = "0.4" pretty_env_logger = "0.4" regex = "1.5" diff --git a/src/main.rs b/src/main.rs index 6bf4006..8f62777 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,6 @@ use xkbcommon::xkb; mod args; mod utils; -#[cfg(feature = "i3")] -extern crate i3ipc; - #[cfg(feature = "i3")] mod wm_i3; @@ -20,7 +17,7 @@ use crate::wm_i3 as wm; #[derive(Debug)] pub struct DesktopWindow { id: i64, - x_window_id: Option, + x_window_id: Option, pos: (i32, i32), size: (i32, i32), is_focused: bool, diff --git a/src/wm_i3.rs b/src/wm_i3.rs index e5de27a..9142d29 100644 --- a/src/wm_i3.rs +++ b/src/wm_i3.rs @@ -1,7 +1,6 @@ use anyhow::{Context, Result}; -use i3ipc::reply::{Node, NodeLayout, NodeType, Workspace}; -use i3ipc::I3Connection; use log::{debug, info}; +use swayipc::{Connection, Node, NodeLayout, NodeType, Workspace}; use crate::DesktopWindow; @@ -43,7 +42,7 @@ fn find_parent_of<'a>(start_node: &'a Node, child: &'a Node) -> Option<&'a Node> /// Return a list of all `DesktopWindow`s for the given `Workspace`. fn crawl_windows(root_node: &Node, workspace: &Workspace) -> Result> { let workspace_node = find_first_node_with_attr(root_node, |x| { - x.name == Some(workspace.name.clone()) && x.nodetype == NodeType::Workspace + x.name == Some(workspace.name.clone()) && x.node_type == NodeType::Workspace }) .context("Couldn't find the Workspace node")?; @@ -55,39 +54,38 @@ fn crawl_windows(root_node: &Node, workspace: &Workspace) -> Result Result Result> { - // Establish a connection to i3 over a unix socket - let mut connection = I3Connection::connect().context("Couldn't acquire i3 connection")?; + // Establish a connection to Sway or i3 over a Unix socket + let mut connection = Connection::new().expect("Couldn't acquire Sway/i3 IPC connection"); let workspaces = connection .get_workspaces() - .context("Problem communicating with i3")? - .workspaces; + .expect("Problem communicating with IPC"); let visible_workspaces = workspaces.iter().filter(|w| w.visible); let root_node = connection.get_tree()?; let mut windows = vec![]; @@ -113,7 +110,7 @@ pub fn get_windows() -> Result> { /// Focus a specific `window`. pub fn focus_window(window: &DesktopWindow) -> Result<()> { - let mut connection = I3Connection::connect().context("Couldn't acquire i3 connection")?; + let mut connection = Connection::new().expect("Couldn't acquire Sway/i3 connection"); let command_str = format!("[con_id=\"{}\"] focus", window.id); let command = connection .run_command(&command_str)