Improve window bar module

main
Tassilo Horn 3 years ago
parent 5d1fbeba06
commit 160b7d645c
  1. 6
      src/bar/module/battery.rs
  2. 17
      src/bar/module/window.rs
  3. 2
      src/fmt_replace.rs

@ -85,12 +85,12 @@ impl BarModuleFn for BarModuleBattery {
fn build(&self) -> s::Block {
let fmt =
"🔋 Bat: {state_of_charge:{:5.1}}% {state} Health: {state_of_health:{:5.1}}%";
let s = get_text(&self.manager, fmt);
"🔋 Bat: {state_of_charge:{:5.1}}%, {state}, Health: {state_of_health:{:5.1}}%";
let text = get_text(&self.manager, fmt);
s::Block {
name: Some(Self::name()),
instance: Some(self.instance.clone()),
full_text: s,
full_text: text,
align: Some(s::Align::Right),
markup: Some(s::Markup::Pango),
short_text: None,

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

@ -41,7 +41,7 @@ macro_rules! fmt_replace {
.replace_all($fmt_str, |caps: &regex::Captures| {
let value: String = match &caps["name"] {
$(
$( | $pat )+ => {
$( $pat )|+ => {
let val = $crate::rtfmt::FmtArg::from($exp);
let fmt_str = caps.name("fmtstr")
.map_or("{}", |m| m.as_str());

Loading…
Cancel
Save