From 86d9e9264d6d068953e6177afd198e49c0e98e30 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 8 May 2022 22:07:26 -0700 Subject: [PATCH] Implement a different GNOME protocol with title --- src/client/gnome_client.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/client/gnome_client.rs b/src/client/gnome_client.rs index 75b7fbd..ee0c3c7 100644 --- a/src/client/gnome_client.rs +++ b/src/client/gnome_client.rs @@ -1,4 +1,5 @@ use crate::client::Client; +use serde::{Deserialize, Serialize}; use zbus::Connection; pub struct GnomeClient { @@ -31,7 +32,21 @@ impl Client for GnomeClient { None => return None, }; + // Attempt the latest protocol if let Ok(message) = connection.call_method( + Some("org.gnome.Shell"), + "/com/k0kubun/Xremap", + Some("com.k0kubun.Xremap"), + "ActiveWindow", + &(), + ) { + if let Ok(json) = message.body::() { + if let Ok(window) = serde_json::from_str::(&json) { + return Some(window.wm_class); + } + } + // Fallback to the legacy protocol + } else if let Ok(message) = connection.call_method( Some("org.gnome.Shell"), "/com/k0kubun/Xremap", Some("com.k0kubun.Xremap"), @@ -45,3 +60,11 @@ impl Client for GnomeClient { None } } + +#[derive(Serialize, Deserialize)] +struct ActiveWindow { + #[serde(default)] + wm_class: String, + #[serde(default)] + title: String, +}