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

refactor: replace channel macros with ext trait methods

This commit is contained in:
Jake Stanger 2025-05-18 15:17:09 +01:00
parent d5744f597c
commit f929aef2d9
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
50 changed files with 658 additions and 476 deletions

View file

@ -3,7 +3,8 @@ use super::{BindModeClient, BindModeUpdate};
#[cfg(feature = "keyboard+hyprland")]
use super::{KeyboardLayoutClient, KeyboardLayoutUpdate};
use super::{Visibility, Workspace};
use crate::{arc_mut, lock, send, spawn_blocking};
use crate::channels::SyncSenderExt;
use crate::{arc_mut, lock, spawn_blocking};
use color_eyre::Result;
use hyprland::ctl::switch_xkb_layout;
use hyprland::data::{Devices, Workspace as HWorkspace, Workspaces};
@ -121,7 +122,7 @@ impl Client {
match workspace {
Ok(Some(workspace)) => {
send!(tx, WorkspaceUpdate::Add(workspace));
tx.send_expect(WorkspaceUpdate::Add(workspace));
}
Err(e) => error!("Failed to get workspace: {e:#}"),
_ => {}
@ -230,13 +231,10 @@ impl Client {
let _lock = lock!(lock);
debug!("Received workspace rename: {data:?}");
send!(
tx,
WorkspaceUpdate::Rename {
id: data.id as i64,
name: data.name
}
);
tx.send_expect(WorkspaceUpdate::Rename {
id: data.id as i64,
name: data.name,
});
});
}
@ -247,7 +245,7 @@ impl Client {
event_listener.add_workspace_deleted_handler(move |data| {
let _lock = lock!(lock);
debug!("Received workspace destroy: {data:?}");
send!(tx, WorkspaceUpdate::Remove(data.id as i64));
tx.send_expect(WorkspaceUpdate::Remove(data.id as i64));
});
}
@ -271,13 +269,10 @@ impl Client {
error!("Unable to locate client");
},
|c| {
send!(
tx,
WorkspaceUpdate::Urgent {
id: c.workspace.id as i64,
urgent: true,
}
);
tx.send_expect(WorkspaceUpdate::Urgent {
id: c.workspace.id as i64,
urgent: true,
});
},
);
});
@ -333,8 +328,7 @@ impl Client {
};
debug!("Received layout: {layout:?}");
send!(tx, KeyboardLayoutUpdate(layout));
tx.send_expect(KeyboardLayoutUpdate(layout));
});
}
@ -351,13 +345,10 @@ impl Client {
let _lock = lock!(lock);
debug!("Received bind mode: {bind_mode:?}");
send!(
tx,
BindModeUpdate {
name: bind_mode,
pango_markup: false,
}
);
tx.send_expect(BindModeUpdate {
name: bind_mode,
pango_markup: false,
});
});
}
@ -369,21 +360,15 @@ impl Client {
workspace: Workspace,
tx: &Sender<WorkspaceUpdate>,
) {
send!(
tx,
WorkspaceUpdate::Focus {
old: prev_workspace.take(),
new: workspace.clone(),
}
);
tx.send_expect(WorkspaceUpdate::Focus {
old: prev_workspace.take(),
new: workspace.clone(),
});
send!(
tx,
WorkspaceUpdate::Urgent {
id: workspace.id,
urgent: false,
}
);
tx.send_expect(WorkspaceUpdate::Urgent {
id: workspace.id,
urgent: false,
});
prev_workspace.replace(workspace);
}
@ -439,7 +424,9 @@ impl super::WorkspaceClient for Client {
})
.collect();
send!(self.workspace.tx, WorkspaceUpdate::Init(workspaces));
self.workspace
.tx
.send_expect(WorkspaceUpdate::Init(workspaces));
}
Err(e) => {
error!("Failed to get workspaces: {e:#}");
@ -486,7 +473,9 @@ impl KeyboardLayoutClient for Client {
.map(|k| k.active_keymap.clone())
}) {
Ok(Some(layout)) => {
send!(self.keyboard_layout.tx, KeyboardLayoutUpdate(layout));
self.keyboard_layout
.tx
.send_expect(KeyboardLayoutUpdate(layout));
}
Ok(None) => error!("Failed to get current keyboard layout hyprland"),
Err(err) => error!("Failed to get devices: {err:#?}"),

View file

@ -1,4 +1,4 @@
use crate::{clients::compositor::Visibility, send, spawn};
use crate::{clients::compositor::Visibility, spawn};
use color_eyre::Report;
use tracing::{error, warn};
@ -7,6 +7,7 @@ use tokio::sync::broadcast;
use super::{Workspace as IronWorkspace, WorkspaceClient, WorkspaceUpdate};
mod connection;
use crate::channels::SyncSenderExt;
use connection::{Action, Connection, Event, Request, WorkspaceReferenceArg};
#[derive(Debug)]
@ -151,7 +152,7 @@ impl Client {
};
for event in events {
send!(tx, event);
tx.send_expect(event);
}
}

View file

@ -1,6 +1,7 @@
use super::{Visibility, Workspace};
use crate::channels::SyncSenderExt;
use crate::clients::sway::Client;
use crate::{await_sync, error, send, spawn};
use crate::{await_sync, error, spawn};
use color_eyre::Report;
use swayipc_async::{InputChange, InputEvent, Node, WorkspaceChange, WorkspaceEvent};
use tokio::sync::broadcast::{Receiver, channel};
@ -8,7 +9,7 @@ use tokio::sync::broadcast::{Receiver, channel};
#[cfg(feature = "workspaces")]
use super::WorkspaceUpdate;
#[cfg(feature = "workspaces")]
#[cfg(feature = "workspaces+sway")]
impl super::WorkspaceClient for Client {
fn focus(&self, id: i64) {
let client = self.connection().clone();
@ -49,13 +50,13 @@ impl super::WorkspaceClient for Client {
let event =
WorkspaceUpdate::Init(workspaces.into_iter().map(Workspace::from).collect());
send!(tx, event);
tx.send_expect(event);
drop(client);
self.add_listener::<WorkspaceEvent>(move |event| {
let update = WorkspaceUpdate::from(event.clone());
send!(tx, update);
tx.send_expect(update);
})
.await
.expect("to add listener");
@ -198,7 +199,7 @@ impl KeyboardLayoutClient for Client {
let inputs = client.get_inputs().await.expect("to get inputs");
if let Some(layout) = inputs.into_iter().find_map(|i| i.xkb_active_layout_name) {
send!(tx, KeyboardLayoutUpdate(layout));
tx.send_expect(KeyboardLayoutUpdate(layout));
} else {
error!("Failed to get keyboard layout from Sway!");
}
@ -207,7 +208,7 @@ impl KeyboardLayoutClient for Client {
self.add_listener::<InputEvent>(move |event| {
if let Ok(layout) = KeyboardLayoutUpdate::try_from(event.clone()) {
send!(tx, layout);
tx.send_expect(layout);
}
})
.await
@ -255,13 +256,10 @@ impl BindModeClient for Client {
mode.change.clone()
};
send!(
tx,
BindModeUpdate {
name,
pango_markup: mode.pango_markup,
}
);
tx.send_expect(BindModeUpdate {
name,
pango_markup: mode.pango_markup,
});
})
.await
})?;