From e75c0bae09baf6f1fad8e08fa645e06b251975cf Mon Sep 17 00:00:00 2001 From: Yavor Kolev Date: Sat, 18 Feb 2023 23:23:12 -0800 Subject: [PATCH] Update Hyprland-rs to `0.3.0` (#247) * Update Hyprland-rs * Remove needless serialize and deserializing * Remove needless conversion of string --- Cargo.lock | 58 +++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- src/client/hypr_client.rs | 12 +++----- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dc1033..5a81be0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,6 +45,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "async-trait" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atty" version = "0.2.14" @@ -255,6 +266,12 @@ dependencies = [ "syn", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "enumflags2" version = "0.6.4" @@ -511,16 +528,22 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyprland" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff61dd8ab0043641e915ba16d0650e73fd56b32aaf9a031d3d2a297b92d0cb2e" +checksum = "0f76d4dad14a688266c346a9233e8cc5cea0c31a489d8811e3d93176338bafc0" dependencies = [ + "async-trait", + "doc-comment", "hex", "lazy_static", + "num-traits", + "paste", "regex", "serde", "serde_json", "serde_repr", + "strum", + "strum_macros", "tokio", ] @@ -822,6 +845,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "paste" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -954,6 +983,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" + [[package]] name = "ryu" version = "1.0.10" @@ -1098,6 +1133,25 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "swayipc" version = "3.0.1" diff --git a/Cargo.toml b/Cargo.toml index e2278b4..2aba38e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde_yaml = "0.9" swayipc = { version = "3.0.1", optional = true } x11rb = { version = "0.11.0", optional = true } zbus = { version = "1.9.2", optional = true } -hyprland = { version = "0.2.4", optional = true } +hyprland = { version = "0.3.0", optional = true } [features] gnome = ["zbus"] diff --git a/src/client/hypr_client.rs b/src/client/hypr_client.rs index 46f7085..89b31db 100644 --- a/src/client/hypr_client.rs +++ b/src/client/hypr_client.rs @@ -1,6 +1,5 @@ use crate::client::Client; -use hyprland::data::blocking::get_active_window; -use serde_json::Value; +use hyprland::{data::Client as HyprClient, prelude::*}; pub struct HyprlandClient; impl HyprlandClient { @@ -15,12 +14,9 @@ impl Client for HyprlandClient { } fn current_application(&mut self) -> Option { - if let Ok(win) = get_active_window() { - let s = serde_json::to_string(&win).ok()?; - let v: Value = serde_json::from_str(&s).ok()?; - let app = v["class"].as_str(); - if let Some(app) = app { - return Some(String::from(app)); + if let Ok(win_opt) = HyprClient::get_active() { + if let Some(win) = win_opt { + return Some(win.class); } } None