1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-02 03:01:04 +02:00

refactor: update gtk/glib, remove glib channels

This is a major refactor which updates GTK, GLib and GTK Layer Shell to their latest versions.

GLib channels, previously used for receiving events on the GLib Main Context thread have been deprecated and a new method for running Futures on the main thread has been added instead. This commit also replaces all the deprecated code with this.

As part of the above, a bug was uncovered related to creating the GLib main context inside the Tokio runtime. Spawning of Tokio tasks has been refactored to fix this.
This commit is contained in:
Jake Stanger 2023-12-17 23:51:43 +00:00
parent 2c2f1c1243
commit bea442ed96
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
39 changed files with 426 additions and 465 deletions

View file

@ -1,15 +1,16 @@
use glib::Propagation;
use std::cell::Cell;
use std::ops::Neg;
use gtk::prelude::*;
use gtk::Scale;
use serde::Deserialize;
use tokio::spawn;
use tokio::sync::mpsc;
use tracing::error;
use crate::modules::custom::set_length;
use crate::script::{OutputStream, Script, ScriptInput};
use crate::{build, send, try_send};
use crate::{build, glib_recv_mpsc, spawn, try_send};
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, ExecEvent};
@ -77,7 +78,7 @@ impl CustomWidget for SliderWidget {
};
scale.set_value(value + delta);
Inhibit(false)
Propagation::Proceed
});
scale.connect_change_value(move |_, _, val| {
@ -97,7 +98,7 @@ impl CustomWidget for SliderWidget {
prev_value.set(val);
}
Inhibit(false)
Propagation::Proceed
});
}
@ -105,13 +106,13 @@ impl CustomWidget for SliderWidget {
let script = Script::from(value);
let scale = scale.clone();
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
let (tx, mut rx) = mpsc::channel(128);
spawn(async move {
script
.run(None, move |stream, _success| match stream {
OutputStream::Stdout(out) => match out.parse() {
Ok(value) => send!(tx, value),
Ok(value) => try_send!(tx, value),
Err(err) => error!("{err:?}"),
},
OutputStream::Stderr(err) => error!("{err:?}"),
@ -119,10 +120,7 @@ impl CustomWidget for SliderWidget {
.await;
});
rx.attach(None, move |value| {
scale.set_value(value);
Continue(true)
});
glib_recv_mpsc!(rx, value => scale.set_value(value));
}
scale