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

refactor: major client code changes

This does away with `lazy_static` singletons for all the clients, instead putting them all inside a `Clients` struct on the `Ironbar` struct.

Client code has been refactored in places to accommodate this, and module code has been updated to get the clients the new way.

The Wayland client has been re-written from the ground up to remove a lot of the needless complications, provide a nicer interface and reduce some duplicate data.

The MPD music client has been overhauled to use the `mpd_utils` crate, which simplifies the code within Ironbar and should offer more robustness and better recovery when connection is lost to the server.

The launcher module in particular has been affected by the refactor.
This commit is contained in:
Jake Stanger 2024-01-07 23:50:10 +00:00
parent 57b57ed002
commit c702f6fffa
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
33 changed files with 1081 additions and 1063 deletions

View file

@ -27,6 +27,8 @@ pub struct Bar {
monitor_name: String,
position: BarPosition,
ironbar: Rc<Ironbar>,
window: ApplicationWindow,
content: gtk::Box,
@ -39,7 +41,12 @@ pub struct Bar {
}
impl Bar {
pub fn new(app: &Application, monitor_name: String, config: Config) -> Self {
pub fn new(
app: &Application,
monitor_name: String,
config: Config,
ironbar: Rc<Ironbar>,
) -> Self {
let window = ApplicationWindow::builder()
.application(app)
.type_(WindowType::Toplevel)
@ -90,6 +97,7 @@ impl Bar {
name,
monitor_name,
position,
ironbar,
window,
content,
start,
@ -263,17 +271,17 @@ impl Bar {
if let Some(modules) = config.start {
let info = info!(ModuleLocation::Left);
add_modules(&self.start, modules, &info, &popup)?;
add_modules(&self.start, modules, &info, &self.ironbar, &popup)?;
}
if let Some(modules) = config.center {
let info = info!(ModuleLocation::Center);
add_modules(&self.center, modules, &info, &popup)?;
add_modules(&self.center, modules, &info, &self.ironbar, &popup)?;
}
if let Some(modules) = config.end {
let info = info!(ModuleLocation::Right);
add_modules(&self.end, modules, &info, &popup)?;
add_modules(&self.end, modules, &info, &self.ironbar, &popup)?;
}
let result = BarLoadResult { popup };
@ -333,6 +341,7 @@ fn add_modules(
content: &gtk::Box,
modules: Vec<ModuleConfig>,
info: &ModuleInfo,
ironbar: &Rc<Ironbar>,
popup: &Rc<RefCell<Popup>>,
) -> Result<()> {
let orientation = info.bar_position.get_orientation();
@ -343,6 +352,7 @@ fn add_modules(
let widget_parts = create_module(
*$module,
$id,
ironbar.clone(),
common.name.clone(),
&info,
&Rc::clone(&popup),
@ -387,7 +397,8 @@ pub fn create_bar(
monitor: &Monitor,
monitor_name: String,
config: Config,
ironbar: Rc<Ironbar>,
) -> Result<Bar> {
let bar = Bar::new(app, monitor_name, config);
let bar = Bar::new(app, monitor_name, config, ironbar);
bar.init(monitor)
}