1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

Merge pull request #623 from JakeStanger/revert-621-fix/markup-escape

Revert "Fix Pango markup not escaped"
This commit is contained in:
Jake Stanger 2024-06-02 17:42:39 +01:00 committed by GitHub
commit 5d1054abd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 23 additions and 40 deletions

View file

@ -22,7 +22,7 @@ enum DynamicStringSegment {
/// ///
/// ```rs /// ```rs
/// dynamic_string(&text, move |string| { /// dynamic_string(&text, move |string| {
/// label.set_markup_escaped(&string); /// label.set_markup(&string);
/// }); /// });
/// ``` /// ```
pub fn dynamic_string<F>(input: &str, mut f: F) pub fn dynamic_string<F>(input: &str, mut f: F)

View file

@ -1,6 +1,6 @@
use glib::{markup_escape_text, IsA}; use glib::IsA;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Label, Orientation, Widget}; use gtk::{Orientation, Widget};
/// Represents a widget's size /// Represents a widget's size
/// and location relative to the bar's start edge. /// and location relative to the bar's start edge.
@ -75,16 +75,3 @@ impl<W: IsA<Widget>> IronbarGtkExt for W {
unsafe { self.set_data(key, value) } unsafe { self.set_data(key, value) }
} }
} }
pub trait IronbarLabelExt {
/// Sets a label's pango markup, escaping it in the process.
/// This should be used for any label values
/// which could contain special characters, for example `&`.
fn set_markup_escaped(&self, text: &str);
}
impl IronbarLabelExt for Label {
fn set_markup_escaped(&self, text: &str) {
self.set_markup(markup_escape_text(text).as_str())
}
}

View file

@ -9,7 +9,7 @@ use tokio::sync::{broadcast, mpsc};
use tokio::time::sleep; use tokio::time::sleep;
use crate::config::{CommonConfig, ModuleOrientation}; use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{ use crate::modules::{
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
}; };
@ -143,7 +143,7 @@ impl Module<Button> for ClockModule {
let rx = context.subscribe(); let rx = context.subscribe();
glib_recv!(rx, date => { glib_recv!(rx, date => {
let date_string = format!("{}", date.format_localized(&format, locale)); let date_string = format!("{}", date.format_localized(&format, locale));
label.set_markup_escaped(&date_string); label.set_label(&date_string);
}); });
let popup = self let popup = self

View file

@ -4,7 +4,6 @@ use serde::Deserialize;
use crate::config::ModuleOrientation; use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use crate::gtk_helpers::IronbarLabelExt;
use crate::modules::PopupButton; use crate::modules::PopupButton;
use crate::{build, try_send}; use crate::{build, try_send};
@ -76,7 +75,7 @@ impl CustomWidget for ButtonWidget {
button.add(&label); button.add(&label);
dynamic_string(&text, move |string| { dynamic_string(&text, move |string| {
label.set_markup_escaped(&string); label.set_markup(&string);
}); });
} }

View file

