Skip to content

Commit

Permalink
refactor: general code tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger committed Dec 11, 2022
1 parent 5e21cbc commit ea2c84d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ fn create_bars(
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;
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(
|| {
info!("Creating bar on '{}'", monitor_name);
Expand Down
10 changes: 6 additions & 4 deletions src/modules/focused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ impl Module<gtk::Box> for FocusedModule {
) -> Result<()> {
let focused = await_sync(async {
let wl = wayland::get_client().await;
// TODO: Avoid cloning
let toplevels = read_lock!(wl.toplevels).clone();
let toplevels = read_lock!(wl.toplevels);

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)))?;
}

Expand Down
16 changes: 5 additions & 11 deletions src/modules/launcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,19 @@ impl Module<gtk::Box> for LauncherModule {
};
}
ToplevelChange::Focus(focused) => {
// TODO: Flatten this
let update_title = if focused {
let mut update_title = false;

if focused {
if let Some(item) = lock!(items).get_mut(&app_id) {
item.set_window_focused(window.id, true);

// might be switching focus between windows of same app
if item.windows.len() > 1 {
item.set_window_name(window.id, window.title.clone());
true
} else {
false
update_title = true;
}
} else {
false
}
} else {
false
};
}

send_update(LauncherUpdate::Focus(app_id.clone(), focused)).await?;

Expand Down Expand Up @@ -266,7 +261,6 @@ impl Module<gtk::Box> for LauncherModule {
if let Err(err) = Command::new("gtk-launch")
.arg(
file.file_name()
// TODO: Don't panic for this
.expect("File segment missing from path to desktop file"),
)
.stdout(Stdio::null())
Expand Down
6 changes: 4 additions & 2 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ impl From<&str> for Script {
.take_while(|c| c.is_ascii_digit())
.collect::<String>();

// TODO: Handle this better than panicking
let interval = interval_str.parse::<u64>().expect("Invalid interval");
let interval = interval_str.parse::<u64>().unwrap_or_else(|_| {
warn!("Received invalid interval in script string. Falling back to default `5000ms`.");
5000
});
(ScriptInputToken::Interval(interval), interval_str.len())
}
// watching or polling
Expand Down

0 comments on commit ea2c84d

Please sign in to comment.