1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 22:31:03 +02:00

Merge pull request #1010 from JakeStanger/refactor/glib-deps

refactor: `recv_glib` dependency arrays
This commit is contained in:
Jake Stanger 2025-05-26 22:54:04 +01:00 committed by GitHub
commit b27c601733
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 539 additions and 517 deletions

View file

@ -95,20 +95,29 @@ pub trait MpscReceiverExt<T> {
/// Spawns a `GLib` future on the local thread, and calls `rx.recv()`
/// in a loop, passing the message to `f`.
///
/// This allows use of `GObjects` and futures in the same context.
fn recv_glib<F>(self, f: F)
/// This allows use of `GObjects` and futures in the same context.#
///
/// `deps` is a single reference, or tuple of references of clonable objects,
/// to be consumed inside the closure.
/// This avoids needing to `element.clone()` everywhere.
fn recv_glib<D, Fn>(self, deps: D, f: Fn)
where
F: FnMut(T) + 'static;
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) + 'static;
}
impl<T: 'static> MpscReceiverExt<T> for mpsc::Receiver<T> {
fn recv_glib<F>(mut self, mut f: F)
fn recv_glib<D, Fn>(mut self, deps: D, mut f: Fn)
where
F: FnMut(T) + 'static,
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) + 'static,
{
let deps = deps.clone_content();
glib::spawn_future_local(async move {
while let Some(val) = self.recv().await {
f(val);
f(&deps, val);
}
});
}
@ -122,14 +131,22 @@ where
/// in a loop, passing the message to `f`.
///
/// This allows use of `GObjects` and futures in the same context.
fn recv_glib<F>(self, f: F)
///
/// `deps` is a single reference, or tuple of references of clonable objects,
/// to be consumed inside the closure.
/// This avoids needing to `element.clone()` everywhere.
fn recv_glib<D, Fn>(self, deps: D, f: Fn)
where
F: FnMut(T) + 'static;
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) + 'static;
/// Like [`BroadcastReceiverExt::recv_glib`], but the closure must return a [`Future`].
fn recv_glib_async<Fn, F>(self, f: Fn)
fn recv_glib_async<D, Fn, F>(self, deps: D, f: Fn)
where
Fn: FnMut(T) -> F + 'static,
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) -> F + 'static,
F: Future;
}
@ -137,14 +154,17 @@ impl<T> BroadcastReceiverExt<T> for broadcast::Receiver<T>
where
T: Debug + Clone + 'static,
{
fn recv_glib<F>(mut self, mut f: F)
fn recv_glib<D, Fn>(mut self, deps: D, mut f: Fn)
where
F: FnMut(T) + 'static,
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) + 'static,
{
let deps = deps.clone_content();
glib::spawn_future_local(async move {
loop {
match self.recv().await {
Ok(val) => f(val),
Ok(val) => f(&deps, val),
Err(broadcast::error::RecvError::Lagged(count)) => {
tracing::warn!(
"Channel lagged behind by {count}, this may result in unexpected or broken behaviour"
@ -159,16 +179,19 @@ where
});
}
fn recv_glib_async<Fn, F>(mut self, mut f: Fn)
fn recv_glib_async<D, Fn, F>(mut self, deps: D, mut f: Fn)
where
Fn: FnMut(T) -> F + 'static,
D: Dependency,
D::Target: Clone + 'static,
Fn: FnMut(&D::Target, T) -> F + 'static,
F: Future,
{
let deps = deps.clone_content();
glib::spawn_future_local(async move {
loop {
match self.recv().await {
Ok(val) => {
f(val).await;
f(&deps, val).await;
}
Err(broadcast::error::RecvError::Lagged(count)) => {
tracing::warn!(
@ -184,3 +207,55 @@ where
});
}
}
/// `recv_glib` callback dependency
/// or dependency tuple.
pub trait Dependency: Clone {
type Target;
fn clone_content(&self) -> Self::Target;
}
impl Dependency for () {
type Target = ();
fn clone_content(&self) -> Self::Target {}
}
impl<'a, T> Dependency for &'a T
where
T: Clone + 'a,
{
type Target = T;
fn clone_content(&self) -> T {
T::clone(self)
}
}
macro_rules! impl_dependency {
($($idx:tt $t:ident),+) => {
impl<'a, $($t),+> Dependency for ($(&'a $t),+)
where
$($t: Clone + 'a),+
{
type Target = ($($t),+);
fn clone_content(&self) -> Self::Target {
($(self.$idx.clone()),+)
}
}
};
}
impl_dependency!(0 T1, 1 T2);
impl_dependency!(0 T1, 1 T2, 2 T3);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7, 7 T8);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7, 7 T8, 8 T9);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7, 7 T8, 8 T9, 9 T10);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7, 7 T8, 8 T9, 9 T10, 10 T11);
impl_dependency!(0 T1, 1 T2, 2 T3, 3 T4, 4 T5, 5 T6, 6 T7, 7 T8, 8 T9, 9 T10, 10 T11, 11 T12);

View file

@ -301,8 +301,7 @@ impl CommonConfig {
install_oneshot!(self.on_mouse_exit, connect_leave_notify_event);
if let Some(tooltip) = self.tooltip {
let container = container.clone();
dynamic_string(&tooltip, move |string| {
dynamic_string(&tooltip, container, move |container, string| {
container.set_tooltip_text(Some(&string));
});
}
@ -314,19 +313,15 @@ impl CommonConfig {
container.show_all();
},
|show_if| {
// need to keep clone here for the notify callback
let container = container.clone();
{
let revealer = revealer.clone();
let container = container.clone();
show_if.subscribe(move |success| {
show_if.subscribe((revealer, &container), |(revealer, container), success| {
if success {
container.show_all();
}
revealer.set_reveal_child(success);
});
}
revealer.connect_child_revealed_notify(move |revealer| {
if !revealer.reveals_child() {

View file

@ -1,6 +1,6 @@
#[cfg(feature = "ipc")]
use crate::Ironbar;
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
use crate::channels::{AsyncSenderExt, Dependency, MpscReceiverExt};
use crate::script::Script;
use crate::spawn;
use cfg_if::cfg_if;
@ -19,9 +19,11 @@ pub enum DynamicBool {
}
impl DynamicBool {
pub fn subscribe<F>(self, f: F)
pub fn subscribe<D, F>(self, deps: D, f: F)
where
F: FnMut(bool) + 'static,
D: Dependency,
D::Target: Clone + 'static,
F: FnMut(&D::Target, bool) + 'static,
{
let value = match self {
Self::Unknown(input) => {
@ -43,7 +45,7 @@ impl DynamicBool {
let (tx, rx) = mpsc::channel(32);
rx.recv_glib(f);
rx.recv_glib(deps, f);
spawn(async move {
match value {

View file

@ -1,6 +1,6 @@
#[cfg(feature = "ipc")]
use crate::Ironbar;
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
use crate::channels::{AsyncSenderExt, Dependency, MpscReceiverExt};
use crate::script::{OutputStream, Script};
use crate::{arc_mut, lock, spawn};
use tokio::sync::mpsc;
@ -26,9 +26,11 @@ enum DynamicStringSegment {
/// label.set_label_escaped(&string);
/// });
/// ```
pub fn dynamic_string<F>(input: &str, f: F)
pub fn dynamic_string<D, F>(input: &str, deps: D, f: F)
where
F: FnMut(String) + 'static,
D: Dependency,
D::Target: Clone + 'static,
F: FnMut(&D::Target, String) + 'static,
{
let (tokens, is_static) = parse_input(input);
@ -89,7 +91,7 @@ where
}
}
rx.recv_glib(f);
rx.recv_glib(deps, f);
// initialize
if is_static {

View file

@ -65,8 +65,7 @@ impl Ipc {
}
});
let application = application.clone();
cmd_rx.recv_glib(move |command| {
cmd_rx.recv_glib(application, move |application, command| {
let res = Self::handle_command(command, &application, &ironbar);
res_tx.send_spawn(res);
});

View file

@ -81,10 +81,7 @@ impl Module<Label> for Bindmode {
}));
}
{
let label = label.clone();
let on_mode = move |mode: BindModeUpdate| {
context.subscribe().recv_glib(&label, |label, mode| {
trace!("mode: {:?}", mode);
label.set_use_markup(mode.pango_markup);
label.set_label_escaped(&mode.name);
@ -94,10 +91,7 @@ impl Module<Label> for Bindmode {
} else {
label.show();
}
};
context.subscribe().recv_glib(on_mode);
}
});
Ok(ModuleParts {
widget: label,

View file

@ -192,7 +192,7 @@ impl Module<gtk::Box> for CairoModule {
}
});
context.subscribe().recv_glib(move |_ev| {
context.subscribe().recv_glib((), move |(), _ev| {
let res = fs::read_to_string(&self.path)
.map(|s| s.replace("function draw", format!("function __draw_{id}").as_str()));

View file

@ -184,9 +184,9 @@ impl Module<Button> for ClipboardModule {
let mut items = HashMap::new();
{
let hidden_option = hidden_option.clone();
context.subscribe().recv_glib(move |event| {
context
.subscribe()
.recv_glib(&hidden_option, move |hidden_option, event| {
match event {
ControllerEvent::Add(id, item) => {
debug!("Adding new value with ID {}", id);
@ -196,7 +196,7 @@ impl Module<Button> for ClipboardModule {
let button = match item.value.as_ref() {
ClipboardValue::Text(value) => {
let button = RadioButton::from_widget(&hidden_option);
let button = RadioButton::from_widget(hidden_option);
let label = Label::new(Some(value));
button.add(&label);
@ -222,7 +222,7 @@ impl Module<Button> for ClipboardModule {
Ok(pixbuf) => {
let image = Image::from_pixbuf(Some(&pixbuf));
let button = RadioButton::from_widget(&hidden_option);
let button = RadioButton::from_widget(hidden_option);
button.set_image(Some(&image));
button.set_always_show_image(true);
button.style_context().add_class("image");
@ -320,7 +320,6 @@ impl Module<Button> for ClipboardModule {
}
}
});
}
container.show_all();
hidden_option.hide();

View file

@ -139,7 +139,7 @@ impl Module<Button> for ClockModule {
let locale = Locale::try_from(self.locale.as_str()).unwrap_or(Locale::POSIX);
let rx = context.subscribe();
rx.recv_glib(move |date| {
rx.recv_glib((), move |(), date| {
let date_string = format!("{}", date.format_localized(&format, locale));
label.set_label(&date_string);
});
@ -173,7 +173,7 @@ impl Module<Button> for ClockModule {
let format = self.format_popup;
let locale = Locale::try_from(self.locale.as_str()).unwrap_or(Locale::POSIX);
context.subscribe().recv_glib(move |date| {
context.subscribe().recv_glib((), move |(), date| {
let date_string = format!("{}", date.format_localized(&format, locale));
clock.set_label(&date_string);
});

View file

@ -73,7 +73,7 @@ impl CustomWidget for ButtonWidget {
button.add(&label);
dynamic_string(&text, move |string| {
dynamic_string(&text, (), move |(), string| {
label.set_label_escaped(&string);
});
}

View file

@ -44,10 +44,7 @@ impl CustomWidget for ImageWidget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let gtk_image = build!(self, Self::Widget);
{
let gtk_image = gtk_image.clone();
dynamic_string(&self.src, move |src| {
dynamic_string(&self.src, &gtk_image, move |gtk_image, src| {
let gtk_image = gtk_image.clone();
let image_provider = context.image_provider.clone();
glib::spawn_future_local(async move {
@ -56,7 +53,6 @@ impl CustomWidget for ImageWidget {
.await;
});
});
}
gtk_image
}

View file

@ -55,12 +55,9 @@ impl CustomWidget for LabelWidget {
label.truncate(truncate);
}
{
let label = label.clone();
dynamic_string(&self.label, move |string| {
dynamic_string(&self.label, &label, move |label, string| {
label.set_label_escaped(&string);
});
}
label
}

View file

@ -95,14 +95,13 @@ impl CustomWidget for ProgressWidget {
.await;
});
rx.recv_glib(move |value| progress.set_fraction(value / self.max));
rx.recv_glib((), move |(), value| progress.set_fraction(value / self.max));
}
if let Some(text) = self.label {
let progress = progress.clone();
progress.set_show_text(true);
dynamic_string(&text, move |string| {
dynamic_string(&text, &progress, move |progress, string| {
progress.set_text(Some(&string));
});
}

View file

@ -165,7 +165,7 @@ impl CustomWidget for SliderWidget {
.await;
});
rx.recv_glib(move |value| scale.set_value(value));
rx.recv_glib((), move |(), value| scale.set_value(value));
}
scale

View file

@ -154,7 +154,7 @@ impl Module<gtk::Box> for FocusedModule {
{
let image_provider = context.ironbar.image_provider();
context.subscribe().recv_glib_async(move |data| {
context.subscribe().recv_glib_async((), move |(), data| {
let icon = icon.clone();
let label = label.clone();
let image_provider = image_provider.clone();

View file

@ -305,11 +305,17 @@ impl Module<gtk::Box> for KeyboardModule {
}
let icons = self.icons;
let handle_event = move |ev: KeyboardUpdate| match ev {
context
.subscribe()
.recv_glib((), move |(), ev: KeyboardUpdate| match ev {
KeyboardUpdate::Key(ev) => {
let parts = match (ev.key, ev.state) {
(Key::Caps, true) if self.show_caps => Some((&caps, icons.caps_on.as_str())),
(Key::Caps, false) if self.show_caps => Some((&caps, icons.caps_off.as_str())),
(Key::Caps, true) if self.show_caps => {
Some((&caps, icons.caps_on.as_str()))
}
(Key::Caps, false) if self.show_caps => {
Some((&caps, icons.caps_off.as_str()))
}
(Key::Num, true) if self.show_num => Some((&num, icons.num_on.as_str())),
(Key::Num, false) if self.show_num => Some((&num, icons.num_off.as_str())),
(Key::Scroll, true) if self.show_scroll => {
@ -335,9 +341,7 @@ impl Module<gtk::Box> for KeyboardModule {
let text = icons.layout_map.get(&language).unwrap_or(&language);
layout_button.set_label(text);
}
};
context.subscribe().recv_glib(handle_event);
});
Ok(ModuleParts::new(container, None))
}
}

View file

@ -56,8 +56,7 @@ impl Module<Label> for LabelModule {
context: &WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
_rx: mpsc::Receiver<Self::ReceiveMessage>,
) -> Result<()> {
let tx = context.tx.clone();
dynamic_string(&self.label, move |string| {
dynamic_string(&self.label, &context.tx, move |tx, string| {
tx.send_update_spawn(string);
});
@ -79,12 +78,9 @@ impl Module<Label> for LabelModule {
label.truncate(truncate);
}
{
let label = label.clone();
context
.subscribe()
.recv_glib(move |string| label.set_label_escaped(&string));
}
context.subscribe().recv_glib(&label, move |label, string| {
label.set_label_escaped(&string)
});
Ok(ModuleParts {
widget: label,

View file

@ -458,10 +458,6 @@ impl Module<gtk::Box> for LauncherModule {
);
{
let container = container.clone();
let controller_tx = context.controller_tx.clone();
let appearance_options = AppearanceOptions {
show_names: self.show_names,
show_icons: self.show_icons,
@ -477,10 +473,11 @@ impl Module<gtk::Box> for LauncherModule {
let mut buttons = IndexMap::<String, ItemButton>::new();
let tx = context.tx.clone();
let rx = context.subscribe();
let handle_event = move |event: LauncherUpdate| {
rx.recv_glib(
(&container, &context.controller_tx, &context.tx),
move |(container, controller_tx, tx), event: LauncherUpdate| {
// all widgets show by default
// so check if pagination should be shown
// to ensure correct state on init.
@ -582,9 +579,8 @@ impl Module<gtk::Box> for LauncherModule {
}
LauncherUpdate::Hover(_) => {}
}
};
rx.recv_glib(handle_event);
},
);
}
let popup = self.into_popup(context, info).into_popup_parts(vec![]); // since item buttons are dynamic, they pass their geometry directly
@ -611,9 +607,9 @@ impl Module<gtk::Box> for LauncherModule {
let mut buttons = IndexMap::<String, IndexMap<usize, ImageTextButton>>::new();
{
let container = container.clone();
context.subscribe().recv_glib(move |event| {
context
.subscribe()
.recv_glib(&container, move |container, event| {
match event {
LauncherUpdate::AddItem(item) => {
let app_id = item.app_id.clone();
@ -703,7 +699,6 @@ impl Module<gtk::Box> for LauncherModule {
_ => {}
}
});
}
Some(container)
}

View file

@ -209,17 +209,18 @@ impl Module<Button> for MenuModule {
center_section.add_class("main-center");
end_section.add_class("main-end");
let container2 = container.clone();
{
let main_menu = main_menu.clone();
let container = container.clone();
let start_section = start_section.clone();
let center_section = center_section.clone();
let end_section = end_section.clone();
let truncate_mode = self.truncate;
context.subscribe().recv_glib(move |applications| {
context.subscribe().recv_glib(
(
&main_menu,
&container,
&start_section,
&center_section,
&end_section,
),
move |(main_menu, container, start_section, center_section, end_section),
applications| {
for application in applications.iter() {
let mut inserted = false;
@ -288,15 +289,14 @@ impl Module<Button> for MenuModule {
add_entries!(&center_entries, &center_section);
add_entries!(&end_entries, &end_section);
main_menu.add(&start_section);
main_menu.add(&center_section);
main_menu.add(&end_section);
});
}
main_menu.add(start_section);
main_menu.add(center_section);
main_menu.add(end_section);
},
);
{
let container = container2;
let container = container.clone();
context.popup.window.connect_hide(move |_| {
start_section.foreach(|child| {
child.remove_class("open");

View file

@ -388,8 +388,7 @@ impl ModuleFactory for BarModuleFactory {
) where
TSend: Debug + Clone + Send + 'static,
{
let popup = self.popup.clone();
rx.recv_glib(move |ev| match ev {
rx.recv_glib(&self.popup, move |popup, ev| match ev {
ModuleUpdateEvent::Update(update) => {
tx.send_expect(update);
}
@ -464,10 +463,9 @@ impl ModuleFactory for PopupModuleFactory {
) where
TSend: Debug + Clone + Send + 'static,
{
let popup = self.popup.clone();
let button_id = self.button_id;
rx.recv_glib(move |ev| match ev {
rx.recv_glib(&self.popup, move |popup, ev| match ev {
ModuleUpdateEvent::Update(update) => {
tx.send_expect(update);
}

View file

@ -217,13 +217,9 @@ impl Module<Button> for MusicModule {
});
}
{
let button = button.clone();
let tx = context.tx.clone();
let rx = context.subscribe();
rx.recv_glib(move |event| {
rx.recv_glib((&button, &context.tx), move |(button, tx), event| {
let ControllerEvent::Update(mut event) = event else {
return;
};
@ -257,7 +253,6 @@ impl Module<Button> for MusicModule {
tx.send_spawn(ModuleUpdateEvent::ClosePopup);
}
});
};
let popup = self
.into_popup(context, info)
@ -403,11 +398,10 @@ impl Module<Button> for MusicModule {
container.show_all();
{
let image_size = self.cover_image_size;
let mut prev_cover = None;
context.subscribe().recv_glib(move |event| {
context.subscribe().recv_glib((), move |(), event| {
match event {
ControllerEvent::Update(Some(update)) => {
// only update art when album changes
@ -421,12 +415,7 @@ impl Module<Button> for MusicModule {
glib::spawn_future_local(async move {
let success = match image_provider
.load_into_image(
&cover_path,
image_size,
false,
&album_image,
)
.load_into_image(&cover_path, image_size, false, &album_image)
.await
{
Ok(true) => {
@ -517,7 +506,6 @@ impl Module<Button> for MusicModule {
_ => {}
}
});
}
Some(container)
}

View file

@ -76,7 +76,7 @@ impl Module<GtkBox> for NetworkManagerModule {
}
});
context.subscribe().recv_glib_async(move |state| {
context.subscribe().recv_glib_async((), move |(), state| {
let image_provider = image_provider.clone();
let icon = icon.clone();

View file

@ -204,17 +204,13 @@ impl Module<Overlay> for NotificationsModule {
ctx.send_spawn(UiEvent::ToggleVisibility);
});
{
let button = button.clone();
context.subscribe().recv_glib(move |ev| {
context.subscribe().recv_glib(&button, move |button, ev| {
let icon = self.icons.icon(ev);
button.set_label(icon);
label.set_label(&ev.count.to_string());
label.set_visible(self.show_count && ev.count > 0);
});
}
Ok(ModuleParts {
widget: overlay,

View file

@ -110,12 +110,9 @@ impl Module<Label> for ScriptModule {
.justify(self.layout.justify.into())
.build();
{
let label = label.clone();
context
.subscribe()
.recv_glib(move |s| label.set_label_escaped(&s));
}
.recv_glib(&label, |label, s| label.set_label_escaped(&s));
Ok(ModuleParts {
widget: label,

View file

@ -303,7 +303,7 @@ impl Module<gtk::Box> for SysInfoModule {
labels.push(label);
}
context.subscribe().recv_glib(move |data| {
context.subscribe().recv_glib((), move |(), data| {
let label = &labels[data.0];
label.set_label_escaped(&data.1);
});

View file

@ -117,13 +117,13 @@ impl Module<gtk::Box> for TrayModule {
// Each widget is wrapped in an EventBox, copying what Waybar does here.
let container = gtk::Box::new(orientation, 10);
{
let container = container.clone();
let mut menus = HashMap::new();
let icon_theme = context.ironbar.image_provider().icon_theme();
// listen for UI updates
context.subscribe().recv_glib(move |update| {
context
.subscribe()
.recv_glib(&container, move |container, update| {
on_update(
update,
&container,
@ -133,7 +133,6 @@ impl Module<gtk::Box> for TrayModule {
self.prefer_theme_icons,
);
});
};
Ok(ModuleParts {
widget: container,

View file

@ -202,7 +202,7 @@ impl Module<Button> for UpowerModule {
let rx = context.subscribe();
let provider = context.ironbar.image_provider();
rx.recv_glib_async(move |properties| {
rx.recv_glib_async((), move |(), properties| {
let state = properties.state;
let is_charging =
@ -258,7 +258,7 @@ impl Module<Button> for UpowerModule {
label.add_class("upower-details");
container.add(&label);
context.subscribe().recv_glib(move |properties| {
context.subscribe().recv_glib((), move |(), properties| {
let state = properties.state;
let format = match state {
BatteryState::Charging | BatteryState::PendingCharge => {

View file

@ -228,13 +228,11 @@ impl Module<Button> for VolumeModule {
});
}
{
let rx = context.subscribe();
let icons = self.icons.clone();
let format = self.format.clone();
rx.recv_glib(move |event| match event {
rx.recv_glib(
(&self.icons, &self.format),
move |(icons, format), event| match event {
Event::AddSink(sink) | Event::UpdateSink(sink) if sink.active => {
let label = format
.replace(
@ -251,8 +249,8 @@ impl Module<Button> for VolumeModule {
button_label.set_label_escaped(&label);
}
_ => {}
});
}
},
);
let popup = self
.into_popup(context, info)
@ -351,13 +349,11 @@ impl Module<Button> for VolumeModule {
container.show_all();
let mut inputs = HashMap::new();
{
let input_container = input_container.clone();
let mut sinks = vec![];
context.subscribe().recv_glib(move |event| {
context
.subscribe()
.recv_glib(&input_container, move |input_container, event| {
match event {
Event::AddSink(info) => {
sink_selector.append(Some(&info.name), &info.description);
@ -477,7 +473,6 @@ impl Module<Button> for VolumeModule {
}
}
});
}
Some(container)
}

View file

@ -317,7 +317,9 @@ impl Module<gtk::Box> for WorkspacesModule {
}
let name_map = self.name_map;
let handle_event = move |event: WorkspaceUpdate| match event {
context
.subscribe()
.recv_glib((), move |(), event| match event {
WorkspaceUpdate::Init(workspaces) => {
if has_initialized {
return;
@ -352,7 +354,9 @@ impl Module<gtk::Box> for WorkspacesModule {
return;
}
if workspace.monitor == output_name && !self.hidden.contains(&workspace.name) {
if workspace.monitor == output_name
&& !self.hidden.contains(&workspace.name)
{
add_workspace(workspace, &mut button_map);
reorder!();
} else {
@ -401,9 +405,7 @@ impl Module<gtk::Box> for WorkspacesModule {
}
}
WorkspaceUpdate::Unknown => warn!("received unknown type workspace event"),
};
context.subscribe().recv_glib(handle_event);
});
}
Ok(ModuleParts {

View file

@ -113,21 +113,15 @@ impl Popup {
let output_size = rc_mut!(output_size);
// respond to resolution changes
{
let output_size = output_size.clone();
let rx = ironbar.clients.borrow_mut().wayland().subscribe_outputs();
let output_name = module_info.output_name.to_string();
let on_output_event = move |event: OutputEvent| {
rx.recv_glib(&output_size, move |output_size, event: OutputEvent| {
if event.event_type == OutputEventType::Update
&& event.output.name.unwrap_or_default() == output_name
{
*output_size.borrow_mut() = event.output.logical_size.unwrap_or_default();
}
};
let rx = ironbar.clients.borrow_mut().wayland().subscribe_outputs();
rx.recv_glib(on_output_event);
}
});
Self {
window: win,

View file

@ -73,7 +73,7 @@ pub fn load_css(style_path: PathBuf, application: Application) {
}
});
rx.recv_glib(move |path| {
rx.recv_glib((), move |(), path| {
info!("Reloading CSS");
if let Err(err) = provider.load_from_file(&gio::File::for_path(path)) {
error!("{:?}", Report::new(err)