mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
refactor: fix new clippy warnings, fmt
This commit is contained in:
parent
b9c41af0f7
commit
fea1f18524
6 changed files with 38 additions and 28 deletions
11
src/bar.rs
11
src/bar.rs
|
@ -4,14 +4,13 @@ use crate::modules::{
|
||||||
};
|
};
|
||||||
use crate::popup::Popup;
|
use crate::popup::Popup;
|
||||||
use crate::unique_id::get_unique_usize;
|
use crate::unique_id::get_unique_usize;
|
||||||
use crate::{arc_rw, Config, GlobalState};
|
use crate::{Config, GlobalState};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use gtk::gdk::Monitor;
|
use gtk::gdk::Monitor;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Application, ApplicationWindow, IconTheme, Orientation};
|
use gtk::{Application, ApplicationWindow, IconTheme, Orientation};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
/// Creates a new window for a bar,
|
/// Creates a new window for a bar,
|
||||||
|
@ -153,7 +152,7 @@ fn create_container(name: &str, orientation: Orientation) -> gtk::Box {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct BarLoadResult {
|
struct BarLoadResult {
|
||||||
popup: Arc<RwLock<Popup>>,
|
popup: Rc<RefCell<Popup>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads the configured modules onto a bar.
|
/// Loads the configured modules onto a bar.
|
||||||
|
@ -186,7 +185,7 @@ fn load_modules(
|
||||||
|
|
||||||
// popup ignores module location so can bodge this for now
|
// popup ignores module location so can bodge this for now
|
||||||
let popup = Popup::new(&info!(ModuleLocation::Left), config.popup_gap);
|
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 {
|
if let Some(modules) = config.start {
|
||||||
let info = info!(ModuleLocation::Left);
|
let info = info!(ModuleLocation::Left);
|
||||||
|
@ -214,7 +213,7 @@ fn add_modules(
|
||||||
content: >k::Box,
|
content: >k::Box,
|
||||||
modules: Vec<ModuleConfig>,
|
modules: Vec<ModuleConfig>,
|
||||||
info: &ModuleInfo,
|
info: &ModuleInfo,
|
||||||
popup: &Arc<RwLock<Popup>>,
|
popup: &Rc<RefCell<Popup>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let orientation = info.bar_position.get_orientation();
|
let orientation = info.bar_position.get_orientation();
|
||||||
|
|
||||||
|
@ -226,7 +225,7 @@ fn add_modules(
|
||||||
$id,
|
$id,
|
||||||
common.name.clone(),
|
common.name.clone(),
|
||||||
&info,
|
&info,
|
||||||
&Arc::clone(&popup),
|
&Rc::clone(&popup),
|
||||||
)?;
|
)?;
|
||||||
set_widget_identifiers(&widget_parts, &common);
|
set_widget_identifiers(&widget_parts, &common);
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,9 @@ fn find_desktop_file_by_filedata(app_id: &str, files: &[PathBuf]) -> Option<Path
|
||||||
let files = files
|
let files = files
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|file| {
|
.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());
|
desktop_files_cache.insert(file.clone(), parsed_desktop_file.clone());
|
||||||
Some((file.clone(), parsed_desktop_file))
|
Some((file.clone(), parsed_desktop_file))
|
||||||
|
@ -162,7 +164,9 @@ fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {
|
||||||
|
|
||||||
file.lines()
|
file.lines()
|
||||||
.filter_map(|line| {
|
.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 key = key.trim();
|
||||||
let value = value.trim();
|
let value = value.trim();
|
||||||
|
@ -185,7 +189,9 @@ fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {
|
||||||
|
|
||||||
/// Attempts to get the icon name from the app's `.desktop` file.
|
/// Attempts to get the icon name from the app's `.desktop` file.
|
||||||
pub fn get_desktop_icon_name(app_id: &str) -> Option<String> {
|
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);
|
let mut desktop_files_cache = lock!(DESKTOP_FILES);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::popup::Popup;
|
use crate::popup::Popup;
|
||||||
use crate::write_lock;
|
use std::cell::{RefCell, RefMut};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock, RwLockWriteGuard};
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Global application state shared across all bars.
|
/// Global application state shared across all bars.
|
||||||
///
|
///
|
||||||
|
@ -9,7 +9,7 @@ use std::sync::{Arc, RwLock, RwLockWriteGuard};
|
||||||
/// that is not otherwise accessible should be placed on here.
|
/// that is not otherwise accessible should be placed on here.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GlobalState {
|
pub struct GlobalState {
|
||||||
popups: HashMap<Box<str>, Arc<RwLock<Popup>>>,
|
popups: HashMap<Box<str>, Rc<RefCell<Popup>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalState {
|
impl GlobalState {
|
||||||
|
@ -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
|
&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
|
&mut self.popups
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_popup_mut<F, T>(&self, monitor_name: &str, f: F) -> Option<T>
|
pub fn with_popup_mut<F, T>(&self, monitor_name: &str, f: F) -> Option<T>
|
||||||
where
|
where
|
||||||
F: FnOnce(RwLockWriteGuard<Popup>) -> T,
|
F: FnOnce(RefMut<Popup>) -> T,
|
||||||
{
|
{
|
||||||
let popup = self.popups().get(monitor_name);
|
let popup = self.popups().get(monitor_name);
|
||||||
|
|
||||||
if let Some(popup) = popup {
|
if let Some(popup) = popup {
|
||||||
let popup = write_lock!(popup);
|
let popup = popup.borrow_mut();
|
||||||
Some(f(popup))
|
Some(f(popup))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -224,7 +224,9 @@ fn create_bars(
|
||||||
.get(i as usize)
|
.get(i as usize)
|
||||||
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;
|
.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(
|
config.monitors.as_ref().map_or_else(
|
||||||
|| {
|
|| {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::sync::{Arc, RwLock};
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use glib::IsA;
|
use glib::IsA;
|
||||||
|
@ -12,7 +13,7 @@ use crate::bridge_channel::BridgeChannel;
|
||||||
use crate::config::{BarPosition, CommonConfig, TransitionType};
|
use crate::config::{BarPosition, CommonConfig, TransitionType};
|
||||||
use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry};
|
use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry};
|
||||||
use crate::popup::Popup;
|
use crate::popup::Popup;
|
||||||
use crate::{send, write_lock};
|
use crate::send;
|
||||||
|
|
||||||
#[cfg(feature = "clipboard")]
|
#[cfg(feature = "clipboard")]
|
||||||
pub mod clipboard;
|
pub mod clipboard;
|
||||||
|
@ -178,7 +179,7 @@ pub fn create_module<TModule, TWidget, TSend, TRec>(
|
||||||
id: usize,
|
id: usize,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
info: &ModuleInfo,
|
info: &ModuleInfo,
|
||||||
popup: &Arc<RwLock<Popup>>,
|
popup: &Rc<RefCell<Popup>>,
|
||||||
) -> Result<ModuleParts<TWidget>>
|
) -> Result<ModuleParts<TWidget>>
|
||||||
where
|
where
|
||||||
TModule: Module<TWidget, SendMessage = TSend, ReceiveMessage = TRec>,
|
TModule: Module<TWidget, SendMessage = TSend, ReceiveMessage = TRec>,
|
||||||
|
@ -234,12 +235,12 @@ where
|
||||||
|
|
||||||
/// Registers the popup content with the popup.
|
/// Registers the popup content with the popup.
|
||||||
fn register_popup_content(
|
fn register_popup_content(
|
||||||
popup: &Arc<RwLock<Popup>>,
|
popup: &Rc<RefCell<Popup>>,
|
||||||
id: usize,
|
id: usize,
|
||||||
name: String,
|
name: String,
|
||||||
popup_content: ModulePopupParts,
|
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
|
/// Sets up the bridge channel receiver
|
||||||
|
@ -251,7 +252,7 @@ fn setup_receiver<TSend>(
|
||||||
channel: BridgeChannel<ModuleUpdateEvent<TSend>>,
|
channel: BridgeChannel<ModuleUpdateEvent<TSend>>,
|
||||||
w_tx: glib::Sender<TSend>,
|
w_tx: glib::Sender<TSend>,
|
||||||
p_tx: glib::Sender<TSend>,
|
p_tx: glib::Sender<TSend>,
|
||||||
popup: Arc<RwLock<Popup>>,
|
popup: Rc<RefCell<Popup>>,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
id: usize,
|
id: usize,
|
||||||
has_popup: bool,
|
has_popup: bool,
|
||||||
|
@ -273,7 +274,7 @@ fn setup_receiver<TSend>(
|
||||||
}
|
}
|
||||||
ModuleUpdateEvent::TogglePopup(button_id) => {
|
ModuleUpdateEvent::TogglePopup(button_id) => {
|
||||||
debug!("Toggling popup for {} [#{}]", name, id);
|
debug!("Toggling popup for {} [#{}]", name, id);
|
||||||
let mut popup = write_lock!(popup);
|
let mut popup = popup.borrow_mut();
|
||||||
if popup.is_visible() {
|
if popup.is_visible() {
|
||||||
popup.hide();
|
popup.hide();
|
||||||
} else {
|
} else {
|
||||||
|
@ -289,7 +290,7 @@ fn setup_receiver<TSend>(
|
||||||
ModuleUpdateEvent::OpenPopup(button_id) => {
|
ModuleUpdateEvent::OpenPopup(button_id) => {
|
||||||
debug!("Opening popup for {} [#{}]", name, id);
|
debug!("Opening popup for {} [#{}]", name, id);
|
||||||
|
|
||||||
let mut popup = write_lock!(popup);
|
let mut popup = popup.borrow_mut();
|
||||||
popup.hide();
|
popup.hide();
|
||||||
popup.show(id, button_id);
|
popup.show(id, button_id);
|
||||||
|
|
||||||
|
@ -302,7 +303,7 @@ fn setup_receiver<TSend>(
|
||||||
ModuleUpdateEvent::OpenPopupAt(geometry) => {
|
ModuleUpdateEvent::OpenPopupAt(geometry) => {
|
||||||
debug!("Opening popup for {} [#{}]", name, id);
|
debug!("Opening popup for {} [#{}]", name, id);
|
||||||
|
|
||||||
let mut popup = write_lock!(popup);
|
let mut popup = popup.borrow_mut();
|
||||||
popup.hide();
|
popup.hide();
|
||||||
popup.show_at(id, geometry);
|
popup.show_at(id, geometry);
|
||||||
|
|
||||||
|
@ -315,7 +316,7 @@ fn setup_receiver<TSend>(
|
||||||
ModuleUpdateEvent::ClosePopup => {
|
ModuleUpdateEvent::ClosePopup => {
|
||||||
debug!("Closing popup for {} [#{}]", name, id);
|
debug!("Closing popup for {} [#{}]", name, id);
|
||||||
|
|
||||||
let mut popup = write_lock!(popup);
|
let mut popup = popup.borrow_mut();
|
||||||
popup.hide();
|
popup.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,7 +216,9 @@ impl Module<Button> for MusicModule {
|
||||||
let tx = context.tx.clone();
|
let tx = context.tx.clone();
|
||||||
|
|
||||||
context.widget_rx.attach(None, move |event| {
|
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() {
|
if let Some(event) = event.take() {
|
||||||
label.set_label(&event.display_string);
|
label.set_label(&event.display_string);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue