mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
refactor: use new smart pointer macros throughout codebase
This commit is contained in:
parent
ac04cc27ce
commit
7016f7f79e
10 changed files with 23 additions and 25 deletions
|
@ -4,7 +4,7 @@ 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::Config;
|
use crate::{arc_rw, Config};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use gtk::gdk::Monitor;
|
use gtk::gdk::Monitor;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
@ -166,7 +166,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::new(RwLock::new(popup));
|
let popup = arc_rw!(popup);
|
||||||
|
|
||||||
if let Some(modules) = config.start {
|
if let Some(modules) = config.start {
|
||||||
let info = info!(ModuleLocation::Left);
|
let info = info!(ModuleLocation::Left);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::wayland::{self, ClipboardItem};
|
use super::wayland::{self, ClipboardItem};
|
||||||
use crate::{lock, try_send};
|
use crate::{arc_mut, lock, try_send};
|
||||||
use indexmap::map::Iter;
|
use indexmap::map::Iter;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -28,9 +28,9 @@ impl ClipboardClient {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
trace!("Initializing clipboard client");
|
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();
|
let senders = senders.clone();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{Workspace, WorkspaceClient, WorkspaceUpdate};
|
use super::{Workspace, WorkspaceClient, WorkspaceUpdate};
|
||||||
use crate::{lock, send};
|
use crate::{arc_mut, lock, send};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use hyprland::data::{Workspace as HWorkspace, Workspaces};
|
use hyprland::data::{Workspace as HWorkspace, Workspaces};
|
||||||
use hyprland::dispatch::{Dispatch, DispatchType, WorkspaceIdentifierWithSpecial};
|
use hyprland::dispatch::{Dispatch, DispatchType, WorkspaceIdentifierWithSpecial};
|
||||||
|
@ -7,7 +7,6 @@ use hyprland::event_listener::EventListenerMutable as EventListener;
|
||||||
use hyprland::prelude::*;
|
use hyprland::prelude::*;
|
||||||
use hyprland::shared::WorkspaceType;
|
use hyprland::shared::WorkspaceType;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use tokio::sync::broadcast::{channel, Receiver, Sender};
|
use tokio::sync::broadcast::{channel, Receiver, Sender};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
|
@ -36,11 +35,11 @@ impl EventClient {
|
||||||
let mut event_listener = EventListener::new();
|
let mut event_listener = EventListener::new();
|
||||||
|
|
||||||
// we need a lock to ensure events don't run at the same time
|
// 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
|
// 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 = 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();
|
let tx = tx.clone();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{MusicClient, PlayerUpdate, Status, Track};
|
use super::{MusicClient, PlayerUpdate, Status, Track};
|
||||||
use crate::clients::music::PlayerState;
|
use crate::clients::music::PlayerState;
|
||||||
use crate::{lock, send};
|
use crate::{arc_mut, lock, send};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use mpris::{DBusError, Event, Metadata, PlaybackStatus, Player, PlayerFinder};
|
use mpris::{DBusError, Event, Metadata, PlaybackStatus, Player, PlayerFinder};
|
||||||
|
@ -27,10 +27,10 @@ impl Client {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let (tx, rx) = channel(32);
|
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 current_player = current_player.clone();
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::unique_id::get_unique_usize;
|
use crate::unique_id::get_unique_usize;
|
||||||
use crate::{lock, send};
|
use crate::{arc_mut, lock, send};
|
||||||
use async_once::AsyncOnce;
|
use async_once::AsyncOnce;
|
||||||
use color_eyre::Report;
|
use color_eyre::Report;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -33,7 +33,7 @@ impl TrayEventReceiver {
|
||||||
let tray = StatusNotifierWatcher::new(rx).await?;
|
let tray = StatusNotifierWatcher::new(rx).await?;
|
||||||
let mut host = Box::pin(tray.create_notifier_host(&id)).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();
|
let b_tx = b_tx.clone();
|
||||||
|
|
|
@ -25,7 +25,7 @@ cfg_if! {
|
||||||
use super::ClipboardItem;
|
use super::ClipboardItem;
|
||||||
use super::wlr_data_control::manager::DataControlDeviceManagerState;
|
use super::wlr_data_control::manager::DataControlDeviceManagerState;
|
||||||
use crate::lock;
|
use crate::lock;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl WaylandClient {
|
||||||
seats: vec![],
|
seats: vec![],
|
||||||
handles: HashMap::new(),
|
handles: HashMap::new(),
|
||||||
#[cfg(feature = "clipboard")]
|
#[cfg(feature = "clipboard")]
|
||||||
clipboard: Arc::new(Mutex::new(None)),
|
clipboard: crate::arc_mut!(None),
|
||||||
toplevel_tx,
|
toplevel_tx,
|
||||||
#[cfg(feature = "clipboard")]
|
#[cfg(feature = "clipboard")]
|
||||||
clipboard_tx,
|
clipboard_tx,
|
||||||
|
|
|
@ -6,7 +6,7 @@ mod wl_seat;
|
||||||
mod wlr_foreign_toplevel;
|
mod wlr_foreign_toplevel;
|
||||||
|
|
||||||
use self::wlr_foreign_toplevel::manager::ToplevelManagerState;
|
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 cfg_if::cfg_if;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use smithay_client_toolkit::output::OutputState;
|
use smithay_client_toolkit::output::OutputState;
|
||||||
|
@ -105,7 +105,7 @@ impl ProvidesRegistryState for Environment {
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CLIENT: Arc<Mutex<WaylandClient>> = Arc::new(Mutex::new(WaylandClient::new()));
|
static ref CLIENT: Arc<Mutex<WaylandClient>> = arc_mut!(WaylandClient::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_client() -> Arc<Mutex<WaylandClient>> {
|
pub fn get_client() -> Arc<Mutex<WaylandClient>> {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#[cfg(feature = "ipc")]
|
#[cfg(feature = "ipc")]
|
||||||
use crate::ironvar::get_variable_manager;
|
use crate::ironvar::get_variable_manager;
|
||||||
use crate::script::{OutputStream, Script};
|
use crate::script::{OutputStream, Script};
|
||||||
use crate::{lock, send};
|
use crate::{arc_mut, lock, send};
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
|
|
||||||
/// A segment of a dynamic string,
|
/// A segment of a dynamic string,
|
||||||
|
@ -34,7 +33,7 @@ where
|
||||||
{
|
{
|
||||||
let tokens = parse_input(input);
|
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);
|
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||||
|
|
||||||
for (i, segment) in tokens.into_iter().enumerate() {
|
for (i, segment) in tokens.into_iter().enumerate() {
|
||||||
|
|
|
@ -100,7 +100,7 @@ macro_rules! write_lock {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! arc_mut {
|
macro_rules! arc_mut {
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
std::sync::Arc::new(std::Sync::Mutex::new($val))
|
std::sync::Arc::new(std::sync::Mutex::new($val))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::config::CommonConfig;
|
||||||
use crate::desktop_file::find_desktop_file;
|
use crate::desktop_file::find_desktop_file;
|
||||||
use crate::modules::launcher::item::AppearanceOptions;
|
use crate::modules::launcher::item::AppearanceOptions;
|
||||||
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
|
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 color_eyre::{Help, Report};
|
||||||
use glib::Continue;
|
use glib::Continue;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
@ -16,7 +16,7 @@ use gtk::{Button, Orientation};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
use tokio::sync::mpsc::{Receiver, Sender};
|
use tokio::sync::mpsc::{Receiver, Sender};
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error, trace};
|
||||||
|
@ -108,7 +108,7 @@ impl Module<gtk::Box> for LauncherModule {
|
||||||
.collect::<IndexMap<_, _>>()
|
.collect::<IndexMap<_, _>>()
|
||||||
});
|
});
|
||||||
|
|
||||||
let items = Arc::new(Mutex::new(items));
|
let items = arc_mut!(items);
|
||||||
|
|
||||||
let items2 = Arc::clone(&items);
|
let items2 = Arc::clone(&items);
|
||||||
let tx2 = tx.clone();
|
let tx2 = tx.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue