Skip to content

Commit

Permalink
refactor: fix new clippy warnings, fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger committed Aug 25, 2023
1 parent b9c41af commit fea1f18
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
11 changes: 5 additions & 6 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use crate::modules::{
};
use crate::popup::Popup;
use crate::unique_id::get_unique_usize;
use crate::{arc_rw, Config, GlobalState};
use crate::{Config, GlobalState};
use color_eyre::Result;
use gtk::gdk::Monitor;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, IconTheme, Orientation};
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::{Arc, RwLock};
use tracing::{debug, info};

/// Creates a new window for a bar,
Expand Down Expand Up @@ -153,7 +152,7 @@ fn create_container(name: &str, orientation: Orientation) -> gtk::Box {

#[derive(Debug)]
struct BarLoadResult {
popup: Arc<RwLock<Popup>>,
popup: Rc<RefCell<Popup>>,
}

/// Loads the configured modules onto a bar.
Expand Down Expand Up @@ -186,7 +185,7 @@ fn load_modules(

// popup ignores module location so can bodge this for now
let popup = Popup::new(&info!(ModuleLocation::Left), config.popup_gap);
let popup = arc_rw!(popup);
let popup = Rc::new(RefCell::new(popup));

if let Some(modules) = config.start {
let info = info!(ModuleLocation::Left);
Expand Down Expand Up @@ -214,7 +213,7 @@ fn add_modules(
content: &gtk::Box,
modules: Vec<ModuleConfig>,
info: &ModuleInfo,
popup: &Arc<RwLock<Popup>>,
popup: &Rc<RefCell<Popup>>,
) -> Result<()> {
let orientation = info.bar_position.get_orientation();

Expand All @@ -226,7 +225,7 @@ fn add_modules(
$id,
common.name.clone(),
&info,
&Arc::clone(&popup),
&Rc::clone(&popup),
)?;
set_widget_identifiers(&widget_parts, &common);

Expand Down
12 changes: 9 additions & 3 deletions src/desktop_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ fn find_desktop_file_by_filedata(app_id: &str, files: &[PathBuf]) -> Option<Path
let files = files
.iter()
.filter_map(|file| {
let Some(parsed_desktop_file) = parse_desktop_file(file) else { return None };
let Some(parsed_desktop_file) = parse_desktop_file(file) else {
return None;
};

desktop_files_cache.insert(file.clone(), parsed_desktop_file.clone());
Some((file.clone(), parsed_desktop_file))
Expand Down Expand Up @@ -162,7 +164,9 @@ fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {

file.lines()
.filter_map(|line| {
let Some((key, value)) = line.split_once('=') else { return None };
let Some((key, value)) = line.split_once('=') else {
return None;
};

let key = key.trim();
let value = value.trim();
Expand All @@ -185,7 +189,9 @@ fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {

/// Attempts to get the icon name from the app's `.desktop` file.
pub fn get_desktop_icon_name(app_id: &str) -> Option<String> {
let Some(path) = find_desktop_file(app_id) else { return None };
let Some(path) = find_desktop_file(app_id) else {
return None;
};

let mut desktop_files_cache = lock!(DESKTOP_FILES);

Expand Down
14 changes: 7 additions & 7 deletions src/global_state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::popup::Popup;
use crate::write_lock;
use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
use std::sync::{Arc, RwLock, RwLockWriteGuard};
use std::rc::Rc;

/// Global application state shared across all bars.
///
/// Data that needs to be accessed from anywhere
/// that is not otherwise accessible should be placed on here.
#[derive(Debug)]
pub struct GlobalState {
popups: HashMap<Box<str>, Arc<RwLock<Popup>>>,
popups: HashMap<Box<str>, Rc<RefCell<Popup>>>,
}

impl GlobalState {
Expand All @@ -19,22 +19,22 @@ impl GlobalState {
}
}

pub fn popups(&self) -> &HashMap<Box<str>, Arc<RwLock<Popup>>> {
pub fn popups(&self) -> &HashMap<Box<str>, Rc<RefCell<Popup>>> {
&self.popups
}

pub fn popups_mut(&mut self) -> &mut HashMap<Box<str>, Arc<RwLock<Popup>>> {
pub fn popups_mut(&mut self) -> &mut HashMap<Box<str>, Rc<RefCell<Popup>>> {
&mut self.popups
}

pub fn with_popup_mut<F, T>(&self, monitor_name: &str, f: F) -> Option<T>
where
F: FnOnce(RwLockWriteGuard<Popup>) -> T,
F: FnOnce(RefMut<Popup>) -> T,
{
let popup = self.popups().get(monitor_name);

if let Some(popup) = popup {
let popup = write_lock!(popup);
let popup = popup.borrow_mut();
Some(f(popup))
} else {
None
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ fn create_bars(
.get(i as usize)
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;

let Some(monitor_name) = &output.name else { continue };
let Some(monitor_name) = &output.name else {
continue;
};

config.monitors.as_ref().map_or_else(
|| {
Expand Down
21 changes: 11 additions & 10 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::{Arc, RwLock};
use std::cell::RefCell;
use std::rc::Rc;

use color_eyre::Result;
use glib::IsA;
Expand All @@ -12,7 +13,7 @@ use crate::bridge_channel::BridgeChannel;
use crate::config::{BarPosition, CommonConfig, TransitionType};
use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry};
use crate::popup::Popup;
use crate::{send, write_lock};
use crate::send;

#[cfg(feature = "clipboard")]
pub mod clipboard;
Expand Down Expand Up @@ -178,7 +179,7 @@ pub fn create_module<TModule, TWidget, TSend, TRec>(
id: usize,
name: Option<String>,
info: &ModuleInfo,
popup: &Arc<RwLock<Popup>>,
popup: &Rc<RefCell<Popup>>,
) -> Result<ModuleParts<TWidget>>
where
TModule: Module<TWidget, SendMessage = TSend, ReceiveMessage = TRec>,
Expand Down Expand Up @@ -234,12 +235,12 @@ where

/// Registers the popup content with the popup.
fn register_popup_content(
popup: &Arc<RwLock<Popup>>,
popup: &Rc<RefCell<Popup>>,
id: usize,
name: String,
popup_content: ModulePopupParts,
) {
write_lock!(popup).register_content(id, name, popup_content);
popup.borrow_mut().register_content(id, name, popup_content);
}

/// Sets up the bridge channel receiver
Expand All @@ -251,7 +252,7 @@ fn setup_receiver<TSend>(
channel: BridgeChannel<ModuleUpdateEvent<TSend>>,
w_tx: glib::Sender<TSend>,
p_tx: glib::Sender<TSend>,
popup: Arc<RwLock<Popup>>,
popup: Rc<RefCell<Popup>>,
name: &'static str,
id: usize,
has_popup: bool,
Expand All @@ -273,7 +274,7 @@ fn setup_receiver<TSend>(
}
ModuleUpdateEvent::TogglePopup(button_id) => {
debug!("Toggling popup for {} [#{}]", name, id);
let mut popup = write_lock!(popup);
let mut popup = popup.borrow_mut();
if popup.is_visible() {
popup.hide();
} else {
Expand All @@ -289,7 +290,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::OpenPopup(button_id) => {
debug!("Opening popup for {} [#{}]", name, id);

let mut popup = write_lock!(popup);
let mut popup = popup.borrow_mut();
popup.hide();
popup.show(id, button_id);

Expand All @@ -302,7 +303,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::OpenPopupAt(geometry) => {
debug!("Opening popup for {} [#{}]", name, id);

let mut popup = write_lock!(popup);
let mut popup = popup.borrow_mut();
popup.hide();
popup.show_at(id, geometry);

Expand All @@ -315,7 +316,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::ClosePopup => {
debug!("Closing popup for {} [#{}]", name, id);

let mut popup = write_lock!(popup);
let mut popup = popup.borrow_mut();
popup.hide();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/music/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ impl Module<Button> for MusicModule {
let tx = context.tx.clone();

context.widget_rx.attach(None, move |event| {
let ControllerEvent::Update(mut event) = event else { return Continue(true) };
let ControllerEvent::Update(mut event) = event else {
return Continue(true);
};

if let Some(event) = event.take() {
label.set_label(&event.display_string);
Expand Down

0 comments on commit fea1f18

Please sign in to comment.