Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

more fixes

Lars Berger4eebc20e3992
diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm/src/common/rect_delta.rs
index 6ab4ea2b..8476f13f 100644
--- a/packages/wm/src/common/rect_delta.rs
+++ b/packages/wm/src/common/rect_delta.rs
@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use super::LengthValue;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct RectDelta {
/// The delta in x-coordinates on the left of the rectangle.
left: LengthValue,
@@ -33,29 +33,39 @@ impl RectDelta {
}
pub fn from_str(unparsed: &str) -> Result<Self> {
- let mut parts = unparsed.split_whitespace();
+ let parts: Vec<&str> = unparsed.split_whitespace().collect();
- match parts.count() {
+ match parts.len() {
1 => {
- let value = LengthValue::from_str(parts.next().unwrap())?;
- Ok(Self::new(value, value, value, value))
+ let value = LengthValue::from_str(parts[0])?;
+ Ok(Self::new(
+ value.clone(),
+ value.clone(),
+ value.clone(),
+ value,
+ ))
}
2 => {
- let top_bottom = LengthValue::from_str(parts.next().unwrap())?;
- let left_right = LengthValue::from_str(parts.next().unwrap())?;
- Ok(Self::new(left_right, top_bottom, left_right, top_bottom))
+ let top_bottom = LengthValue::from_str(parts[0])?;
+ let left_right = LengthValue::from_str(parts[1])?;
+ Ok(Self::new(
+ left_right.clone(),
+ top_bottom.clone(),
+ left_right,
+ top_bottom,
+ ))
}
3 => {
- let top = LengthValue::from_str(parts.next().unwrap())?;
- let left_right = LengthValue::from_str(parts.next().unwrap())?;
- let bottom = LengthValue::from_str(parts.next().unwrap())?;
- Ok(Self::new(left_right, top, left_right, bottom))
+ let top = LengthValue::from_str(parts[0])?;
+ let left_right = LengthValue::from_str(parts[1])?;
+ let bottom = LengthValue::from_str(parts[2])?;
+ Ok(Self::new(left_right.clone(), top, left_right, bottom))
}
4 => {
- let top = LengthValue::from_str(parts.next().unwrap())?;
- let right = LengthValue::from_str(parts.next().unwrap())?;
- let bottom = LengthValue::from_str(parts.next().unwrap())?;
- let left = LengthValue::from_str(parts.next().unwrap())?;
+ let top = LengthValue::from_str(parts[0])?;
+ let right = LengthValue::from_str(parts[1])?;
+ let bottom = LengthValue::from_str(parts[2])?;
+ let left = LengthValue::from_str(parts[3])?;
Ok(Self::new(left, top, right, bottom))
}
_ => bail!("Invalid shorthand."),
diff --git a/packages/wm/src/common/units.rs b/packages/wm/src/common/units.rs
index 1152b934..5442b837 100644
--- a/packages/wm/src/common/units.rs
+++ b/packages/wm/src/common/units.rs
@@ -3,13 +3,13 @@ use std::str::FromStr;
use anyhow::{bail, Context, Result};
use regex::Regex;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct LengthValue {
pub amount: f32,
pub unit: LengthUnit,
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub enum LengthUnit {
Pixel,
Percentage,
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs
index e55612bb..e45db193 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/containers/container.rs
@@ -44,15 +44,15 @@ impl Container {
}
pub fn parent(&self) -> Option<Arc<Container>> {
- self.inner().parent
+ self.inner().parent.clone()
}
pub fn set_parent(&mut self, parent: Option<Arc<Container>>) {
- self.inner().parent = parent;
+ self.inner_mut().parent = parent;
}
pub fn children(&self) -> Vec<Arc<Container>> {
- self.inner().children
+ self.inner().children.clone()
}
pub fn set_children(&self, children: Vec<Arc<Container>>) {
@@ -61,7 +61,7 @@ impl Container {
/// Order of which child containers last had focus.
pub fn child_focus_order(&self) -> Vec<Arc<Container>> {
- self.inner().child_focus_order
+ self.inner().child_focus_order.clone()
}
pub fn set_child_focus_order(
@@ -78,7 +78,7 @@ impl Container {
/// Index of this container in parent's child focus order.
pub fn focus_index(&self) -> u32 {
- match self.inner().parent {
+ match &self.inner().parent {
None => 0,
Some(p) => p
.child_focus_order()
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index dbed46d4..28608718 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
use anyhow::Result;
use futures_util::{SinkExt, StreamExt};
use ipc_client::DEFAULT_IPC_ADDR;
@@ -54,7 +56,7 @@ impl IpcServer {
pub async fn process_message(
&self,
_message: IpcMessage,
- wm_state: WmState,
+ wm_state: Arc<WmState>,
) {
todo!()
}
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 9b1bae70..57e8fc1c 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -59,6 +59,8 @@ async fn start_wm(config_path: Option<String>) -> Result<()> {
let mut wm = WindowManager::start(user_config).await?;
loop {
+ let wm_state = wm.state.clone();
+
tokio::select! {
Some(event) = event_listener.event_rx.recv() => {
info!("Received platform event: {:?}", event);
@@ -70,7 +72,7 @@ async fn start_wm(config_path: Option<String>) -> Result<()> {
},
Some(ipc_message) = ipc_server.message_rx.recv() => {
info!("Received IPC message: {:?}", ipc_message);
- ipc_server.process_message(ipc_message, wm.state).await
+ ipc_server.process_message(ipc_message, wm_state).await
},
}
}
diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rs
index ae2724ea..a74ec199 100644
--- a/packages/wm/src/monitors/monitor.rs
+++ b/packages/wm/src/monitors/monitor.rs
@@ -29,28 +29,28 @@ impl Monitor {
}
}
-impl ContainerVariant for Monitor {
- fn inner(&self) -> InnerContainer {
- self.inner
- }
-
- fn r#type(&self) -> ContainerType {
- ContainerType::Monitor
- }
-
- fn height(&self) -> u32 {
- self.height
- }
-
- fn width(&self) -> u32 {
- self.width
- }
-
- fn x(&self) -> u32 {
- self.x
- }
-
- fn y(&self) -> u32 {
- self.y
- }
-}
+// impl ContainerVariant for Monitor {
+// fn inner(&self) -> InnerContainer {
+// self.inner
+// }
+
+// fn r#type(&self) -> ContainerType {
+// ContainerType::Monitor
+// }
+
+// fn height(&self) -> u32 {
+// self.height
+// }
+
+// fn width(&self) -> u32 {
+// self.width
+// }
+
+// fn x(&self) -> u32 {
+// self.x
+// }
+
+// fn y(&self) -> u32 {
+// self.y
+// }
+// }
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index c3956e62..8995eda6 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -1,3 +1,5 @@
+use std::sync::Arc;
+
use anyhow::Result;
use tokio::sync::mpsc::{self, UnboundedReceiver};
use wineventhook::WindowEvent;
@@ -8,7 +10,7 @@ use crate::{
pub struct WindowManager {
pub event_rx: UnboundedReceiver<WmEvent>,
- pub state: WmState,
+ pub state: Arc<WmState>,
}
impl WindowManager {
@@ -17,7 +19,7 @@ impl WindowManager {
Ok(Self {
event_rx,
- state: WmState::new(user_config),
+ state: Arc::new(WmState::new(user_config)),
})
}
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index 81880c7c..a82f0377 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -37,8 +37,8 @@ impl WmState {
}
}
- /// Get the currently focused container. This can either be a `Window` or
- /// a `Workspace` without any descendant windows.
+ // Get the currently focused container. This can either be a `Window` or
+ // a `Workspace` without any descendant windows.
// pub fn focused_container(&self) -> Arc<Container> {
// self
// .root_container