diff --git a/src/bar.rs b/src/bar.rs index fc47fab..777c645 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -4,7 +4,7 @@ use crate::modules::{ }; use crate::popup::Popup; use crate::unique_id::get_unique_usize; -use crate::Config; +use crate::{arc_rw, Config}; use color_eyre::Result; use gtk::gdk::Monitor; use gtk::prelude::*; @@ -166,7 +166,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::new(RwLock::new(popup)); + let popup = arc_rw!(popup); if let Some(modules) = config.start { let info = info!(ModuleLocation::Left); diff --git a/src/clients/clipboard.rs b/src/clients/clipboard.rs index fb2623c..383c8af 100644 --- a/src/clients/clipboard.rs +++ b/src/clients/clipboard.rs @@ -1,5 +1,5 @@ use super::wayland::{self, ClipboardItem}; -use crate::{lock, try_send}; +use crate::{arc_mut, lock, try_send}; use indexmap::map::Iter; use indexmap::IndexMap; use lazy_static::lazy_static; @@ -28,9 +28,9 @@ impl ClipboardClient { fn new() -> Self { trace!("Initializing clipboard client"); - let senders = Arc::new(Mutex::new(Vec::<(EventSender, usize)>::new())); + let senders = arc_mut!(Vec::<(EventSender, usize)>::new()); - let cache = Arc::new(Mutex::new(ClipboardCache::new())); + let cache = arc_mut!(ClipboardCache::new()); { let senders = senders.clone(); diff --git a/src/clients/compositor/hyprland.rs b/src/clients/compositor/hyprland.rs index 9e11616..73fdfd9 100644 --- a/src/clients/compositor/hyprland.rs +++ b/src/clients/compositor/hyprland.rs @@ -1,5 +1,5 @@ use super::{Workspace, WorkspaceClient, WorkspaceUpdate}; -use crate::{lock, send}; +use crate::{arc_mut, lock, send}; use color_eyre::Result; use hyprland::data::{Workspace as HWorkspace, Workspaces}; use hyprland::dispatch::{Dispatch, DispatchType, WorkspaceIdentifierWithSpecial}; @@ -7,7 +7,6 @@ use hyprland::event_listener::EventListenerMutable as EventListener; use hyprland::prelude::*; use hyprland::shared::WorkspaceType; use lazy_static::lazy_static; -use std::sync::{Arc, Mutex}; use tokio::sync::broadcast::{channel, Receiver, Sender}; use tokio::task::spawn_blocking; use tracing::{debug, error, info}; @@ -36,11 +35,11 @@ impl EventClient { let mut event_listener = EventListener::new(); // we need a lock to ensure events don't run at the same time - let lock = Arc::new(Mutex::new(())); + let lock = arc_mut!(()); // cache the active workspace since Hyprland doesn't give us the prev active let active = Self::get_active_workspace().expect("Failed to get active workspace"); - let active = Arc::new(Mutex::new(Some(active))); + let active = arc_mut!(Some(active)); { let tx = tx.clone(); diff --git a/src/clients/music/mpris.rs b/src/clients/music/mpris.rs index e99556e..0ca5388 100644 --- a/src/clients/music/mpris.rs +++ b/src/clients/music/mpris.rs @@ -1,6 +1,6 @@ use super::{MusicClient, PlayerUpdate, Status, Track}; use crate::clients::music::PlayerState; -use crate::{lock, send}; +use crate::{arc_mut, lock, send}; use color_eyre::Result; use lazy_static::lazy_static; use mpris::{DBusError, Event, Metadata, PlaybackStatus, Player, PlayerFinder}; @@ -27,10 +27,10 @@ impl Client { fn new() -> Self { let (tx, rx) = channel(32); - let current_player = Arc::new(Mutex::new(None)); + let current_player = arc_mut!(None); { - let players_list = Arc::new(Mutex::new(HashSet::new())); + let players_list = arc_mut!(HashSet::new()); let current_player = current_player.clone(); let tx = tx.clone(); diff --git a/src/clients/system_tray.rs b/src/clients/system_tray.rs index 9375453..f10a897 100644 --- a/src/clients/system_tray.rs +++ b/src/clients/system_tray.rs @@ -1,5 +1,5 @@ use crate::unique_id::get_unique_usize; -use crate::{lock, send}; +use crate::{arc_mut, lock, send}; use async_once::AsyncOnce; use color_eyre::Report; use lazy_static::lazy_static; @@ -33,7 +33,7 @@ impl TrayEventReceiver { let tray = StatusNotifierWatcher::new(rx).await?; let mut host = Box::pin(tray.create_notifier_host(&id)).await?; - let tray = Arc::new(Mutex::new(BTreeMap::new())); + let tray = arc_mut!(BTreeMap::new()); { let b_tx = b_tx.clone(); diff --git a/src/clients/wayland/client.rs b/src/clients/wayland/client.rs index 5c16348..2a1a874 100644 --- a/src/clients/wayland/client.rs +++ b/src/clients/wayland/client.rs @@ -25,7 +25,7 @@ cfg_if! { use super::ClipboardItem; use super::wlr_data_control::manager::DataControlDeviceManagerState; use crate::lock; - use std::sync::{Arc, Mutex}; + use std::sync::Arc; } } @@ -138,7 +138,7 @@ impl WaylandClient { seats: vec![], handles: HashMap::new(), #[cfg(feature = "clipboard")] - clipboard: Arc::new(Mutex::new(None)), + clipboard: crate::arc_mut!(None), toplevel_tx, #[cfg(feature = "clipboard")] clipboard_tx, diff --git a/src/clients/wayland/mod.rs b/src/clients/wayland/mod.rs index faf5d6c..014c786 100644 --- a/src/clients/wayland/mod.rs +++ b/src/clients/wayland/mod.rs @@ -6,7 +6,7 @@ mod wl_seat; mod wlr_foreign_toplevel; use self::wlr_foreign_toplevel::manager::ToplevelManagerState; -use crate::{delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager}; +use crate::{arc_mut, delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager}; use cfg_if::cfg_if; use lazy_static::lazy_static; use smithay_client_toolkit::output::OutputState; @@ -105,7 +105,7 @@ impl ProvidesRegistryState for Environment { } lazy_static! { - static ref CLIENT: Arc> = Arc::new(Mutex::new(WaylandClient::new())); + static ref CLIENT: Arc> = arc_mut!(WaylandClient::new()); } pub fn get_client() -> Arc> { diff --git a/src/dynamic_value/dynamic_string.rs b/src/dynamic_value/dynamic_string.rs index d9332f0..32c034e 100644 --- a/src/dynamic_value/dynamic_string.rs +++ b/src/dynamic_value/dynamic_string.rs @@ -1,9 +1,8 @@ #[cfg(feature = "ipc")] use crate::ironvar::get_variable_manager; use crate::script::{OutputStream, Script}; -use crate::{lock, send}; +use crate::{arc_mut, lock, send}; use gtk::prelude::*; -use std::sync::{Arc, Mutex}; use tokio::spawn; /// A segment of a dynamic string, @@ -34,7 +33,7 @@ where { let tokens = parse_input(input); - let label_parts = Arc::new(Mutex::new(Vec::new())); + let label_parts = arc_mut!(vec![]); let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); for (i, segment) in tokens.into_iter().enumerate() { diff --git a/src/macros.rs b/src/macros.rs index fa2ea30..5e5e99f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -100,7 +100,7 @@ macro_rules! write_lock { #[macro_export] macro_rules! arc_mut { ($val:expr) => { - std::sync::Arc::new(std::Sync::Mutex::new($val)) + std::sync::Arc::new(std::sync::Mutex::new($val)) }; } diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index c7e166e..d12d7d5 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -8,7 +8,7 @@ use crate::config::CommonConfig; use crate::desktop_file::find_desktop_file; use crate::modules::launcher::item::AppearanceOptions; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; -use crate::{lock, send_async, try_send, write_lock}; +use crate::{arc_mut, lock, send_async, try_send, write_lock}; use color_eyre::{Help, Report}; use glib::Continue; use gtk::prelude::*; @@ -16,7 +16,7 @@ use gtk::{Button, Orientation}; use indexmap::IndexMap; use serde::Deserialize; use std::process::{Command, Stdio}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use tokio::spawn; use tokio::sync::mpsc::{Receiver, Sender}; use tracing::{debug, error, trace}; @@ -108,7 +108,7 @@ impl Module for LauncherModule { .collect::>() }); - let items = Arc::new(Mutex::new(items)); + let items = arc_mut!(items); let items2 = Arc::clone(&items); let tx2 = tx.clone();