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

refactor: general code tidy-up

This commit is contained in:
Jake Stanger 2022-12-11 23:09:19 +00:00
parent 5e21cbcca6
commit ea2c84d1bd
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
4 changed files with 15 additions and 18 deletions

View file

@ -121,7 +121,6 @@ fn create_bars(
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?; .ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;
let monitor_name = &output.name; let monitor_name = &output.name;
// TODO: Could we use an Arc<Config> or `Cow<Config>` here to avoid cloning?
config.monitors.as_ref().map_or_else( config.monitors.as_ref().map_or_else(
|| { || {
info!("Creating bar on '{}'", monitor_name); info!("Creating bar on '{}'", monitor_name);

View file

@ -49,13 +49,15 @@ impl Module<gtk::Box> for FocusedModule {
) -> Result<()> { ) -> Result<()> {
let focused = await_sync(async { let focused = await_sync(async {
let wl = wayland::get_client().await; let wl = wayland::get_client().await;
// TODO: Avoid cloning let toplevels = read_lock!(wl.toplevels);
let toplevels = read_lock!(wl.toplevels).clone();
toplevels.into_iter().find(|(_, (top, _))| top.active) toplevels
.iter()
.find(|(_, (top, _))| top.active)
.map(|(_, (top, _))| top.clone())
}); });
if let Some((_, (top, _))) = focused { if let Some(top) = focused {
tx.try_send(ModuleUpdateEvent::Update((top.title.clone(), top.app_id)))?; tx.try_send(ModuleUpdateEvent::Update((top.title.clone(), top.app_id)))?;
} }

View file

@ -214,24 +214,19 @@ impl Module<gtk::Box> for LauncherModule {
}; };
} }
ToplevelChange::Focus(focused) => { ToplevelChange::Focus(focused) => {
// TODO: Flatten this let mut update_title = false;
let update_title = if focused {
if focused {
if let Some(item) = lock!(items).get_mut(&app_id) { if let Some(item) = lock!(items).get_mut(&app_id) {
item.set_window_focused(window.id, true); item.set_window_focused(window.id, true);
// might be switching focus between windows of same app // might be switching focus between windows of same app
if item.windows.len() > 1 { if item.windows.len() > 1 {
item.set_window_name(window.id, window.title.clone()); item.set_window_name(window.id, window.title.clone());
true update_title = true;
} else {
false
} }
} else {
false
} }
} else { }
false
};
send_update(LauncherUpdate::Focus(app_id.clone(), focused)).await?; send_update(LauncherUpdate::Focus(app_id.clone(), focused)).await?;
@ -266,7 +261,6 @@ impl Module<gtk::Box> for LauncherModule {
if let Err(err) = Command::new("gtk-launch") if let Err(err) = Command::new("gtk-launch")
.arg( .arg(
file.file_name() file.file_name()
// TODO: Don't panic for this
.expect("File segment missing from path to desktop file"), .expect("File segment missing from path to desktop file"),
) )
.stdout(Stdio::null()) .stdout(Stdio::null())

View file

@ -131,8 +131,10 @@ impl From<&str> for Script {
.take_while(|c| c.is_ascii_digit()) .take_while(|c| c.is_ascii_digit())
.collect::<String>(); .collect::<String>();
// TODO: Handle this better than panicking let interval = interval_str.parse::<u64>().unwrap_or_else(|_| {
let interval = interval_str.parse::<u64>().expect("Invalid interval"); warn!("Received invalid interval in script string. Falling back to default `5000ms`.");
5000
});
(ScriptInputToken::Interval(interval), interval_str.len()) (ScriptInputToken::Interval(interval), interval_str.len())
} }
// watching or polling // watching or polling