GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor: remove wrapping arc + mutex around `UserConfig`
Lars Berger1865c6ea2300
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rsindex 48dd8751..526100c8 100644--- a/packages/wm/src/common/platform/event_listener.rs+++ b/packages/wm/src/common/platform/event_listener.rs@@ -48,10 +48,9 @@ pub struct EventListener {impl EventListener {/// Initializes listener for platform events.///- /// Creates an instance of `EventListener`.- pub async fn start(config: &Arc<Mutex<UserConfig>>) -> Result<Self> {+ /// Returns an instance of `EventListener`.+ pub async fn start(config: &UserConfig) -> Result<Self> {let (event_tx, event_rx) = mpsc::unbounded_channel();- let config = config.lock().await;let event_window = EventWindow::new(event_tx,diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rsindex 36c73ed8..bc23c48a 100644--- a/packages/wm/src/common/platform/platform.rs+++ b/packages/wm/src/common/platform/platform.rs@@ -105,8 +105,8 @@ impl Platform {}/// Creates a new `EventListener` for the specified user config.- pub async fn new_event_listener(- config: &Arc<Mutex<UserConfig>>,+ pub async fn start_event_listener(+ config: &UserConfig,) -> anyhow::Result<EventListener> {EventListener::start(config).await}diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex 342bbbd9..de637166 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -59,7 +59,7 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {Platform::set_dpi_awareness()?;// Parse and validate user config.- let config = UserConfig::read(config_path).await?;+ let mut config = UserConfig::read(config_path).await?;// Start watcher process for restoring hidden windows on crash.start_watcher_process()?;@@ -70,11 +70,9 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {let mut ipc_server = IpcServer::start().await?;// Start listening for platform events.- let mut event_listener = Platform::new_event_listener(&config).await?;+ let mut event_listener = Platform::start_event_listener(&config).await?;loop {- let mut config = config.lock().await;-tokio::select! {Some(event) = event_listener.event_rx.recv() => {debug!("Received platform event: {:?}", event);diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rsindex d0d63813..1f2190d9 100644--- a/packages/wm/src/user_config.rs+++ b/packages/wm/src/user_config.rs@@ -9,7 +9,7 @@ use tokio::{use crate::{app_command::InvokeCommand,- common::{LengthValue, RectDelta, ColorRGBA},+ common::{ColorRGBA, LengthValue, RectDelta},monitors::Monitor,workspaces::Workspace,};@@ -26,9 +26,7 @@ pub struct UserConfig {impl UserConfig {/// Read and validate the user config from the given path.- pub async fn read(- config_path: Option<PathBuf>,- ) -> Result<Arc<Mutex<Self>>> {+ pub async fn read(config_path: Option<PathBuf>) -> Result<Self> {let default_config_path = home::home_dir().context("Unable to get home directory.")?.join(".glzr/glazewm/config.yaml");@@ -50,11 +48,11 @@ impl UserConfig {let (changes_tx, changes_rx) = mpsc::unbounded_channel::<()>();- Ok(Arc::new(Mutex::new(Self {+ Ok(Self {value: parsed_config,changes_rx,changes_tx,- })))+ })}/// Initialize a new config file from the sample config resource.diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex 11cb7593..c6ce831c 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -1,6 +1,6 @@use std::sync::Arc;-use anyhow::{Context, Result};+use anyhow::Context;use tokio::sync::{mpsc::{self},Mutex,@@ -33,8 +33,7 @@ pub struct WindowManager {}impl WindowManager {- pub async fn new(config: &Arc<Mutex<UserConfig>>) -> Result<Self> {- let config = config.lock().await;+ pub async fn new(config: &UserConfig) -> anyhow::Result<Self> {let (event_tx, event_rx) = mpsc::unbounded_channel();let mut state = WmState::new(event_tx);