From 75b5699785c4bb7018f5b3a0207596c32b92021b Mon Sep 17 00:00:00 2001 From: cyber-sushi Date: Thu, 9 May 2024 18:36:08 +0200 Subject: [PATCH] Get active window on Hyprland using subprocess instead of relying on external library --- src/active_client.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/active_client.rs b/src/active_client.rs index 5ccc99e..c88c30b 100644 --- a/src/active_client.rs +++ b/src/active_client.rs @@ -1,20 +1,23 @@ use crate::Config; -use hyprland::{data::Client, prelude::*}; +use serde_json; use swayipc_async::Connection; -use std::collections::HashMap; +use std::{collections::HashMap, process::Command}; use x11rb::protocol::xproto::{get_property, get_input_focus, Atom, AtomEnum}; pub async fn get_active_window(current_desktop: &Option, config: &HashMap) -> String { let active_client = current_desktop.clone().unwrap_or(String::from("default")); match active_client.as_str() { "Hyprland" => { - let active_window: String = match Client::get_active_async().await.unwrap() { - Some(window) => window.class, - None => String::from("default") - }; - if config.contains_key(&active_window) { - active_window + let query = Command::new("hyprctl").args(["activewindow", "-j"]).output().unwrap(); + if let Ok(reply) = serde_json::from_str::(std::str::from_utf8(query.stdout.as_slice()).unwrap()) { + let active_window = reply["class"].to_string().replace("\"", ""); + if config.contains_key(&active_window) { + active_window + } else { + String::from("default") + } } else { + println!("Unable to connect to the compositor. Running without user environment?"); String::from("default") } }, @@ -61,3 +64,4 @@ pub async fn get_active_window(current_desktop: &Option, config: &HashMa _ => String::from("default") } } +