Skip to content

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

fix: type errors

Lars Berger6eca375b02ec
diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 00000000..50a43500
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,14 @@
+[unstable]
+# Enables Cargo artifact dependencies.
+#
+# This allows a crate to depend on a specific binary artifact from another
+# crate. This is used as part of the build process for `x86_64` targets using
+# `rust-osdev/bootloader`, where a target crate depends on the kernel binary
+# artifact from the kernel core crate and links it with the bootloader binary in
+# a `build.rs` script.
+#
+# Artifact dependencies are also used by `manganese` to depend on binary crates
+# as normal Cargo.toml dependencies.
+#
+# See: https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies
+bindeps = true
diff --git a/Cargo.lock b/Cargo.lock
index c478af43..a33d3f18 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -368,6 +368,15 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd"
+[[package]]
+name = "home"
+version = "0.5.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
+dependencies = [
+ "windows-sys 0.52.0",
+]
+
[[package]]
name = "http"
version = "1.0.0"
@@ -412,23 +421,18 @@ dependencies = [
"anyhow",
]
-[[package]]
-name = "ipc-server"
-version = "0.0.0"
-dependencies = [
- "anyhow",
- "futures-util",
- "ipc-client",
- "tokio",
- "tokio-tungstenite",
-]
-
[[package]]
name = "itoa"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
[[package]]
name = "libc"
version = "0.2.153"
@@ -477,6 +481,16 @@ dependencies = [
"windows-sys 0.48.0",
]
+[[package]]
+name = "nu-ansi-term"
+version = "0.46.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
+dependencies = [
+ "overload",
+ "winapi",
+]
+
[[package]]
name = "num_cpus"
version = "1.16.0"
@@ -516,6 +530,18 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "once_cell"
+version = "1.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
+
+[[package]]
+name = "overload"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
+
[[package]]
name = "parking_lot"
version = "0.12.1"
@@ -722,6 +748,15 @@ dependencies = [
"digest",
]
+[[package]]
+name = "sharded-slab"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
+dependencies = [
+ "lazy_static",
+]
+
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
@@ -793,6 +828,16 @@ dependencies = [
"syn",
]
+[[package]]
+name = "thread_local"
+version = "1.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+]
+
[[package]]
name = "tinyvec"
version = "1.6.0"
@@ -850,6 +895,63 @@ dependencies = [
"tungstenite",
]
+[[package]]
+name = "tracing"
+version = "0.1.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
+dependencies = [
+ "pin-project-lite",
+ "tracing-attributes",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-attributes"
+version = "0.1.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "tracing-core"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
+dependencies = [
+ "once_cell",
+ "valuable",
+]
+
+[[package]]
+name = "tracing-log"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
+dependencies = [
+ "log",
+ "once_cell",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-subscriber"
+version = "0.3.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
+dependencies = [
+ "nu-ansi-term",
+ "sharded-slab",
+ "smallvec",
+ "thread_local",
+ "tracing-core",
+ "tracing-log",
+]
+
[[package]]
name = "tungstenite"
version = "0.21.0"
@@ -934,6 +1036,12 @@ dependencies = [
"getrandom",
]
+[[package]]
+name = "valuable"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
+
[[package]]
name = "version_check"
version = "0.9.4"
@@ -950,7 +1058,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
name = "watcher"
version = "0.0.0"
dependencies = [
+ "anyhow",
"ipc-client",
+ "tokio",
]
[[package]]
@@ -1170,13 +1280,17 @@ version = "0.0.0"
dependencies = [
"anyhow",
"clap",
+ "futures-util",
+ "home",
"ipc-client",
- "ipc-server",
"regex",
"serde",
"serde_json",
"serde_yaml",
"tokio",
+ "tokio-tungstenite",
+ "tracing",
+ "tracing-subscriber",
"uuid",
"watcher",
"windows",
diff --git a/Cargo.toml b/Cargo.toml
index 7f116ec6..067f4ff7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,3 +24,7 @@ windows = { version = "0.52", features = [
"Win32_UI_WindowsAndMessaging",
"Win32_System_SystemServices",
] }
+
+[unstable]
+# Enables Cargo artifact dependencies.
+bindeps = true
diff --git a/packages/wm/Cargo.toml b/packages/wm/Cargo.toml
index 4d7a968c..43433903 100644
--- a/packages/wm/Cargo.toml
+++ b/packages/wm/Cargo.toml
@@ -21,5 +21,11 @@ serde_yaml = "0.9"
regex = { workspace = true }
tokio = { workspace = true }
tokio-tungstenite = "0.21"
+tracing = "0.1"
+tracing-subscriber = "0.3"
windows = { workspace = true }
wineventhook = "0.9"
+
+[unstable]
+# Enables Cargo artifact dependencies.
+bindeps = true
diff --git a/packages/wm/src/common/direction.rs b/packages/wm/src/common/direction.rs
index 0691612b..be0dbb26 100644
--- a/packages/wm/src/common/direction.rs
+++ b/packages/wm/src/common/direction.rs
@@ -1,3 +1,5 @@
+use anyhow::{bail, Result};
+
pub enum Direction {
Left,
Right,
@@ -28,11 +30,11 @@ impl Direction {
/// Direction::from_str("left") // Direction::Left
/// ```
pub fn from_str(unparsed: &str) -> Result<Direction> {
- match self {
- "left" => Direction::Left,
- "right" => Direction::Right,
- "up" => Direction::Up,
- "down" => Direction::Down,
+ match unparsed {
+ "left" => Ok(Direction::Left),
+ "right" => Ok(Direction::Right),
+ "up" => Ok(Direction::Up),
+ "down" => Ok(Direction::Down),
_ => bail!("Not a valid direction: {}", unparsed),
}
}
diff --git a/packages/wm/src/common/mod.rs b/packages/wm/src/common/mod.rs
index 93fc0224..17cbb0fc 100644
--- a/packages/wm/src/common/mod.rs
+++ b/packages/wm/src/common/mod.rs
@@ -1,13 +1,12 @@
mod direction;
mod focus_mode;
-mod platform;
+pub mod platform;
mod rect_delta;
mod tiling_direction;
mod units;
pub use direction::*;
pub use focus_mode::*;
-pub use platform::*;
pub use rect_delta::*;
pub use tiling_direction::*;
pub use units::*;
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rs
index 82491fe0..3516b771 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm/src/common/platform/event_listener.rs
@@ -1,4 +1,5 @@
-use anyhow::Result;
+use tokio::sync::mpsc::{self, Receiver, Sender};
+use wineventhook::{EventFilter, WindowEvent, WindowEventHook};
pub enum PlatformEvent {
DisplaySettingsChanged,
@@ -21,16 +22,17 @@ pub struct EventListener {
}
impl EventListener {
- pub fn new() -> Self {
+ /// Start listening for platform events.
+ pub async fn start() -> Self {
let (event_tx, mut event_rx) = mpsc::unbounded_channel();
- Self { event_tx, event_rx }
- }
-
- pub async fn start(&mut self) -> Self {
- self.hook =
- WindowEventHook::hook(EventFilter::default(), self.event_tx).await?;
+ let hook =
+ WindowEventHook::hook(EventFilter::default(), event_tx).await?;
- self
+ Self {
+ event_tx,
+ event_rx,
+ hook,
+ }
}
}
diff --git a/packages/wm/src/common/platform/mod.rs b/packages/wm/src/common/platform/mod.rs
index 284b4248..0eed9f4e 100644
--- a/packages/wm/src/common/platform/mod.rs
+++ b/packages/wm/src/common/platform/mod.rs
@@ -1,3 +1,5 @@
mod event_listener;
+mod platform;
-use event_listener::*;
+pub use event_listener::*;
+pub use platform::*;
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs
index e69de29b..46b8afb4 100644
--- a/packages/wm/src/common/platform/platform.rs
+++ b/packages/wm/src/common/platform/platform.rs
@@ -0,0 +1,3 @@
+use windows::Win32::Foundation::HWND;
+
+pub type WindowHandle = HWND;
diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm/src/common/rect_delta.rs
index aba3a3d5..4887185f 100644
--- a/packages/wm/src/common/rect_delta.rs
+++ b/packages/wm/src/common/rect_delta.rs
@@ -1,3 +1,7 @@
+use anyhow::{bail, Result};
+
+use super::LengthValue;
+
pub struct RectDelta {
/// The delta in x-coordinates on the left of the rectangle.
left: LengthValue,
@@ -32,7 +36,7 @@ impl RectDelta {
match parts.len() {
1 => {
- let value = parse_length_value(&parts[0])?;
+ let value = LengthValue::from_str(&parts[0])?;
Ok(Self::new(
value.clone(),
value.clone(),
@@ -41,8 +45,8 @@ impl RectDelta {
))
}
2 => {
- let top_bottom = parse_length_value(&parts[0])?;
- let left_right = parse_length_value(&parts[1])?;
+ 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(),
@@ -51,19 +55,19 @@ impl RectDelta {
))
}
3 => {
- let top = parse_length_value(&parts[0])?;
- let left_right = parse_length_value(&parts[1])?;
- let bottom = parse_length_value(&parts[2])?;
+ 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 = parse_length_value(&parts[0])?;
- let right = parse_length_value(&parts[1])?;
- let bottom = parse_length_value(&parts[2])?;
- let left = parse_length_value(&parts[3])?;
+ 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))
}
- _ => Err("Invalid shorthand.".into()),
+ _ => bail!("Invalid shorthand."),
}
}
}
diff --git a/packages/wm/src/common/tiling_direction.rs b/packages/wm/src/common/tiling_direction.rs
index e9f91d1b..62556eec 100644
--- a/packages/wm/src/common/tiling_direction.rs
+++ b/packages/wm/src/common/tiling_direction.rs
@@ -1,3 +1,7 @@
+use anyhow::{bail, Result};
+
+use super::Direction;
+
pub enum TilingDirection {
Vertical,
Horizontal,
@@ -26,8 +30,8 @@ impl TilingDirection {
/// ```
pub fn from_direction(&self, direction: Direction) -> TilingDirection {
match direction {
- Direction::Left | Direction::Right => TilingDirection.Horizontal,
- Direction::Up | Direction::Down => TilingDirection.Vertical,
+ Direction::Left | Direction::Right => TilingDirection::Horizontal,
+ Direction::Up | Direction::Down => TilingDirection::Vertical,
}
}
@@ -38,9 +42,9 @@ impl TilingDirection {
/// TilingDirection::from_str("horizontal") // TilingDirection::Horizontal
/// ```
pub fn from_str(unparsed: &str) -> Result<TilingDirection> {
- match self {
- "horizontal" => TilingDirection.Horizontal,
- "vertical" => TilingDirection.Vertical,
+ match unparsed {
+ "horizontal" => Ok(TilingDirection::Horizontal),
+ "vertical" => Ok(TilingDirection::Vertical),
_ => bail!("Not a valid tiling direction: {}", unparsed),
}
}
diff --git a/packages/wm/src/common/units.rs b/packages/wm/src/common/units.rs
index bc193102..5cbc701b 100644
--- a/packages/wm/src/common/units.rs
+++ b/packages/wm/src/common/units.rs
@@ -1,5 +1,6 @@
use std::str::FromStr;
+use anyhow::{bail, Result};
use regex::Regex;
pub struct LengthValue {
@@ -19,7 +20,7 @@ impl LengthValue {
/// ```
/// LengthValue::from_str("100px") // { amount: 100.0, unit: LengthUnit::Pixel }
/// ```
- fn from_str(unparsed: &str) -> Result<LengthValue> {
+ pub fn from_str(unparsed: &str) -> Result<LengthValue> {
let units_regex = Regex::new(r"(\d+)(%|ppt|px)?")?;
let captures = units_regex.captures(unparsed)?;
@@ -27,8 +28,8 @@ impl LengthValue {
let unit_str = captures.get(2).map_or("", |m| m.as_str());
let unit = match unit_str {
- "px" | "" => Unit::Pixel,
- "%" => Unit::Percentage,
+ "px" | "" => LengthUnit::Pixel,
+ "%" => LengthUnit::Percentage,
_ => bail!("Not a valid unit '{}'.", unit_str),
};
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs
index 0183df5d..19807696 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/containers/container.rs
@@ -1,5 +1,6 @@
use std::sync::Arc;
+use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::container_type::ContainerType;
@@ -35,7 +36,7 @@ pub enum Container {
Window(Window),
}
-pub trait Container {
+pub trait Containeraa {
/// Derived container type (eg. `ContainerType::Monitor`).
fn r#type(&self) -> ContainerType;
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index dcdcae3f..5fe2c2dd 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -1,8 +1,14 @@
use anyhow::Result;
-use ipc_client::DEFAULT_IPC_ADDR;
use futures_util::{SinkExt, StreamExt};
-use tokio::{net::TcpListener, sync::mpsc::UnboundedSender};
+use ipc_client::DEFAULT_IPC_ADDR;
+use tokio::{
+ net::TcpListener,
+ sync::mpsc::{self, UnboundedReceiver, UnboundedSender},
+};
use tokio_tungstenite::accept_async;
+use tracing::info;
+
+use crate::wm_state::WmState;
pub enum IpcMessage {
Monitors,
@@ -17,9 +23,12 @@ pub struct IpcServer {
}
impl IpcServer {
- pub fn new(message_tx: UnboundedSender<IpcMessage>) -> Self {
+ pub fn new() -> Self {
let (message_tx, mut message_rx) = mpsc::unbounded_channel::<i32>();
- Self { message_tx, message_rx }
+ Self {
+ message_tx,
+ message_rx,
+ }
}
pub async fn start(&self) -> Result<()> {
@@ -44,7 +53,11 @@ impl IpcServer {
todo!()
}
- pub async fn process_message(&self, _message: IpcMessage, wm_state: WmState) {
+ pub async fn process_message(
+ &self,
+ _message: IpcMessage,
+ wm_state: WmState,
+ ) {
todo!()
}
}
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 8ffd2719..26361192 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -1,25 +1,29 @@
+use std::env;
+
+use anyhow::{Context, Result};
use clap::Parser;
-use common::RectDelta;
-use ipc_client;
+use common::platform::EventListener;
+use ipc_client::{self, IpcClient};
+
use ipc_server::IpcServer;
-use tokio::sync::mpsc;
-use wineventhook::{EventFilter, WindowEventHook};
-use wm_state::WmState;
-use workspaces::Workspace;
+use tokio::process::Command;
+use tracing::info;
+use user_config::UserConfig;
+use wm::WindowManager;
use crate::cli::{Cli, CliCommand};
mod cli;
-mod ipc_server;
mod common;
mod containers;
+mod ipc_server;
mod monitors;
mod user_config;
// mod windows;
mod wm;
-mod wm_state;
mod wm_command;
mod wm_event;
+mod wm_state;
mod workspaces;
#[tokio::main]
@@ -32,7 +36,7 @@ async fn main() {
}
_ => {
let args = std::env::args_os();
- ipc_client::new().send_raw(args).unwrap()
+ IpcClient::new().send_raw(args).unwrap()
}
}
}
@@ -41,7 +45,7 @@ async fn start_wm(config_path: Option<&str>) {
// Parse and validate user config.
let user_config = UserConfig::read(config_path).await;
- let event_listener = platform::EventListener::new().start().await;
+ let event_listener = EventListener::new().start().await;
let ipc_server = IpcServer::new().start().await;
// Start watcher process for restoring hidden windows on crash.
@@ -67,8 +71,9 @@ async fn start_wm(config_path: Option<&str>) {
}
}
-fn start_watcher_process() -> Result<()> {
- let watcher_path = env::var_os("CARGO_BIN_FILE_WATCHER").expect("watcher binary");
- let mut watcher = Command::new(watcher_path);
- watcher.status().expect("watcher failed").success();
+async fn start_watcher_process() -> Result<Command> {
+ let watcher_path = env::var_os("CARGO_BIN_FILE_WATCHER")
+ .context("Failed to resolve path to watcher process.")?;
+
+ Command::new(watcher_path);
}
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index d5090143..58d0fa48 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -1,3 +1,10 @@
+use std::path::PathBuf;
+
+use serde::{Deserialize, Deserializer};
+use tokio::fs;
+
+use crate::common::{LengthValue, RectDelta};
+
#[derive(Debug, Deserialize)]
pub struct GapsConfig {
/// Gap between adjacent windows.
@@ -47,46 +54,48 @@ pub struct UserConfig {
pub workspaces: Vec<WorkspaceConfig>,
}
-const SAMPLE_CONFIG: &str = include_str!("resources/sample-config.yaml");
+const SAMPLE_CONFIG: &str =
+ include_str!("../../../resources/sample-config.yaml");
impl UserConfig {
pub async fn read(config_path: Option<&str>) -> Self {
- let default_config_path = home::home_dir().context("Unable to get home directory.")?.resolve(".glzr/glazewm/config.yaml");
-
-
- let config_path = match config_path {
- Some(val) => PathBuf::from(val),
- None => default_config_path,
- };
-
- // Create new config file from sample if it doesn't exist.
- if !config_path.exists() {
- fs::create_dir_all(&config_path).with_context(|| {
- format!("Unable to create directory {}.", &config_path.display())
- })?;
+ let default_config_path = home::home_dir()
+ .context("Unable to get home directory.")?
+ .resolve(".glzr/glazewm/config.yaml");
+
+ let config_path = match config_path {
+ Some(val) => PathBuf::from(val),
+ None => default_config_path,
+ };
+
+ // Create new config file from sample if it doesn't exist.
+ if !config_path.exists() {
+ fs::create_dir_all(&config_path).await.with_context(|| {
+ format!("Unable to create directory {}.", &config_path.display())
+ })?;
+
+ fs::write(&config_path, SAMPLE_CONFIG)
+ .await
+ .with_context(|| {
+ format!("Unable to write to {}.", config_path.display())
+ })?;
+ }
- fs::write(&config_path, SAMPLE_CONFIG).with_context(|| {
- format!("Unable to write to {}.", config_path.display())
- })?;
+ let config_str = fs::read_to_string(&config_path)
+ .context("Unable to read config file.");
- let config_str = fs::read_to_string(&config_path).context("Unable to read config file.");
+ serde_yaml::from_str(config_str)
}
- UserConfig {
- gaps: GapsConfig::new(),
- focus_borders: FocusBordersConfig::new(),
- general: GeneralConfig::new(),
- bar: BarConfig::new(),
- bars: Vec::new(),
- workspaces: Vec::new(),
- window_rules: Vec::new(),
- keybindings: Vec::new(),
- binding_modes: Vec::new(),
- }
+ fn create_from_sample() -> Self {
+ let config_str = SAMPLE_CONFIG;
+ serde_yaml::from_str(config_str).unwrap()
}
}
-fn to_length_value<'de, D>(deserializer: D) -> Result<LengthValue, D::Error>
+fn to_length_value<'de, D>(
+ deserializer: D,
+) -> Result<LengthValue, D::Error>
where
D: Deserializer<'de>,
{
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 79eda87d..a644c9a1 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -1,11 +1,15 @@
+use wineventhook::WindowEvent;
+
+use crate::{user_config::UserConfig, wm_state::WmState};
+
pub struct WindowManager {
state: WmState,
}
impl WindowManager {
- pub fn new() -> Self {
+ pub fn new(user_config: UserConfig) -> Self {
Self {
- state: WmState::new(),
+ state: WmState::new(user_config),
}
}
diff --git a/packages/wm/src/wm_command.rs b/packages/wm/src/wm_command.rs
index a2fb4c44..b7d04bab 100644
--- a/packages/wm/src/wm_command.rs
+++ b/packages/wm/src/wm_command.rs
@@ -1,3 +1,8 @@
+use crate::{
+ common::{Direction, TilingDirection},
+ containers::Container,
+};
+
pub enum WmCommand {
CloseWindow(Container),
ExitWm,
diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rs
index c2988ac1..81d3ffb2 100644
--- a/packages/wm/src/wm_event.rs
+++ b/packages/wm/src/wm_event.rs
@@ -1,4 +1,10 @@
use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use crate::{
+ common::{platform::WindowHandle, TilingDirection},
+ containers::Container,
+};
#[derive(Debug, Deserialize, Clone, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
@@ -7,40 +13,40 @@ pub enum WmEvent {
new_binding_mode: String,
},
FocusChanged {
- focused_container: &dyn Container,
+ focused_container: Container,
},
FocusedContainerMoved {
- focused_container: &dyn Container,
+ focused_container: Container,
},
MonitorAdded {
- added_monitor: &dyn Container,
+ added_monitor: Container,
},
MonitorRemoved {
- removed_id: Guid,
+ removed_id: Uuid,
removed_device_name: String,
},
NativeFocusSynced {
- focused_container: &dyn Container,
+ focused_container: Container,
},
TilingDirectionChanged {
new_tiling_direction: TilingDirection,
},
UserConfigReloaded,
WindowManaged {
- managed_window: &dyn Container,
+ managed_window: Container,
},
WindowUnmanaged {
- unmanaged_id: Guid,
+ unmanaged_id: Uuid,
unmanaged_handle: WindowHandle,
},
WorkspaceActivated {
- activated_workspace: &dyn Container,
+ activated_workspace: Container,
},
WorkspaceDeactivated {
- deactivated_id: Guid,
+ deactivated_id: Uuid,
deactivated_name: String,
},
WorkingAreaResized {
- affected_monitor: &dyn Container,
+ affected_monitor: Container,
},
}
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index 4a6f0da3..b74ee4c9 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -4,16 +4,16 @@ use uuid::Uuid;
use crate::{
common::FocusMode,
containers::{Container, ContainerType, RootContainer},
+ user_config::UserConfig,
};
pub struct WmState {
- /// The root node of the container tree. Monitors are the children of the
+ /// Root node of the container tree. Monitors are the children of the
/// root node, followed by workspaces, then split containers/windows.
root_container: RootContainer,
- /// Containers (and their descendants) to redraw on the next invocation
- /// of `RedrawContainersCommand`.
- containers_to_redraw: Vec<Arc<dyn Container>>,
+ /// Containers (and their descendants) that have a pending redraw.
+ containers_to_redraw: Vec<Arc<Container>>,
/// Whether native focus needs to be reassigned to the WM's focused
/// container.
@@ -21,21 +21,25 @@ pub struct WmState {
/// Name of the currently active binding mode (if one is active).
active_binding_mode: Option<String>,
+
+ /// Parsed user config.
+ user_config: UserConfig,
}
impl WmState {
- pub fn new() -> Self {
+ pub fn new(user_config: UserConfig) -> Self {
Self {
root_container: RootContainer::new(),
containers_to_redraw: Vec::new(),
has_pending_focus_sync: false,
active_binding_mode: None,
+ user_config,
}
}
- /// The currently focused container. This can either be a `Window` or a
- /// `Workspace` without any descendant windows.
- pub fn focused_container(&self) -> Arc<dyn Container> {
+ /// 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
.last_focused_descendant()
@@ -51,10 +55,7 @@ impl WmState {
}
}
- pub fn get_container_by_id(
- &self,
- id: Uuid,
- ) -> Option<Arc<dyn Container>> {
+ pub fn container_by_id(&self, id: Uuid) -> Option<Arc<Container>> {
self
.root_container
.self_and_descendants()