Check if associated config file exists by matching config properties instead of hashing

This commit is contained in:
cyber-sushi 2024-05-29 06:08:36 +02:00
parent 955eac92e9
commit 46cdd0346a

View file

@ -2,10 +2,10 @@ use crate::Config;
use crate::udev_monitor::{Client, Server}; use crate::udev_monitor::{Client, Server};
use serde_json; use serde_json;
use swayipc_async::Connection; use swayipc_async::Connection;
use std::{collections::HashMap, process::Command}; use std::process::Command;
use x11rb::protocol::xproto::{get_property, get_input_focus, Atom, AtomEnum}; use x11rb::protocol::xproto::{get_property, get_input_focus, Atom, AtomEnum};
pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>) -> Client { pub async fn get_active_window(server: &Server, config: &Vec<Config>) -> Client {
match server { match server {
Server::Connected(server) => { Server::Connected(server) => {
let server_str = server.as_str(); let server_str = server.as_str();
@ -14,7 +14,7 @@ pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>
let query = Command::new("hyprctl").args(["activewindow", "-j"]).output().unwrap(); let query = Command::new("hyprctl").args(["activewindow", "-j"]).output().unwrap();
if let Ok(reply) = serde_json::from_str::<serde_json::Value>(std::str::from_utf8(query.stdout.as_slice()).unwrap()) { if let Ok(reply) = serde_json::from_str::<serde_json::Value>(std::str::from_utf8(query.stdout.as_slice()).unwrap()) {
let active_window = Client::Class(reply["class"].to_string().replace("\"", "")); let active_window = Client::Class(reply["class"].to_string().replace("\"", ""));
if config.contains_key(&active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window ) {
active_window active_window
} else { } else {
Client::Default Client::Default
@ -34,7 +34,7 @@ pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>
}, },
None => Client::Default None => Client::Default
}; };
if config.contains_key(&active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window ) {
active_window active_window
} else { } else {
Client::Default Client::Default
@ -43,7 +43,7 @@ pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>
"KDE" => { "KDE" => {
if let Ok(query) = Command::new("sh").arg("c").arg("kdotool getactivewindow getwindowclassname").output() { if let Ok(query) = Command::new("sh").arg("c").arg("kdotool getactivewindow getwindowclassname").output() {
let active_window = Client::Class(std::str::from_utf8(query.stdout.as_slice()).unwrap().trim().to_string()); let active_window = Client::Class(std::str::from_utf8(query.stdout.as_slice()).unwrap().trim().to_string());
if config.contains_key(&active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window ) {
active_window active_window
} else { } else {
Client::Default Client::Default
@ -66,7 +66,7 @@ pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>
class = &class[..class.len() -1]; class = &class[..class.len() -1];
} }
let active_window = Client::Class(std::str::from_utf8(class).unwrap().to_string()); let active_window = Client::Class(std::str::from_utf8(class).unwrap().to_string());
if config.contains_key(&active_window) { if let Some(_) = config.iter().find(|&x| x.associations.client == active_window ) {
active_window active_window
} else { } else {
Client::Default Client::Default