@ -5,7 +5,6 @@ use serde::Deserialize;
use crate::build; use crate::build;
use crate::config::ModuleOrientation; use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use crate::gtk_helpers::IronbarLabelExt;
use super::{CustomWidget, CustomWidgetContext}; use super::{CustomWidget, CustomWidgetContext};
@ -51,7 +50,7 @@ impl CustomWidget for LabelWidget {
{ {
let label = label.clone(); let label = label.clone();
dynamic_string(&self.label, move |string| { dynamic_string(&self.label, move |string| {
label.set_markup_escaped(&string); label.set_markup(&string);
}); });
} }

View file

@ -165,7 +165,7 @@ impl Module<gtk::Box> for FocusedModule {
if self.show_title { if self.show_title {
label.show(); label.show();
label.set_text(&name); label.set_label(&name);
} }
} else { } else {
icon.hide(); icon.hide();

View file

@ -1,6 +1,5 @@
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use crate::gtk_helpers::IronbarLabelExt;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
use crate::{glib_recv, module_impl, try_send}; use crate::{glib_recv, module_impl, try_send};
use color_eyre::Result; use color_eyre::Result;
@ -62,7 +61,7 @@ impl Module<Label> for LabelModule {
{ {
let label = label.clone(); let label = label.clone();
glib_recv!(context.subscribe(), string => label.set_markup_escaped(&string)); glib_recv!(context.subscribe(), string => label.set_markup(&string));
} }
Ok(ModuleParts { Ok(ModuleParts {

View file

@ -5,7 +5,7 @@ use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use color_eyre::Result; use color_eyre::Result;
use glib::{markup_escape_text, Propagation, PropertySet}; use glib::{Propagation, PropertySet};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Button, IconTheme, Label, Orientation, Scale}; use gtk::{Button, IconTheme, Label, Orientation, Scale};
use regex::Regex; use regex::Regex;
@ -16,7 +16,7 @@ use crate::clients::music::{
self, MusicClient, PlayerState, PlayerUpdate, ProgressTick, Status, Track, self, MusicClient, PlayerState, PlayerUpdate, ProgressTick, Status, Track,
}; };
use crate::clients::Clients; use crate::clients::Clients;
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::gtk_helpers::IronbarGtkExt;
use crate::image::{new_icon_button, new_icon_label, ImageProvider}; use crate::image::{new_icon_button, new_icon_label, ImageProvider};
use crate::modules::PopupButton; use crate::modules::PopupButton;
use crate::modules::{ use crate::modules::{
@ -222,7 +222,7 @@ impl Module<Button> for MusicModule {
}; };
if let Some(event) = event.take() { if let Some(event) = event.take() {
label.set_markup_escaped(&event.display_string); label.set_label(&event.display_string);
button.show(); button.show();
@ -473,7 +473,7 @@ impl Module<Button> for MusicModule {
if let (Some(elapsed), Some(duration)) = if let (Some(elapsed), Some(duration)) =
(progress_tick.elapsed, progress_tick.duration) (progress_tick.elapsed, progress_tick.duration)
{ {
progress_label.set_text(&format!( progress_label.set_label(&format!(
"{}/{}", "{}/{}",
format_time(elapsed), format_time(elapsed),
format_time(duration) format_time(duration)
@ -549,7 +549,7 @@ impl IconLabel {
let mut builder = Label::builder().use_markup(true); let mut builder = Label::builder().use_markup(true);
if let Some(label) = label { if let Some(label) = label {
builder = builder.label(markup_escape_text(label)); builder = builder.label(label);
} }
let label = builder.build(); let label = builder.build();

View file

@ -210,7 +210,7 @@ impl Module<Overlay> for NotificationsModule {
let icon = self.icons.icon(ev); let icon = self.icons.icon(ev);
button.set_label(icon); button.set_label(icon);
label.set_text(&ev.count.to_string()); label.set_label(&ev.count.to_string());
label.set_visible(self.show_count && ev.count > 0); label.set_visible(self.show_count && ev.count > 0);
}); });
} }

View file

@ -1,5 +1,4 @@
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::gtk_helpers::IronbarLabelExt;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
use crate::script::{OutputStream, Script, ScriptMode}; use crate::script::{OutputStream, Script, ScriptMode};
use crate::{glib_recv, module_impl, spawn, try_send}; use crate::{glib_recv, module_impl, spawn, try_send};
@ -104,7 +103,7 @@ impl Module<Label> for ScriptModule {
{ {
let label = label.clone(); let label = label.clone();
glib_recv!(context.subscribe(), s => label.set_markup_escaped(s.as_str())); glib_recv!(context.subscribe(), s => label.set_markup(s.as_str()));
} }
Ok(ModuleParts { Ok(ModuleParts {

View file

@ -1,5 +1,5 @@
use crate::config::{CommonConfig, ModuleOrientation}; use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
use crate::{glib_recv, module_impl, send_async, spawn}; use crate::{glib_recv, module_impl, send_async, spawn};
use color_eyre::Result; use color_eyre::Result;
@ -266,7 +266,7 @@ impl Module<gtk::Box> for SysInfoModule {
.to_string() .to_string()
}); });
label.set_markup_escaped(format_compiled.as_ref()); label.set_markup(format_compiled.as_ref());
} }
}); });
} }

View file

@ -124,7 +124,7 @@ impl TrayMenu {
label.show(); label.show();
label label
}) })
.set_text(text); .set_label(text);
} }
/// Shows the label, using its current text. /// Shows the label, using its current text.

View file

@ -9,7 +9,7 @@ use zbus;
use zbus::fdo::PropertiesProxy; use zbus::fdo::PropertiesProxy;
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::gtk_helpers::IronbarGtkExt;
use crate::image::ImageProvider; use crate::image::ImageProvider;
use crate::modules::PopupButton; use crate::modules::PopupButton;
use crate::modules::{ use crate::modules::{
@ -212,7 +212,7 @@ impl Module<gtk::Button> for UpowerModule {
ImageProvider::parse(&icon_name, &icon_theme, false, self.icon_size) ImageProvider::parse(&icon_name, &icon_theme, false, self.icon_size)
.map(|provider| provider.load_into_image(icon.clone())); .map(|provider| provider.load_into_image(icon.clone()));
label.set_markup_escaped(format.as_ref()); label.set_markup(format.as_ref());
}); });
let rx = context.subscribe(); let rx = context.subscribe();
@ -263,7 +263,7 @@ impl Module<gtk::Button> for UpowerModule {
_ => String::new(), _ => String::new(),
}; };
label.set_markup_escaped(&format); label.set_markup(&format);
}); });
container.show_all(); container.show_all();

View file

@ -432,7 +432,7 @@ impl Module<Button> for VolumeModule {
} }
Event::UpdateInput(info) => { Event::UpdateInput(info) => {
if let Some(ui) = inputs.get(&info.index) { if let Some(ui) = inputs.get(&info.index) {
ui.label.set_text(&info.name); ui.label.set_label(&info.name);
ui.slider.set_value(info.volume); ui.slider.set_value(info.volume);
ui.slider.set_sensitive(info.can_set_volume); ui.slider.set_sensitive(info.can_set_volume);
ui.btn_mute.set_label(if info.muted { &self.icons.muted } else { self.icons.volume_icon(info.volume) }); ui.btn_mute.set_label(if info.muted { &self.icons.muted } else { self.icons.volume_icon(info.volume) });