Use Server enum instead of Option to match compositor
This commit is contained in:
parent
c19357d0b8
commit
31c1b1ce44
1 changed files with 60 additions and 53 deletions
|
@ -1,23 +1,26 @@
|
||||||
use crate::Config;
|
use crate::Config;
|
||||||
|
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::{collections::HashMap, 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(current_desktop: &Option<String>, config: &HashMap<String, Config>) -> String {
|
pub async fn get_active_window(server: &Server, config: &HashMap<Client, Config>) -> Client {
|
||||||
let active_client = current_desktop.clone().unwrap_or(String::from("default"));
|
match server {
|
||||||
match active_client.as_str() {
|
Server::Connected(server) => {
|
||||||
|
let server_str = server.as_str();
|
||||||
|
match server_str {
|
||||||
"Hyprland" => {
|
"Hyprland" => {
|
||||||
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 = reply["class"].to_string().replace("\"", "");
|
let active_window = Client::Class(reply["class"].to_string().replace("\"", ""));
|
||||||
if config.contains_key(&active_window) {
|
if config.contains_key(&active_window) {
|
||||||
active_window
|
active_window
|
||||||
} else {
|
} else {
|
||||||
String::from("default")
|
Client::Default
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String::from("default")
|
Client::Default
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sway" => {
|
"sway" => {
|
||||||
|
@ -25,16 +28,16 @@ pub async fn get_active_window(current_desktop: &Option<String>, config: &HashMa
|
||||||
let active_window = match connection.get_tree().await.unwrap().find_focused(|window| window.focused) {
|
let active_window = match connection.get_tree().await.unwrap().find_focused(|window| window.focused) {
|
||||||
Some(window) => {
|
Some(window) => {
|
||||||
match window.app_id {
|
match window.app_id {
|
||||||
Some(id) => id,
|
Some(id) => Client::Class(id),
|
||||||
None => window.window_properties.unwrap().class.unwrap()
|
None => Client::Class(window.window_properties.unwrap().class.unwrap())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => String::from("default")
|
None => Client::Default
|
||||||
};
|
};
|
||||||
if config.contains_key(&active_window) {
|
if config.contains_key(&active_window) {
|
||||||
active_window
|
active_window
|
||||||
} else {
|
} else {
|
||||||
String::from("default")
|
Client::Default
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x11" => {
|
"x11" => {
|
||||||
|
@ -50,17 +53,21 @@ pub async fn get_active_window(current_desktop: &Option<String>, config: &HashMa
|
||||||
if class.last() == Some(&0) {
|
if class.last() == Some(&0) {
|
||||||
class = &class[..class.len() -1];
|
class = &class[..class.len() -1];
|
||||||
}
|
}
|
||||||
let active_window = 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 config.contains_key(&active_window) {
|
||||||
active_window
|
active_window
|
||||||
} else {
|
} else {
|
||||||
String::from("default")
|
Client::Default
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String::from("default")
|
Client::Default
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => String::from("default")
|
_ => Client::Default
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Server::Unsupported => Client::Default,
|
||||||
|
Server::Failed => Client::Default,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue