|
|
@ -16,6 +16,7 @@ |
|
|
|
//! The window `swayrbar` module.
|
|
|
|
//! The window `swayrbar` module.
|
|
|
|
|
|
|
|
|
|
|
|
use crate::bar::module::BarModuleFn; |
|
|
|
use crate::bar::module::BarModuleFn; |
|
|
|
|
|
|
|
use crate::fmt_replace::fmt_replace; |
|
|
|
use crate::ipc; |
|
|
|
use crate::ipc; |
|
|
|
use crate::ipc::NodeMethods; |
|
|
|
use crate::ipc::NodeMethods; |
|
|
|
use swaybar_types as s; |
|
|
|
use swaybar_types as s; |
|
|
@ -40,14 +41,22 @@ impl BarModuleFn for BarModuleWindow { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build(&self) -> s::Block { |
|
|
|
fn build(&self) -> s::Block { |
|
|
|
|
|
|
|
let fmt = "🪟 {title} — {app_name}"; |
|
|
|
let root = ipc::get_root_node(false); |
|
|
|
let root = ipc::get_root_node(false); |
|
|
|
let focused_win = root.iter().find(|n| n.focused); |
|
|
|
let focused_win = root |
|
|
|
let app_name = focused_win.map_or("", |w| w.get_app_name()); |
|
|
|
.iter() |
|
|
|
let title = focused_win.map_or("", |w| w.get_name()); |
|
|
|
.find(|n| n.focused && n.get_type() == ipc::Type::Window); |
|
|
|
|
|
|
|
let text = match focused_win { |
|
|
|
|
|
|
|
Some(win) => fmt_replace!(&fmt, false, { |
|
|
|
|
|
|
|
"title" |"name" => win.get_name(), |
|
|
|
|
|
|
|
"app_name" => win.get_app_name(), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
None => String::new(), |
|
|
|
|
|
|
|
}; |
|
|
|
s::Block { |
|
|
|
s::Block { |
|
|
|
name: Some(Self::name()), |
|
|
|
name: Some(Self::name()), |
|
|
|
instance: Some(self.instance.clone()), |
|
|
|
instance: Some(self.instance.clone()), |
|
|
|
full_text: "🪟 ".to_string() + title + " — " + app_name, |
|
|
|
full_text: text, |
|
|
|
align: Some(s::Align::Left), |
|
|
|
align: Some(s::Align::Left), |
|
|
|
markup: Some(s::Markup::Pango), |
|
|
|
markup: Some(s::Markup::Pango), |
|
|
|
short_text: None, |
|
|
|
short_text: None, |
|
|
|