Skip to content

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

feat: restructure crates; improve folder structure of `wm` crate (#908)

Lars Berger51de98bf7214
diff --git a/Cargo.lock b/Cargo.lock
index a7fe9867..a3b73247 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2034,19 +2034,6 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
-[[package]]
-name = "watcher"
-version = "0.0.0"
-dependencies = [
- "anyhow",
- "serde_json",
- "tauri-winres",
- "tokio",
- "tracing",
- "tracing-subscriber",
- "wm",
-]
-
[[package]]
name = "winapi"
version = "0.3.9"
@@ -2280,7 +2267,6 @@ dependencies = [
"enum-as-inner",
"futures-util",
"home",
- "regex",
"serde",
"serde_json",
"serde_yaml",
@@ -2292,8 +2278,78 @@ dependencies = [
"tracing-subscriber",
"tray-icon",
"uuid",
+ "wm-cli",
+ "wm-common",
+ "wm-ipc-client",
+ "wm-platform",
+]
+
+[[package]]
+name = "wm-cli"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "futures-util",
+ "serde_json",
+ "tauri-winres",
+ "tokio",
+ "tokio-tungstenite",
+ "uuid",
+ "wm-common",
+ "wm-ipc-client",
+]
+
+[[package]]
+name = "wm-common"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "clap",
+ "regex",
+ "serde",
+ "tracing",
+ "uuid",
+]
+
+[[package]]
+name = "wm-ipc-client"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "futures-util",
+ "serde_json",
+ "tokio",
+ "tokio-tungstenite",
+ "uuid",
+ "wm-common",
+]
+
+[[package]]
+name = "wm-platform"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "home",
+ "tokio",
+ "tracing",
"windows",
"windows-interface",
+ "wm-common",
+]
+
+[[package]]
+name = "wm-watcher"
+version = "0.0.0"
+dependencies = [
+ "anyhow",
+ "serde_json",
+ "tauri-winres",
+ "tokio",
+ "tracing",
+ "tracing-subscriber",
+ "wm-common",
+ "wm-ipc-client",
+ "wm-platform",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 51c019f6..823e759b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,12 +1,18 @@
[workspace]
resolver = "2"
members = ["packages/*"]
-default-members = ["packages/wm", "packages/watcher"]
+default-members = ["packages/wm", "packages/wm-cli", "packages/wm-watcher"]
[workspace.dependencies]
anyhow = { version = "1", features = ["backtrace"] }
+clap = { version = "4", features = ["derive"] }
+futures-util = "0.3"
+home = "0.5"
+serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
-tokio = { version = "1", features = ["full"] }
tauri-winres = "0.1"
+tokio = { version = "1", features = ["full"] }
+tokio-tungstenite = "0.21"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+uuid = { version = "1", features = ["v4", "serde"] }
diff --git a/packages/wm-cli/Cargo.toml b/packages/wm-cli/Cargo.toml
new file mode 100644
index 00000000..1d9149b8
--- /dev/null
+++ b/packages/wm-cli/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "wm-cli"
+version = "0.0.0"
+edition = "2021"
+
+[lib]
+path = "src/lib.rs"
+
+[[bin]]
+name = "glazewm-cli"
+path = "src/main.rs"
+
+[build-dependencies]
+tauri-winres = { workspace = true }
+
+[dependencies]
+anyhow = { workspace = true }
+futures-util = { workspace = true }
+serde_json = { workspace = true }
+tokio = { workspace = true }
+tokio-tungstenite = { workspace = true }
+uuid = { workspace = true }
+wm-common = { path = "../wm-common" }
+wm-ipc-client = { path = "../wm-ipc-client" }
diff --git a/packages/wm-cli/build.rs b/packages/wm-cli/build.rs
new file mode 100644
index 00000000..2581fd07
--- /dev/null
+++ b/packages/wm-cli/build.rs
@@ -0,0 +1,37 @@
+use tauri_winres::VersionInfo;
+
+fn main() {
+ println!("cargo:rerun-if-env-changed=VERSION_NUMBER");
+ let mut res = tauri_winres::WindowsResource::new();
+
+ res.set_icon("../../resources/assets/icon.ico");
+
+ // Set language to English (US).
+ res.set_language(0x0409);
+
+ res.set("OriginalFilename", "glazewm.exe");
+ res.set("ProductName", "GlazeWM CLI");
+ res.set("FileDescription", "GlazeWM CLI");
+
+ let version_parts = env!("VERSION_NUMBER")
+ .split('.')
+ .take(3)
+ .map(|part| part.parse().unwrap_or(0))
+ .collect::<Vec<u16>>();
+
+ let [major, minor, patch] =
+ <[u16; 3]>::try_from(version_parts).unwrap_or([0, 0, 0]);
+
+ let version_str = format!("{}.{}.{}.0", major, minor, patch);
+ res.set("FileVersion", &version_str);
+ res.set("ProductVersion", &version_str);
+
+ let version_u64 = ((major as u64) << 48)
+ | ((minor as u64) << 32)
+ | ((patch as u64) << 16);
+
+ res.set_version_info(VersionInfo::FILEVERSION, version_u64);
+ res.set_version_info(VersionInfo::PRODUCTVERSION, version_u64);
+
+ res.compile().unwrap();
+}
diff --git a/packages/wm-cli/src/lib.rs b/packages/wm-cli/src/lib.rs
new file mode 100644
index 00000000..adf4e6f9
--- /dev/null
+++ b/packages/wm-cli/src/lib.rs
@@ -0,0 +1,38 @@
+use anyhow::Context;
+use wm_common::ClientResponseData;
+use wm_ipc_client::IpcClient;
+
+pub async fn start(args: Vec<String>) -> anyhow::Result<()> {
+ let mut client = IpcClient::connect().await?;
+
+ let message = args[1..].join(" ");
+ client
+ .send(&message)
+ .await
+ .context("Failed to send command to IPC server.")?;
+
+ let client_response = client
+ .client_response(&message)
+ .await
+ .context("Failed to receive response from IPC server.")?;
+
+ match client_response.data {
+ // For event subscriptions, omit the initial response message and
+ // continuously output subsequent event messages.
+ Some(ClientResponseData::EventSubscribe(data)) => loop {
+ let event_subscription = client
+ .event_subscription(&data.subscription_id)
+ .await
+ .context("Failed to receive response from IPC server.")?;
+
+ println!("{}", serde_json::to_string(&event_subscription)?);
+ },
+ // For all other messages, output and exit when the first response
+ // message is received.
+ _ => {
+ println!("{}", serde_json::to_string(&client_response)?);
+ }
+ }
+
+ Ok(())
+}
diff --git a/packages/wm-cli/src/main.rs b/packages/wm-cli/src/main.rs
new file mode 100644
index 00000000..349dc5ae
--- /dev/null
+++ b/packages/wm-cli/src/main.rs
@@ -0,0 +1,44 @@
+use std::{env, process::Command};
+
+use anyhow::Context;
+use wm_cli::start;
+use wm_common::AppCommand;
+
+#[tokio::main]
+async fn main() -> anyhow::Result<()> {
+ let args = std::env::args().collect::<Vec<_>>();
+ let app_command = AppCommand::parse_with_default(&args);
+
+ match app_command {
+ AppCommand::Start { .. } => {
+ let exe_dir = env::current_exe()?
+ .parent()
+ .context("Failed to resolve path to the current executable.")?
+ .to_owned();
+
+ // Main executable is either in the current directory (when running
+ // debug/release builds) or in the parent directory when packaged.
+ let main_path =
+ [exe_dir.join("glazewm.exe"), exe_dir.join("../glazewm.exe")]
+ .into_iter()
+ .find(|path| path.exists())
+ .and_then(|path| path.to_str().map(|s| s.to_string()))
+ .context("Failed to resolve path to the main executable.")?;
+
+ // UIAccess applications can't be started directly, so we need to use
+ // CMD to start it. The start command is used to avoid a long-running
+ // CMD process in the background.
+ Command::new("cmd")
+ .args(
+ ["/C", "start", "", &main_path]
+ .into_iter()
+ .chain(args.iter().skip(1).map(|s| s.as_str())),
+ )
+ .spawn()
+ .context("Failed to start main executable.")?;
+
+ Ok(())
+ }
+ _ => start(args).await,
+ }
+}
diff --git a/packages/wm-common/Cargo.toml b/packages/wm-common/Cargo.toml
new file mode 100644
index 00000000..e133cab6
--- /dev/null
+++ b/packages/wm-common/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "wm-common"
+version = "0.0.0"
+edition = "2021"
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+anyhow = { workspace = true }
+clap = { workspace = true }
+regex = "1"
+serde = { workspace = true }
+tracing = { workspace = true }
+uuid = { workspace = true }
diff --git a/packages/wm/src/windows/active_drag.rs b/packages/wm-common/src/active_drag.rs
similarity index 100%
rename from packages/wm/src/windows/active_drag.rs
rename to packages/wm-common/src/active_drag.rs
diff --git a/packages/wm-common/src/app_command.rs b/packages/wm-common/src/app_command.rs
new file mode 100644
index 00000000..e079cc07
--- /dev/null
+++ b/packages/wm-common/src/app_command.rs
@@ -0,0 +1,371 @@
+use std::{iter, path::PathBuf};
+
+use clap::{error::KindFormatter, Args, Parser, ValueEnum};
+use serde::{Deserialize, Deserializer, Serialize};
+use tracing::Level;
+use uuid::Uuid;
+
+use crate::{Direction, LengthValue, OpacityValue, TilingDirection};
+
+const VERSION: &str = env!("VERSION_NUMBER");
+
+#[derive(Clone, Debug, Parser)]
+#[clap(author, version = VERSION, about, long_about = None)]
+pub enum AppCommand {
+ /// Starts the window manager.
+ Start {
+ /// Custom path to user config file.
+ ///
+ /// The default path is `%userprofile%/.glzr/glazewm/config.yaml`
+ #[clap(short = 'c', long = "config", value_hint = clap::ValueHint::FilePath)]
+ config_path: Option<PathBuf>,
+
+ #[clap(flatten)]
+ verbosity: Verbosity,
+ },
+
+ /// Retrieves and outputs a specific part of the window manager's state.
+ ///
+ /// Requires an already running instance of the window manager.
+ #[clap(alias = "q")]
+ Query {
+ #[clap(subcommand)]
+ command: QueryCommand,
+ },
+
+ /// Invokes a window manager command.
+ ///
+ /// Requires an already running instance of the window manager.
+ #[clap(alias = "c")]
+ Command {
+ #[clap(long = "id")]
+ subject_container_id: Option<Uuid>,
+
+ #[clap(subcommand)]
+ command: InvokeCommand,
+ },
+
+ /// Subscribes to one or more WM events (e.g. `window_close`), and
+ /// continuously outputs the incoming events.
+ ///
+ /// Requires an already running instance of the window manager.
+ Sub {
+ /// WM event(s) to subscribe to.
+ #[clap(short = 'e', long, value_enum, num_args = 1..)]
+ events: Vec<SubscribableEvent>,
+ },
+
+ /// Unsubscribes from a prior event subscription.
+ ///
+ /// Requires an already running instance of the window manager.
+ Unsub {
+ /// Subscription ID to unsubscribe from.
+ #[clap(long = "id")]
+ subscription_id: Uuid,
+ },
+}
+
+impl AppCommand {
+ /// Parses `AppCommand` from command line arguments.
+ ///
+ /// Defaults to `AppCommand::Start` if no arguments are provided.
+ pub fn parse_with_default(args: &Vec<String>) -> Self {
+ match args.len() == 1 {
+ true => AppCommand::Start {
+ config_path: None,
+ verbosity: Verbosity {
+ verbose: false,
+ quiet: false,
+ },
+ },
+ false => AppCommand::parse_from(args),
+ }
+ }
+}
+
+/// Verbosity flags to be used with `#[command(flatten)]`.
+#[derive(Args, Clone, Debug)]
+#[clap(about = None, long_about = None)]
+pub struct Verbosity {
+ /// Enables verbose logging.
+ #[clap(short = 'v', long, action)]
+ verbose: bool,
+
+ /// Disables logging.
+ #[clap(short = 'q', long, action, conflicts_with = "verbose")]
+ quiet: bool,
+}
+
+impl Verbosity {
+ /// Gets the log level based on the verbosity flags.
+ pub fn level(&self) -> Level {
+ match (self.verbose, self.quiet) {
+ (true, _) => Level::DEBUG,
+ (_, true) => Level::ERROR,
+ _ => Level::INFO,
+ }
+ }
+}
+
+#[derive(Clone, Debug, Parser)]
+pub enum QueryCommand {
+ /// Outputs metadata about the application (e.g. version number).
+ AppMetadata,
+ /// Outputs the active binding modes.
+ BindingModes,
+ /// Outputs the focused container (either a window or an empty
+ /// workspace).
+ Focused,
+ /// Outputs the tiling direction of the focused container.
+ TilingDirection,
+ /// Outputs all monitors.
+ Monitors,
+ /// Outputs all windows.
+ Windows,
+ /// Outputs all active workspaces.
+ Workspaces,
+ /// Outputs whether the window manager is paused.
+ Paused,
+}
+
+#[derive(Clone, Debug, PartialEq, ValueEnum)]
+#[clap(rename_all = "snake_case")]
+pub enum SubscribableEvent {
+ All,
+ ApplicationExiting,
+ BindingModesChanged,
+ FocusChanged,
+ FocusedContainerMoved,
+ MonitorAdded,
+ MonitorUpdated,
+ MonitorRemoved,
+ TilingDirectionChanged,
+ UserConfigChanged,
+ WindowManaged,
+ WindowUnmanaged,
+ WorkspaceActivated,
+ WorkspaceDeactivated,
+ WorkspaceUpdated,
+ PauseChanged,
+}
+
+#[derive(Clone, Debug, Parser, PartialEq, Serialize)]
+pub enum InvokeCommand {
+ AdjustBorders(InvokeAdjustBordersCommand),
+ Close,
+ Focus(InvokeFocusCommand),
+ Ignore,
+ Move(InvokeMoveCommand),
+ MoveWorkspace {
+ #[clap(long)]
+ direction: Direction,
+ },
+ Position(InvokePositionCommand),
+ Resize(InvokeResizeCommand),
+ SetFloating {
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ shown_on_top: Option<bool>,
+
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ centered: Option<bool>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ x_pos: Option<i32>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ y_pos: Option<i32>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ width: Option<LengthValue>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ height: Option<LengthValue>,
+ },
+ SetFullscreen {
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ shown_on_top: Option<bool>,
+
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ maximized: Option<bool>,
+ },
+ SetMinimized,
+ SetTiling,
+ SetTitleBarVisibility {
+ #[clap(required = true, value_enum)]
+ visibility: TitleBarVisibility,
+ },
+ SetOpacity {
+ #[clap(required = true, allow_hyphen_values = true)]
+ opacity: OpacityValue,
+ },
+ ShellExec {
+ #[clap(long, action)]
+ hide_window: bool,
+
+ #[clap(required = true, trailing_var_arg = true)]
+ command: Vec<String>,
+ },
+ // Reuse `InvokeResizeCommand` struct.
+ Size(InvokeResizeCommand),
+ ToggleFloating {
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ shown_on_top: Option<bool>,
+
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ centered: Option<bool>,
+ },
+ ToggleFullscreen {
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ shown_on_top: Option<bool>,
+
+ #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
+ maximized: Option<bool>,
+ },
+ ToggleMinimized,
+ ToggleTiling,
+ ToggleTilingDirection,
+ SetTilingDirection {
+ #[clap(required = true)]
+ tiling_direction: TilingDirection,
+ },
+ WmCycleFocus {
+ #[clap(long, default_value_t = false)]
+ omit_fullscreen: bool,
+
+ #[clap(long, default_value_t = true)]
+ omit_minimized: bool,
+ },
+ WmDisableBindingMode {
+ #[clap(long)]
+ name: String,
+ },
+ WmEnableBindingMode {
+ #[clap(long)]
+ name: String,
+ },
+ WmExit,
+ WmRedraw,
+ WmReloadConfig,
+ WmTogglePause,
+}
+
+impl<'de> Deserialize<'de> for InvokeCommand {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ // Clap expects an array of string slices where the first argument is
+ // the binary name/path. When deserializing commands from the user
+ // config, we therefore have to prepend an additional empty argument.
+ let unparsed = String::deserialize(deserializer)?;
+ let unparsed_split = iter::once("").chain(unparsed.split_whitespace());
+
+ InvokeCommand::try_parse_from(unparsed_split).map_err(|err| {
+ // Format the error message and remove the "error: " prefix.
+ let err_msg = err.apply::<KindFormatter>().to_string();
+ serde::de::Error::custom(err_msg.trim_start_matches("error: "))
+ })
+ }
+}
+
+#[derive(Clone, Debug, PartialEq, Serialize, ValueEnum)]
+#[clap(rename_all = "snake_case")]
+#[serde(rename_all = "snake_case")]
+pub enum TitleBarVisibility {
+ Shown,
+ Hidden,
+}
+
+#[derive(Args, Clone, Debug, PartialEq, Serialize)]
+#[group(required = true, multiple = true)]
+pub struct InvokeAdjustBordersCommand {
+ #[clap(long, allow_hyphen_values = true)]
+ pub top: Option<LengthValue>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub right: Option<LengthValue>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub bottom: Option<LengthValue>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub left: Option<LengthValue>,
+}
+
+#[derive(Args, Clone, Debug, PartialEq, Serialize)]
+#[group(required = true, multiple = false)]
+pub struct InvokeFocusCommand {
+ #[clap(long)]
+ pub direction: Option<Direction>,
+
+ #[clap(long)]
+ pub workspace: Option<String>,
+
+ #[clap(long)]
+ pub monitor: Option<usize>,
+
+ #[clap(long)]
+ pub next_active_workspace: bool,
+
+ #[clap(long)]
+ pub prev_active_workspace: bool,
+
+ #[clap(long)]
+ pub next_workspace: bool,
+
+ #[clap(long)]
+ pub prev_workspace: bool,
+
+ #[clap(long)]
+ pub recent_workspace: bool,
+}
+
+#[derive(Args, Clone, Debug, PartialEq, Serialize)]
+#[group(required = true, multiple = false)]
+pub struct InvokeMoveCommand {
+ /// Direction to move the window.
+ #[clap(long)]
+ pub direction: Option<Direction>,
+
+ /// Name of workspace to move the window.
+ #[clap(long)]
+ pub workspace: Option<String>,
+
+ #[clap(long)]
+ pub next_active_workspace: bool,
+
+ #[clap(long)]
+ pub prev_active_workspace: bool,
+
+ #[clap(long)]
+ pub next_workspace: bool,
+
+ #[clap(long)]
+ pub prev_workspace: bool,
+
+ #[clap(long)]
+ pub recent_workspace: bool,
+}
+
+#[derive(Args, Clone, Debug, PartialEq, Serialize)]
+#[group(required = true, multiple = true)]
+pub struct InvokeResizeCommand {
+ #[clap(long, allow_hyphen_values = true)]
+ pub width: Option<LengthValue>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub height: Option<LengthValue>,
+}
+
+#[derive(Args, Clone, Debug, PartialEq, Serialize)]
+#[group(required = true, multiple = true)]
+pub struct InvokePositionCommand {
+ #[clap(long, action)]
+ pub centered: bool,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub x_pos: Option<i32>,
+
+ #[clap(long, allow_hyphen_values = true)]
+ pub y_pos: Option<i32>,
+}
diff --git a/packages/wm/src/common/color.rs b/packages/wm-common/src/color.rs
similarity index 100%
rename from packages/wm/src/common/color.rs
rename to packages/wm-common/src/color.rs
diff --git a/packages/wm/src/common/direction.rs b/packages/wm-common/src/direction.rs
similarity index 100%
rename from packages/wm/src/common/direction.rs
rename to packages/wm-common/src/direction.rs
diff --git a/packages/wm/src/common/display_state.rs b/packages/wm-common/src/display_state.rs
similarity index 100%
rename from packages/wm/src/common/display_state.rs
rename to packages/wm-common/src/display_state.rs
diff --git a/packages/wm/src/containers/container_dto.rs b/packages/wm-common/src/dtos/container_dto.rs
similarity index 74%
rename from packages/wm/src/containers/container_dto.rs
rename to packages/wm-common/src/dtos/container_dto.rs
index 1ee10117..d6faa4e4 100644
--- a/packages/wm/src/containers/container_dto.rs
+++ b/packages/wm-common/src/dtos/container_dto.rs
@@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize};
-use super::{RootContainerDto, SplitContainerDto};
-use crate::{
- monitors::MonitorDto, windows::WindowDto, workspaces::WorkspaceDto,
+use super::{
+ MonitorDto, RootContainerDto, SplitContainerDto, WindowDto, WorkspaceDto,
};
/// User-friendly representation of a container.
diff --git a/packages/wm-common/src/dtos/mod.rs b/packages/wm-common/src/dtos/mod.rs
new file mode 100644
index 00000000..132a2d70
--- /dev/null
+++ b/packages/wm-common/src/dtos/mod.rs
@@ -0,0 +1,13 @@
+mod container_dto;
+mod monitor_dto;
+mod root_container_dto;
+mod split_container_dto;
+mod window_dto;
+mod workspace_dto;
+
+pub use container_dto::*;
+pub use monitor_dto::*;
+pub use root_container_dto::*;
+pub use split_container_dto::*;
+pub use window_dto::*;
+pub use workspace_dto::*;
diff --git a/packages/wm-common/src/dtos/monitor_dto.rs b/packages/wm-common/src/dtos/monitor_dto.rs
new file mode 100644
index 00000000..fe700c37
--- /dev/null
+++ b/packages/wm-common/src/dtos/monitor_dto.rs
@@ -0,0 +1,29 @@
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use super::ContainerDto;
+use crate::Rect;
+
+/// User-friendly representation of a monitor.
+///
+/// Used for IPC and debug logging.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct MonitorDto {
+ pub id: Uuid,
+ pub parent_id: Option<Uuid>,
+ pub children: Vec<ContainerDto>,
+ pub child_focus_order: Vec<Uuid>,
+ pub has_focus: bool,
+ pub width: i32,
+ pub height: i32,
+ pub x: i32,
+ pub y: i32,
+ pub dpi: u32,
+ pub scale_factor: f32,
+ pub handle: isize,
+ pub device_name: String,
+ pub device_path: Option<String>,
+ pub hardware_id: Option<String>,
+ pub working_rect: Rect,
+}
diff --git a/packages/wm-common/src/dtos/root_container_dto.rs b/packages/wm-common/src/dtos/root_container_dto.rs
new file mode 100644
index 00000000..53181b67
--- /dev/null
+++ b/packages/wm-common/src/dtos/root_container_dto.rs
@@ -0,0 +1,16 @@
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use super::ContainerDto;
+
+/// User-friendly representation of a root container.
+///
+/// Used for IPC and debug logging.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct RootContainerDto {
+ pub id: Uuid,
+ pub parent_id: Option<Uuid>,
+ pub children: Vec<ContainerDto>,
+ pub child_focus_order: Vec<Uuid>,
+}
diff --git a/packages/wm-common/src/dtos/split_container_dto.rs b/packages/wm-common/src/dtos/split_container_dto.rs
new file mode 100644
index 00000000..c730072e
--- /dev/null
+++ b/packages/wm-common/src/dtos/split_container_dto.rs
@@ -0,0 +1,24 @@
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use super::ContainerDto;
+use crate::TilingDirection;
+
+/// User-friendly representation of a split container.
+///
+/// Used for IPC and debug logging.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SplitContainerDto {
+ pub id: Uuid,
+ pub parent_id: Option<Uuid>,
+ pub children: Vec<ContainerDto>,
+ pub child_focus_order: Vec<Uuid>,
+ pub has_focus: bool,
+ pub tiling_size: f32,
+ pub width: i32,
+ pub height: i32,
+ pub x: i32,
+ pub y: i32,
+ pub tiling_direction: TilingDirection,
+}
diff --git a/packages/wm/src/windows/window_dto.rs b/packages/wm-common/src/dtos/window_dto.rs
similarity index 89%
rename from packages/wm/src/windows/window_dto.rs
rename to packages/wm-common/src/dtos/window_dto.rs
index ff127981..589263c7 100644
--- a/packages/wm/src/windows/window_dto.rs
+++ b/packages/wm-common/src/dtos/window_dto.rs
@@ -1,8 +1,7 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
-use super::{ActiveDrag, WindowState};
-use crate::common::{DisplayState, Rect, RectDelta};
+use crate::{ActiveDrag, DisplayState, Rect, RectDelta, WindowState};
/// User-friendly representation of a tiling or non-tiling window.
///
diff --git a/packages/wm-common/src/dtos/workspace_dto.rs b/packages/wm-common/src/dtos/workspace_dto.rs
new file mode 100644
index 00000000..de6b5dfe
--- /dev/null
+++ b/packages/wm-common/src/dtos/workspace_dto.rs
@@ -0,0 +1,26 @@
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use super::ContainerDto;
+use crate::TilingDirection;
+
+/// User-friendly representation of a workspace.
+///
+/// Used for IPC and debug logging.
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct WorkspaceDto {
+ pub id: Uuid,
+ pub name: String,
+ pub display_name: Option<String>,
+ pub parent_id: Option<Uuid>,
+ pub children: Vec<ContainerDto>,
+ pub child_focus_order: Vec<Uuid>,
+ pub has_focus: bool,
+ pub is_displayed: bool,
+ pub width: i32,
+ pub height: i32,
+ pub x: i32,
+ pub y: i32,
+ pub tiling_direction: TilingDirection,
+}
diff --git a/packages/wm-common/src/ipc.rs b/packages/wm-common/src/ipc.rs
new file mode 100644
index 00000000..72fc6a10
--- /dev/null
+++ b/packages/wm-common/src/ipc.rs
@@ -0,0 +1,102 @@
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
+
+use crate::{BindingModeConfig, ContainerDto, TilingDirection, WmEvent};
+
+pub const DEFAULT_IPC_PORT: u32 = 6123;
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(tag = "messageType", rename_all = "snake_case")]
+pub enum ServerMessage {
+ ClientResponse(ClientResponseMessage),
+ EventSubscription(EventSubscriptionMessage),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ClientResponseMessage {
+ pub client_message: String,
+ pub data: Option<ClientResponseData>,
+ pub error: Option<String>,
+ pub success: bool,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub enum ClientResponseData {
+ AppMetadata(AppMetadataData),
+ BindingModes(BindingModesData),
+ Command(CommandData),
+ EventSubscribe(EventSubscribeData),
+ EventUnsubscribe,
+ Focused(FocusedData),
+ Monitors(MonitorsData),
+ TilingDirection(TilingDirectionData),
+ Windows(WindowsData),
+ Workspaces(WorkspacesData),
+ Paused(bool),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct AppMetadataData {
+ pub version: String,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BindingModesData {
+ pub binding_modes: Vec<BindingModeConfig>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct CommandData {
+ pub subject_container_id: Uuid,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct EventSubscribeData {
+ pub subscription_id: Uuid,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct FocusedData {
+ pub focused: ContainerDto,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct MonitorsData {
+ pub monitors: Vec<ContainerDto>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct TilingDirectionData {
+ pub tiling_direction: TilingDirection,
+ pub direction_container: ContainerDto,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct WindowsData {
+ pub windows: Vec<ContainerDto>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct WorkspacesData {
+ pub workspaces: Vec<ContainerDto>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct EventSubscriptionMessage {
+ pub data: Option<WmEvent>,
+ pub error: Option<String>,
+ pub subscription_id: Uuid,
+ pub success: bool,
+}
diff --git a/packages/wm/src/common/length_value.rs b/packages/wm-common/src/length_value.rs
similarity index 100%
rename from packages/wm/src/common/length_value.rs
rename to packages/wm-common/src/length_value.rs
diff --git a/packages/wm/src/common/mod.rs b/packages/wm-common/src/lib.rs
similarity index 54%
rename from packages/wm/src/common/mod.rs
rename to packages/wm-common/src/lib.rs
index 120c1399..2896f847 100644
--- a/packages/wm/src/common/mod.rs
+++ b/packages/wm-common/src/lib.rs
@@ -1,27 +1,35 @@
+mod active_drag;
+mod app_command;
mod color;
-pub mod commands;
mod direction;
mod display_state;
-pub mod events;
+mod dtos;
+mod ipc;
mod length_value;
-mod memo;
mod opacity_value;
-pub mod platform;
+mod parsed_config;
mod point;
mod rect;
mod rect_delta;
mod tiling_direction;
-mod try_warn;
-mod vec_deque_ext;
+mod utils;
+mod window_state;
+mod wm_event;
+pub use active_drag::*;
+pub use app_command::*;
pub use color::*;
pub use direction::*;
pub use display_state::*;
+pub use dtos::*;
+pub use ipc::*;
pub use length_value::*;
-pub use memo::*;
pub use opacity_value::*;
+pub use parsed_config::*;
pub use point::*;
pub use rect::*;
pub use rect_delta::*;
pub use tiling_direction::*;
-pub use vec_deque_ext::*;
+pub use utils::*;
+pub use window_state::*;
+pub use wm_event::*;
diff --git a/packages/wm/src/common/opacity_value.rs b/packages/wm-common/src/opacity_value.rs
similarity index 100%
rename from packages/wm/src/common/opacity_value.rs
rename to packages/wm-common/src/opacity_value.rs
diff --git a/packages/wm-common/src/parsed_config.rs b/packages/wm-common/src/parsed_config.rs
new file mode 100644
index 00000000..73500fe0
--- /dev/null
+++ b/packages/wm-common/src/parsed_config.rs
@@ -0,0 +1,365 @@
+use serde::{Deserialize, Serialize};
+
+use crate::{
+ app_command::InvokeCommand, Color, LengthValue, OpacityValue, RectDelta,
+};
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct ParsedConfig {
+ pub binding_modes: Vec<BindingModeConfig>,
+ pub gaps: GapsConfig,
+ pub general: GeneralConfig,
+ pub keybindings: Vec<KeybindingConfig>,
+ pub window_behavior: WindowBehaviorConfig,
+ pub window_effects: WindowEffectsConfig,
+ pub window_rules: Vec<WindowRuleConfig>,
+ pub workspaces: Vec<WorkspaceConfig>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct BindingModeConfig {
+ /// Name of the binding mode.
+ pub name: String,
+
+ /// Display name of the binding mode.
+ pub display_name: Option<String>,
+
+ /// Keybindings that will be active when the binding mode is active.
+ pub keybindings: Vec<KeybindingConfig>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct GapsConfig {
+ /// Whether to scale the gaps with the DPI of the monitor.
+ #[serde(default = "default_bool::<true>")]
+ pub scale_with_dpi: bool,
+
+ /// Gap between adjacent windows.
+ pub inner_gap: LengthValue,
+
+ /// Gap between windows and the screen edge.
+ pub outer_gap: RectDelta,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct GeneralConfig {
+ /// Config for automatically moving the cursor.
+ pub cursor_jump: CursorJumpConfig,
+
+ /// Whether to automatically focus windows underneath the cursor.
+ #[serde(default = "default_bool::<false>")]
+ pub focus_follows_cursor: bool,
+
+ /// Whether to switch back and forth between the previously focused
+ /// workspace when focusing the current workspace.
+ #[serde(default = "default_bool::<true>")]
+ pub toggle_workspace_on_refocus: bool,
+
+ /// Commands to run when the WM has started (e.g. to run a script or
+ /// launch another application).
+ #[serde(default)]
+ pub startup_commands: Vec<InvokeCommand>,
+
+ /// Commands to run just before the WM is shutdown.
+ #[serde(default)]
+ pub shutdown_commands: Vec<InvokeCommand>,
+
+ /// Commands to run after the WM config has reloaded.
+ #[serde(default)]
+ pub config_reload_commands: Vec<InvokeCommand>,
+
+ /// How windows should be hidden when switching workspaces.
+ #[serde(default)]
+ pub hide_method: HideMethod,
+
+ /// Affects which windows get shown in the native Windows taskbar.
+ #[serde(default = "default_bool::<false>")]
+ pub show_all_in_taskbar: bool,
+}
+
+#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum HideMethod {
+ Hide,
+ #[default]
+ Cloak,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct CursorJumpConfig {
+ /// Whether to automatically move the cursor on the specified trigger.
+ #[serde(default = "default_bool::<true>")]
+ pub enabled: bool,
+
+ /// Trigger for cursor jump.
+ #[serde(default)]
+ pub trigger: CursorJumpTrigger,
+}
+
+#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum CursorJumpTrigger {
+ #[default]
+ MonitorFocus,
+ WindowFocus,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct KeybindingConfig {
+ /// Keyboard shortcut to trigger the keybinding.
+ pub bindings: Vec<String>,
+
+ /// WM commands to run when the keybinding is triggered.
+ pub commands: Vec<InvokeCommand>,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowBehaviorConfig {
+ /// New windows are created in this state whenever possible.
+ #[serde(default)]
+ pub initial_state: InitialWindowState,
+
+ /// Sets the default options for when a new window is created. This also
+ /// changes the defaults for when the state change commands, like
+ /// `set_floating`, are used without any flags.
+ pub state_defaults: WindowStateDefaultsConfig,
+}
+
+#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum InitialWindowState {
+ #[default]
+ Tiling,
+ Floating,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowStateDefaultsConfig {
+ pub floating: FloatingStateConfig,
+ pub fullscreen: FullscreenStateConfig,
+}
+
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct FloatingStateConfig {
+ /// Whether to center new floating windows.
+ #[serde(default = "default_bool::<true>")]
+ pub centered: bool,
+
+ /// Whether to show floating windows as always on top.
+ #[serde(default = "default_bool::<false>")]
+ pub shown_on_top: bool,
+}
+
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct FullscreenStateConfig {
+ /// Whether to prefer fullscreen windows to be maximized.
+ #[serde(default = "default_bool::<true>")]
+ pub maximized: bool,
+
+ /// Whether to show fullscreen windows as always on top.
+ #[serde(default = "default_bool::<false>")]
+ pub shown_on_top: bool,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowEffectsConfig {
+ /// Visual effects to apply to the focused window.
+ pub focused_window: WindowEffectConfig,
+
+ /// Visual effects to apply to non-focused windows.
+ pub other_windows: WindowEffectConfig,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowEffectConfig {
+ /// Config for optionally applying a colored border.
+ pub border: BorderEffectConfig,
+
+ /// Config for optionally hiding the title bar.
+ #[serde(default)]
+ pub hide_title_bar: HideTitleBarEffectConfig,
+
+ /// Config for optionally changing the corner style.
+ #[serde(default)]
+ pub corner_style: CornerEffectConfig,
+
+ /// Config for optionally applying transparency.
+ #[serde(default)]
+ pub transparency: TransparencyEffectConfig,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct BorderEffectConfig {
+ /// Whether to enable the effect.
+ #[serde(default = "default_bool::<false>")]
+ pub enabled: bool,
+
+ /// Color of the window border.
+ #[serde(default = "default_blue")]
+ pub color: Color,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, Default)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct HideTitleBarEffectConfig {
+ /// Whether to enable the effect.
+ #[serde(default = "default_bool::<false>")]
+ pub enabled: bool,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct CornerEffectConfig {
+ /// Whether to enable the effect.
+ #[serde(default = "default_bool::<false>")]
+ pub enabled: bool,
+
+ /// Style of the window corners.
+ #[serde(default)]
+ pub style: CornerStyle,
+}
+
+#[derive(
+ Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default,
+)]
+#[serde(rename_all = "snake_case")]
+pub enum CornerStyle {
+ #[default]
+ Default,
+ Square,
+ Rounded,
+ SmallRounded,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, Default)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct TransparencyEffectConfig {
+ /// Whether to enable the effect.
+ #[serde(default = "default_bool::<false>")]
+ pub enabled: bool,
+
+ /// The opacity to apply.
+ #[serde(default)]
+ pub opacity: OpacityValue,
+}
+
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowRuleConfig {
+ pub commands: Vec<InvokeCommand>,
+
+ #[serde(rename = "match")]
+ pub match_window: Vec<WindowMatchConfig>,
+
+ #[serde(default = "default_window_rule_on")]
+ pub on: Vec<WindowRuleEvent>,
+
+ #[serde(default = "default_bool::<true>")]
+ pub run_once: bool,
+}
+
+#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowMatchConfig {
+ #[serde(default)]
+ pub window_process: Option<MatchType>,
+
+ #[serde(default)]
+ pub window_class: Option<MatchType>,
+
+ #[serde(default)]
+ pub window_title: Option<MatchType>,
+}
+
+/// Due to limitations in `serde_yaml`, we need to use an untagged enum
+/// instead of a regular enum for serialization. Using a regular enum
+/// causes issues with flow-style objects in YAML.
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
+#[serde(untagged)]
+pub enum MatchType {
+ Equals { equals: String },
+ Includes { includes: String },
+ Regex { regex: String },
+ NotEquals { not_equals: String },
+ NotRegex { not_regex: String },
+}
+
+impl MatchType {
+ /// Whether the given value is a match for the match type.
+ pub fn is_match(&self, value: &str) -> bool {
+ match self {
+ MatchType::Equals { equals } => value == equals,
+ MatchType::Includes { includes } => value.contains(includes),
+ MatchType::Regex { regex } => regex::Regex::new(regex)
+ .map(|re| re.is_match(value))
+ .unwrap_or(false),
+ MatchType::NotEquals { not_equals } => value != not_equals,
+ MatchType::NotRegex { not_regex } => regex::Regex::new(not_regex)
+ .map(|re| !re.is_match(value))
+ .unwrap_or(false),
+ }
+ }
+}
+
+#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum WindowRuleEvent {
+ /// When a window receives native focus.
+ Focus,
+ /// When a window is initially managed.
+ Manage,
+ /// When the title of a window changes.
+ TitleChange,
+}
+
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WorkspaceConfig {
+ pub name: String,
+ pub display_name: Option<String>,
+ pub bind_to_monitor: Option<u32>,
+ #[serde(default = "default_bool::<false>")]
+ pub keep_alive: bool,
+}
+
+/// Helper function for setting a default value for a boolean field.
+const fn default_bool<const V: bool>() -> bool {
+ V
+}
+
+/// Helper function for setting a default value for a color field.
+const fn default_blue() -> Color {
+ Color {
+ r: 140,
+ g: 190,
+ b: 255,
+ a: 255,
+ }
+}
+
+/// Helper function for setting a default value for window rule events.
+fn default_window_rule_on() -> Vec<WindowRuleEvent> {
+ vec![WindowRuleEvent::Manage, WindowRuleEvent::TitleChange]
+}
+
+impl Default for CornerEffectConfig {
+ fn default() -> Self {
+ CornerEffectConfig {
+ enabled: false,
+ style: CornerStyle::Default,
+ }
+ }
+}
diff --git a/packages/wm/src/common/point.rs b/packages/wm-common/src/point.rs
similarity index 100%
rename from packages/wm/src/common/point.rs
rename to packages/wm-common/src/point.rs
diff --git a/packages/wm/src/common/rect.rs b/packages/wm-common/src/rect.rs
similarity index 100%
rename from packages/wm/src/common/rect.rs
rename to packages/wm-common/src/rect.rs
diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm-common/src/rect_delta.rs
similarity index 100%
rename from packages/wm/src/common/rect_delta.rs
rename to packages/wm-common/src/rect_delta.rs
diff --git a/packages/wm/src/common/tiling_direction.rs b/packages/wm-common/src/tiling_direction.rs
similarity index 100%
rename from packages/wm/src/common/tiling_direction.rs
rename to packages/wm-common/src/tiling_direction.rs
diff --git a/packages/wm/src/common/memo.rs b/packages/wm-common/src/utils/memo.rs
similarity index 100%
rename from packages/wm/src/common/memo.rs
rename to packages/wm-common/src/utils/memo.rs
diff --git a/packages/wm-common/src/utils/mod.rs b/packages/wm-common/src/utils/mod.rs
new file mode 100644
index 00000000..0a9e41cb
--- /dev/null
+++ b/packages/wm-common/src/utils/mod.rs
@@ -0,0 +1,6 @@
+mod memo;
+mod try_warn;
+mod vec_deque_ext;
+
+pub use memo::*;
+pub use vec_deque_ext::*;
diff --git a/packages/wm/src/common/try_warn.rs b/packages/wm-common/src/utils/try_warn.rs
similarity index 100%
rename from packages/wm/src/common/try_warn.rs
rename to packages/wm-common/src/utils/try_warn.rs
diff --git a/packages/wm/src/common/vec_deque_ext.rs b/packages/wm-common/src/utils/vec_deque_ext.rs
similarity index 100%
rename from packages/wm/src/common/vec_deque_ext.rs
rename to packages/wm-common/src/utils/vec_deque_ext.rs
diff --git a/packages/wm/src/windows/window_state.rs b/packages/wm-common/src/window_state.rs
similarity index 61%
rename from packages/wm/src/windows/window_state.rs
rename to packages/wm-common/src/window_state.rs
index 065b041a..784eae04 100644
--- a/packages/wm/src/windows/window_state.rs
+++ b/packages/wm-common/src/window_state.rs
@@ -1,8 +1,10 @@
use serde::{Deserialize, Serialize};
-use crate::user_config::{
- FloatingStateConfig, FullscreenStateConfig, InitialWindowState,
- UserConfig,
+use crate::{
+ parsed_config::{
+ FloatingStateConfig, FullscreenStateConfig, InitialWindowState,
+ },
+ ParsedConfig,
};
/// Represents the possible states a window can have.
@@ -16,11 +18,11 @@ pub enum WindowState {
}
impl WindowState {
- pub fn default_from_config(config: &UserConfig) -> Self {
- match config.value.window_behavior.initial_state {
+ pub fn default_from_config(config: &ParsedConfig) -> Self {
+ match config.window_behavior.initial_state {
InitialWindowState::Tiling => WindowState::Tiling,
InitialWindowState::Floating => WindowState::Floating(
- config.value.window_behavior.state_defaults.floating.clone(),
+ config.window_behavior.state_defaults.floating.clone(),
),
}
}
diff --git a/packages/wm/src/wm_event.rs b/packages/wm-common/src/wm_event.rs
similarity index 92%
rename from packages/wm/src/wm_event.rs
rename to packages/wm-common/src/wm_event.rs
index 13dbdb0c..5e8731bf 100644
--- a/packages/wm/src/wm_event.rs
+++ b/packages/wm-common/src/wm_event.rs
@@ -2,9 +2,9 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::{
- common::TilingDirection,
- containers::ContainerDto,
- user_config::{BindingModeConfig, ParsedConfig},
+ dtos::ContainerDto,
+ parsed_config::{BindingModeConfig, ParsedConfig},
+ TilingDirection,
};
#[derive(Clone, Debug, Deserialize, Serialize)]
diff --git a/packages/wm-ipc-client/Cargo.toml b/packages/wm-ipc-client/Cargo.toml
new file mode 100644
index 00000000..96e5d100
--- /dev/null
+++ b/packages/wm-ipc-client/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "wm-ipc-client"
+version = "0.0.0"
+edition = "2021"
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+anyhow = { workspace = true }
+futures-util = { workspace = true }
+serde_json = { workspace = true }
+tokio = { workspace = true }
+tokio-tungstenite = { workspace = true }
+uuid = { workspace = true }
+wm-common = { path = "../wm-common" }
diff --git a/packages/wm/src/ipc_client.rs b/packages/wm-ipc-client/src/lib.rs
similarity index 98%
rename from packages/wm/src/ipc_client.rs
rename to packages/wm-ipc-client/src/lib.rs
index e0b202ae..d80560a4 100644
--- a/packages/wm/src/ipc_client.rs
+++ b/packages/wm-ipc-client/src/lib.rs
@@ -5,8 +5,7 @@ use tokio_tungstenite::{
connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream,
};
use uuid::Uuid;
-
-use crate::ipc_server::{
+use wm_common::{
ClientResponseMessage, EventSubscriptionMessage, ServerMessage,
DEFAULT_IPC_PORT,
};
diff --git a/packages/wm-platform/Cargo.toml b/packages/wm-platform/Cargo.toml
new file mode 100644
index 00000000..d0c244ca
--- /dev/null
+++ b/packages/wm-platform/Cargo.toml
@@ -0,0 +1,37 @@
+[package]
+name = "wm-platform"
+version = "0.0.0"
+edition = "2021"
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+anyhow = { workspace = true }
+home = { workspace = true }
+tokio = { workspace = true }
+tracing = { workspace = true }
+windows = { version = "0.52", features = [
+ "implement",
+ "Win32_Devices_HumanInterfaceDevice",
+ "Win32_Foundation",
+ "Win32_Graphics_Dwm",
+ "Win32_Graphics_Gdi",
+ "Win32_Security",
+ "Win32_System_Com",
+ "Win32_System_Environment",
+ "Win32_System_LibraryLoader",
+ "Win32_System_Registry",
+ "Win32_System_RemoteDesktop",
+ "Win32_System_SystemServices",
+ "Win32_System_Threading",
+ "Win32_UI_Accessibility",
+ "Win32_UI_HiDpi",
+ "Win32_UI_Input_Ime",
+ "Win32_UI_Input_KeyboardAndMouse",
+ "Win32_UI_Shell_Common",
+ "Win32_UI_TextServices",
+ "Win32_UI_WindowsAndMessaging",
+] }
+windows-interface = { version = "0.52" }
+wm-common = { path = "../wm-common" }
diff --git a/packages/wm/src/common/platform/com.rs b/packages/wm-platform/src/com.rs
similarity index 100%
rename from packages/wm/src/common/platform/com.rs
rename to packages/wm-platform/src/com.rs
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm-platform/src/event_listener.rs
similarity index 80%
rename from packages/wm/src/common/platform/event_listener.rs
rename to packages/wm-platform/src/event_listener.rs
index eb61d65c..ea30ef83 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm-platform/src/event_listener.rs
@@ -1,11 +1,9 @@
use tokio::sync::mpsc::{self, UnboundedReceiver};
+use wm_common::{
+ BindingModeConfig, InvokeCommand, KeybindingConfig, ParsedConfig, Point,
+};
use super::{EventWindow, NativeWindow};
-use crate::{
- app_command::InvokeCommand,
- common::Point,
- user_config::{BindingModeConfig, KeybindingConfig, UserConfig},
-};
#[derive(Debug)]
pub enum PlatformEvent {
@@ -43,13 +41,13 @@ impl EventListener {
/// Initializes listener for platform events.
///
/// Returns an instance of `EventListener`.
- pub fn start(config: &UserConfig) -> anyhow::Result<Self> {
+ pub fn start(config: &ParsedConfig) -> anyhow::Result<Self> {
let (event_tx, event_rx) = mpsc::unbounded_channel();
let event_window = EventWindow::new(
event_tx,
- &config.value.keybindings,
- config.value.general.focus_follows_cursor,
+ &config.keybindings,
+ config.general.focus_follows_cursor,
)?;
Ok(Self {
@@ -62,14 +60,13 @@ impl EventListener {
/// currently active binding modes.
pub fn update(
&mut self,
- config: &UserConfig,
+ config: &ParsedConfig,
binding_modes: &[BindingModeConfig],
paused: bool,
) {
// Modify keybindings based on active binding modes and paused state.
let keybindings = if paused {
&config
- .value
.keybindings
.iter()
.filter(|config| {
@@ -80,13 +77,12 @@ impl EventListener {
} else {
match binding_modes.first() {
Some(binding_mode) => &binding_mode.keybindings,
- None => &config.value.keybindings,
+ None => &config.keybindings,
}
};
- self.event_window.update(
- keybindings,
- config.value.general.focus_follows_cursor && !paused,
- );
+ self
+ .event_window
+ .update(keybindings, config.general.focus_follows_cursor && !paused);
}
}
diff --git a/packages/wm/src/common/platform/event_window.rs b/packages/wm-platform/src/event_window.rs
similarity index 98%
rename from packages/wm/src/common/platform/event_window.rs
rename to packages/wm-platform/src/event_window.rs
index aeb96c26..eb67ad9d 100644
--- a/packages/wm/src/common/platform/event_window.rs
+++ b/packages/wm-platform/src/event_window.rs
@@ -30,13 +30,11 @@ use windows::Win32::{
},
},
};
+use wm_common::{KeybindingConfig, Point};
use super::{
KeyboardHook, MouseMoveEvent, Platform, PlatformEvent, WindowEventHook,
-};
-use crate::{
- common::{platform::FOREGROUND_INPUT_IDENTIFIER, Point},
- user_config::KeybindingConfig,
+ FOREGROUND_INPUT_IDENTIFIER,
};
/// Global instance of sender for platform events.
diff --git a/packages/wm/src/common/platform/keyboard_hook.rs b/packages/wm-platform/src/keyboard_hook.rs
similarity index 99%
rename from packages/wm/src/common/platform/keyboard_hook.rs
rename to packages/wm-platform/src/keyboard_hook.rs
index 2e457634..68788c05 100644
--- a/packages/wm/src/common/platform/keyboard_hook.rs
+++ b/packages/wm-platform/src/keyboard_hook.rs
@@ -15,9 +15,9 @@ use windows::Win32::{
},
},
};
+use wm_common::KeybindingConfig;
use super::PlatformEvent;
-use crate::user_config::KeybindingConfig;
/// Global instance of `KeyboardHook`.
///
diff --git a/packages/wm-platform/src/lib.rs b/packages/wm-platform/src/lib.rs
new file mode 100644
index 00000000..c50f65a9
--- /dev/null
+++ b/packages/wm-platform/src/lib.rs
@@ -0,0 +1,22 @@
+#![feature(iterator_try_collect)]
+#![feature(once_cell_try)]
+
+mod com;
+mod event_listener;
+mod event_window;
+mod keyboard_hook;
+mod native_monitor;
+mod native_window;
+mod platform;
+mod single_instance;
+mod window_event_hook;
+
+pub use com::*;
+pub use event_listener::*;
+pub use event_window::*;
+pub use keyboard_hook::*;
+pub use native_monitor::*;
+pub use native_window::*;
+pub use platform::*;
+pub use single_instance::*;
+pub use window_event_hook::*;
diff --git a/packages/wm/src/common/platform/mod.rs b/packages/wm-platform/src/mod.rs
similarity index 100%
rename from packages/wm/src/common/platform/mod.rs
rename to packages/wm-platform/src/mod.rs
diff --git a/packages/wm/src/common/platform/native_monitor.rs b/packages/wm-platform/src/native_monitor.rs
similarity index 99%
rename from packages/wm/src/common/platform/native_monitor.rs
rename to packages/wm-platform/src/native_monitor.rs
index c0e88dda..55c66bf4 100644
--- a/packages/wm/src/common/platform/native_monitor.rs
+++ b/packages/wm-platform/src/native_monitor.rs
@@ -15,8 +15,7 @@ use windows::{
},
},
};
-
-use crate::common::Rect;
+use wm_common::Rect;
#[derive(Clone, Debug)]
pub struct NativeMonitor {
diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm-platform/src/native_window.rs
similarity index 98%
rename from packages/wm/src/common/platform/native_window.rs
rename to packages/wm-platform/src/native_window.rs
index fc3b29bb..7f13de8c 100644
--- a/packages/wm/src/common/platform/native_window.rs
+++ b/packages/wm-platform/src/native_window.rs
@@ -41,13 +41,12 @@ use windows::{
},
},
};
+use wm_common::{
+ Color, CornerStyle, HideMethod, LengthValue, Memo, OpacityValue, Rect,
+ RectDelta, WindowState,
+};
use super::{iapplication_view_collection, iservice_provider, COM_INIT};
-use crate::{
- common::{Color, LengthValue, Memo, OpacityValue, Rect, RectDelta},
- user_config::{CornerStyle, HideMethod},
- windows::WindowState,
-};
/// Magic number used to identify programmatic mouse inputs from our own
/// process.
@@ -777,6 +776,15 @@ impl NativeWindow {
// Whether to hide or show the window.
self.set_visible(is_visible, hide_method)
}
+
+ pub fn cleanup(&self) {
+ if let Err(err) = self.show() {
+ warn!("Failed to show window: {:?}", err);
+ }
+
+ _ = self.set_taskbar_visibility(true);
+ _ = self.set_border_color(None);
+ }
}
impl PartialEq for NativeWindow {
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm-platform/src/platform.rs
similarity index 99%
rename from packages/wm/src/common/platform/platform.rs
rename to packages/wm-platform/src/platform.rs
index 78cfaddb..21f30293 100644
--- a/packages/wm/src/common/platform/platform.rs
+++ b/packages/wm-platform/src/platform.rs
@@ -32,12 +32,12 @@ use windows::{
},
},
};
+use wm_common::{ParsedConfig, Point};
use super::{
native_monitor, native_window, EventListener, NativeMonitor,
NativeWindow, SingleInstance,
};
-use crate::{common::Point, user_config::UserConfig};
pub type WindowProcedure = WNDPROC;
@@ -118,7 +118,7 @@ impl Platform {
/// Creates a new `EventListener` for the specified user config.
pub fn start_event_listener(
- config: &UserConfig,
+ config: &ParsedConfig,
) -> anyhow::Result<EventListener> {
EventListener::start(config)
}
diff --git a/packages/wm/src/common/platform/single_instance.rs b/packages/wm-platform/src/single_instance.rs
similarity index 100%
rename from packages/wm/src/common/platform/single_instance.rs
rename to packages/wm-platform/src/single_instance.rs
diff --git a/packages/wm/src/common/platform/window_event_hook.rs b/packages/wm-platform/src/window_event_hook.rs
similarity index 100%
rename from packages/wm/src/common/platform/window_event_hook.rs
rename to packages/wm-platform/src/window_event_hook.rs
diff --git a/packages/watcher/Cargo.toml b/packages/wm-watcher/Cargo.toml
similarity index 69%
rename from packages/watcher/Cargo.toml
rename to packages/wm-watcher/Cargo.toml
index c12af0a2..894abd91 100644
--- a/packages/watcher/Cargo.toml
+++ b/packages/wm-watcher/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "watcher"
+name = "wm-watcher"
version = "0.0.0"
edition = "2021"
@@ -7,17 +7,15 @@ edition = "2021"
name = "glazewm-watcher"
path = "src/main.rs"
-[features]
-no_console = []
-
[build-dependencies]
tauri-winres = { workspace = true }
[dependencies]
-wm = { path = "../wm" }
-
anyhow = { workspace = true }
+serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
-serde_json = { workspace = true }
+wm-common = { path = "../wm-common" }
+wm-ipc-client = { path = "../wm-ipc-client" }
+wm-platform = { path = "../wm-platform" }
diff --git a/packages/watcher/build.rs b/packages/wm-watcher/build.rs
similarity index 100%
rename from packages/watcher/build.rs
rename to packages/wm-watcher/build.rs
diff --git a/packages/watcher/src/main.rs b/packages/wm-watcher/src/main.rs
similarity index 85%
rename from packages/watcher/src/main.rs
rename to packages/wm-watcher/src/main.rs
index 32fe9180..116bc39d 100644
--- a/packages/watcher/src/main.rs
+++ b/packages/wm-watcher/src/main.rs
@@ -1,15 +1,17 @@
-// Conditionally build the application with either a `windows` or `console`
-// subsystem (default is `console`). This determines whether a console
-// window is spawned on launch, if not already ran through a console.
-#![cfg_attr(feature = "no_console", windows_subsystem = "windows")]
+// The `windows` or `console` subsystem (default is `console`) determines
+// whether a console window is spawned on launch, if not already ran
+// through a console. The following prevents this additional console window
+// in release mode.
+#![cfg_attr(
+ all(not(debug_assertions), target_os = "windows"),
+ windows_subsystem = "windows"
+)]
use anyhow::{bail, Context};
use tracing::info;
-use wm::{
- cleanup::run_cleanup, common::platform::NativeWindow,
- containers::ContainerDto, ipc_client::IpcClient,
- ipc_server::ClientResponseData, windows::WindowDto, wm_event::WmEvent,
-};
+use wm_common::{ClientResponseData, ContainerDto, WindowDto, WmEvent};
+use wm_ipc_client::IpcClient;
+use wm_platform::NativeWindow;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@@ -38,7 +40,9 @@ async fn main() -> anyhow::Result<()> {
.map(NativeWindow::new)
.collect::<Vec<_>>();
- run_cleanup(managed_windows);
+ for window in managed_windows {
+ window.cleanup();
+ }
}
}
diff --git a/packages/wm/Cargo.toml b/packages/wm/Cargo.toml
index ad3b0690..957e1d26 100644
--- a/packages/wm/Cargo.toml
+++ b/packages/wm/Cargo.toml
@@ -7,15 +7,11 @@ license = "GPL-3"
edition = "2021"
default-run = "glazewm"
-[lib]
-path = "src/lib.rs"
-
[[bin]]
name = "glazewm"
path = "src/main.rs"
[features]
-no_console = []
ui_access = []
[build-dependencies]
@@ -23,42 +19,22 @@ tauri-winres = { workspace = true }
[dependencies]
anyhow = { workspace = true }
-clap = { version = "4", features = ["derive"] }
ambassador = "0.4"
+clap = { workspace = true }
enum-as-inner = "0.6"
-futures-util = "0.3"
-home = "0.5"
-uuid = { version = "1", features = ["v4", "serde"] }
-serde = { version = "1", features = ["derive"] }
+futures-util = { workspace = true }
+home = { workspace = true }
+serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = "0.9"
-regex = "1"
tokio = { workspace = true }
-tracing-appender = "0.2"
-tokio-tungstenite = "0.21"
+tokio-tungstenite = { workspace = true }
tracing = { workspace = true }
+tracing-appender = "0.2"
tracing-subscriber = { workspace = true }
tray-icon = "0.14"
-windows = { version = "0.52", features = [
- "implement",
- "Win32_Devices_HumanInterfaceDevice",
- "Win32_Foundation",
- "Win32_Graphics_Dwm",
- "Win32_Graphics_Gdi",
- "Win32_Security",
- "Win32_System_Com",
- "Win32_System_Environment",
- "Win32_System_LibraryLoader",
- "Win32_System_Registry",
- "Win32_System_RemoteDesktop",
- "Win32_System_SystemServices",
- "Win32_System_Threading",
- "Win32_UI_Accessibility",
- "Win32_UI_HiDpi",
- "Win32_UI_Input_Ime",
- "Win32_UI_Input_KeyboardAndMouse",
- "Win32_UI_Shell_Common",
- "Win32_UI_TextServices",
- "Win32_UI_WindowsAndMessaging",
-] }
-windows-interface = { version = "0.52" }
+uuid = { workspace = true }
+wm-common = { path = "../wm-common" }
+wm-cli = { path = "../wm-cli" }
+wm-platform = { path = "../wm-platform" }
+wm-ipc-client = { path = "../wm-ipc-client" }
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
deleted file mode 100644
index 71d2e9f2..00000000
--- a/packages/wm/src/app_command.rs
+++ /dev/null
@@ -1,912 +0,0 @@
-use std::{iter, path::PathBuf};
-
-use anyhow::{bail, Context};
-use clap::{error::KindFormatter, Args, Parser, ValueEnum};
-use serde::{Deserialize, Deserializer, Serialize};
-use tracing::{warn, Level};
-use uuid::Uuid;
-
-use crate::{
- common::{
- commands::{
- cycle_focus, disable_binding_mode, enable_binding_mode,
- reload_config, shell_exec, toggle_pause,
- },
- Direction, LengthValue, OpacityValue, RectDelta, TilingDirection,
- },
- containers::{
- commands::{
- focus_in_direction, set_tiling_direction, toggle_tiling_direction,
- },
- traits::CommonGetters,
- Container,
- },
- monitors::commands::focus_monitor,
- user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
- windows::{
- commands::{
- ignore_window, move_window_in_direction, move_window_to_workspace,
- resize_window, set_window_position, set_window_size,
- update_window_state, WindowPositionTarget,
- },
- traits::WindowGetters,
- WindowState,
- },
- wm_state::WmState,
- workspaces::{
- commands::{focus_workspace, move_workspace_in_direction},
- WorkspaceTarget,
- },
-};
-
-const VERSION: &str = env!("VERSION_NUMBER");
-
-#[derive(Clone, Debug, Parser)]
-#[clap(author, version = VERSION, about, long_about = None)]
-pub enum AppCommand {
- /// Starts the window manager.
- Start {
- /// Custom path to user config file.
- ///
- /// The default path is `%userprofile%/.glzr/glazewm/config.yaml`
- #[clap(short = 'c', long = "config", value_hint = clap::ValueHint::FilePath)]
- config_path: Option<PathBuf>,
-
- #[clap(flatten)]
- verbosity: Verbosity,
- },
-
- /// Retrieves and outputs a specific part of the window manager's state.
- ///
- /// Requires an already running instance of the window manager.
- #[clap(alias = "q")]
- Query {
- #[clap(subcommand)]
- command: QueryCommand,
- },
-
- /// Invokes a window manager command.
- ///
- /// Requires an already running instance of the window manager.
- #[clap(alias = "c")]
- Command {
- #[clap(long = "id")]
- subject_container_id: Option<Uuid>,
-
- #[clap(subcommand)]
- command: InvokeCommand,
- },
-
- /// Subscribes to one or more WM events (e.g. `window_close`), and
- /// continuously outputs the incoming events.
- ///
- /// Requires an already running instance of the window manager.
- Sub {
- /// WM event(s) to subscribe to.
- #[clap(short = 'e', long, value_enum, num_args = 1..)]
- events: Vec<SubscribableEvent>,
- },
-
- /// Unsubscribes from a prior event subscription.
- ///
- /// Requires an already running instance of the window manager.
- Unsub {
- /// Subscription ID to unsubscribe from.
- #[clap(long = "id")]
- subscription_id: Uuid,
- },
-}
-
-impl AppCommand {
- /// Parses `AppCommand` from command line arguments.
- ///
- /// Defaults to `AppCommand::Start` if no arguments are provided.
- pub fn parse_with_default(args: &Vec<String>) -> Self {
- match args.len() == 1 {
- true => AppCommand::Start {
- config_path: None,
- verbosity: Verbosity {
- verbose: false,
- quiet: false,
- },
- },
- false => AppCommand::parse_from(args),
- }
- }
-}
-
-/// Verbosity flags to be used with `#[command(flatten)]`.
-#[derive(Args, Clone, Debug)]
-#[clap(about = None, long_about = None)]
-pub struct Verbosity {
- /// Enables verbose logging.
- #[clap(short = 'v', long, action)]
- verbose: bool,
-
- /// Disables logging.
- #[clap(short = 'q', long, action, conflicts_with = "verbose")]
- quiet: bool,
-}
-
-impl Verbosity {
- /// Gets the log level based on the verbosity flags.
- pub fn level(&self) -> Level {
- match (self.verbose, self.quiet) {
- (true, _) => Level::DEBUG,
- (_, true) => Level::ERROR,
- _ => Level::INFO,
- }
- }
-}
-
-#[derive(Clone, Debug, Parser)]
-pub enum QueryCommand {
- /// Outputs metadata about the application (e.g. version number).
- AppMetadata,
- /// Outputs the active binding modes.
- BindingModes,
- /// Outputs the focused container (either a window or an empty
- /// workspace).
- Focused,
- /// Outputs the tiling direction of the focused container.
- TilingDirection,
- /// Outputs all monitors.
- Monitors,
- /// Outputs all windows.
- Windows,
- /// Outputs all active workspaces.
- Workspaces,
- /// Outputs whether the window manager is paused.
- Paused,
-}
-
-#[derive(Clone, Debug, PartialEq, ValueEnum)]
-#[clap(rename_all = "snake_case")]
-pub enum SubscribableEvent {
- All,
- ApplicationExiting,
- BindingModesChanged,
- FocusChanged,
- FocusedContainerMoved,
- MonitorAdded,
- MonitorUpdated,
- MonitorRemoved,
- TilingDirectionChanged,
- UserConfigChanged,
- WindowManaged,
- WindowUnmanaged,
- WorkspaceActivated,
- WorkspaceDeactivated,
- WorkspaceUpdated,
- PauseChanged,
-}
-
-#[derive(Clone, Debug, Parser, PartialEq, Serialize)]
-pub enum InvokeCommand {
- AdjustBorders(InvokeAdjustBordersCommand),
- Close,
- Focus(InvokeFocusCommand),
- Ignore,
- Move(InvokeMoveCommand),
- MoveWorkspace {
- #[clap(long)]
- direction: Direction,
- },
- Position(InvokePositionCommand),
- Resize(InvokeResizeCommand),
- SetFloating {
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- shown_on_top: Option<bool>,
-
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- centered: Option<bool>,
-
- #[clap(long, allow_hyphen_values = true)]
- x_pos: Option<i32>,
-
- #[clap(long, allow_hyphen_values = true)]
- y_pos: Option<i32>,
-
- #[clap(long, allow_hyphen_values = true)]
- width: Option<LengthValue>,
-
- #[clap(long, allow_hyphen_values = true)]
- height: Option<LengthValue>,
- },
- SetFullscreen {
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- shown_on_top: Option<bool>,
-
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- maximized: Option<bool>,
- },
- SetMinimized,
- SetTiling,
- SetTitleBarVisibility {
- #[clap(required = true, value_enum)]
- visibility: TitleBarVisibility,
- },
- SetOpacity {
- #[clap(required = true, allow_hyphen_values = true)]
- opacity: OpacityValue,
- },
- ShellExec {
- #[clap(long, action)]
- hide_window: bool,
-
- #[clap(required = true, trailing_var_arg = true)]
- command: Vec<String>,
- },
- // Reuse `InvokeResizeCommand` struct.
- Size(InvokeResizeCommand),
- ToggleFloating {
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- shown_on_top: Option<bool>,
-
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- centered: Option<bool>,
- },
- ToggleFullscreen {
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- shown_on_top: Option<bool>,
-
- #[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
- maximized: Option<bool>,
- },
- ToggleMinimized,
- ToggleTiling,
- ToggleTilingDirection,
- SetTilingDirection {
- #[clap(required = true)]
- tiling_direction: TilingDirection,
- },
- WmCycleFocus {
- #[clap(long, default_value_t = false)]
- omit_fullscreen: bool,
-
- #[clap(long, default_value_t = true)]
- omit_minimized: bool,
- },
- WmDisableBindingMode {
- #[clap(long)]
- name: String,
- },
- WmEnableBindingMode {
- #[clap(long)]
- name: String,
- },
- WmExit,
- WmRedraw,
- WmReloadConfig,
- WmTogglePause,
-}
-
-impl InvokeCommand {
- pub fn run(
- &self,
- subject_container: Container,
- state: &mut WmState,
- config: &mut UserConfig,
- ) -> anyhow::Result<()> {
- if subject_container.is_detached() {
- bail!("Cannot run command because subject container is detached.");
- }
-
- match self {
- InvokeCommand::AdjustBorders(args) => {
- match subject_container.as_window_container() {
- Ok(window) => {
- let args = args.clone();
- let border_delta = RectDelta::new(
- args.left.unwrap_or(LengthValue::from_px(0)),
- args.top.unwrap_or(LengthValue::from_px(0)),
- args.right.unwrap_or(LengthValue::from_px(0)),
- args.bottom.unwrap_or(LengthValue::from_px(0)),
- );
-
- window.set_border_delta(border_delta);
- state.pending_sync.containers_to_redraw.push(window.into());
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::Close => {
- match subject_container.as_window_container() {
- Ok(window) => {
- // Window handle might no longer be valid here.
- if let Err(err) = window.native().close() {
- warn!("Failed to close window: {:?}", err);
- }
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::Focus(args) => {
- if let Some(direction) = &args.direction {
- focus_in_direction(subject_container, direction, state)?;
- }
-
- if let Some(name) = &args.workspace {
- focus_workspace(
- WorkspaceTarget::Name(name.to_string()),
- state,
- config,
- )?;
- }
-
- if let Some(monitor_index) = &args.monitor {
- focus_monitor(*monitor_index, state, config)?;
- }
-
- if args.next_active_workspace {
- focus_workspace(WorkspaceTarget::NextActive, state, config)?;
- }
-
- if args.prev_active_workspace {
- focus_workspace(WorkspaceTarget::PreviousActive, state, config)?;
- }
-
- if args.next_workspace {
- focus_workspace(WorkspaceTarget::Next, state, config)?;
- }
-
- if args.prev_workspace {
- focus_workspace(WorkspaceTarget::Previous, state, config)?;
- }
-
- if args.recent_workspace {
- focus_workspace(WorkspaceTarget::Recent, state, config)?;
- }
-
- Ok(())
- }
- InvokeCommand::Ignore => {
- match subject_container.as_window_container() {
- Ok(window) => ignore_window(window, state),
- _ => Ok(()),
- }
- }
- InvokeCommand::Move(args) => {
- match subject_container.as_window_container() {
- Ok(window) => {
- if let Some(direction) = &args.direction {
- move_window_in_direction(
- window.clone(),
- direction,
- state,
- config,
- )?;
- };
-
- if let Some(name) = &args.workspace {
- move_window_to_workspace(
- window.clone(),
- WorkspaceTarget::Name(name.to_string()),
- state,
- config,
- )?;
- }
-
- if args.next_active_workspace {
- move_window_to_workspace(
- window.clone(),
- WorkspaceTarget::NextActive,
- state,
- config,
- )?;
- }
-
- if args.prev_active_workspace {
- move_window_to_workspace(
- window.clone(),
- WorkspaceTarget::PreviousActive,
- state,
- config,
- )?;
- }
-
- if args.next_workspace {
- move_window_to_workspace(
- window.clone(),
- WorkspaceTarget::Next,
- state,
- config,
- )?;
- }
-
- if args.prev_workspace {
- move_window_to_workspace(
- window.clone(),
- WorkspaceTarget::Previous,
- state,
- config,
- )?;
- }
-
- if args.recent_workspace {
- move_window_to_workspace(
- window,
- WorkspaceTarget::Recent,
- state,
- config,
- )?;
- }
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::MoveWorkspace { direction } => {
- let workspace =
- subject_container.workspace().context("No workspace.")?;
-
- move_workspace_in_direction(
- workspace,
- direction.clone(),
- state,
- config,
- )
- }
- InvokeCommand::Position(args) => {
- match subject_container.as_window_container() {
- Ok(window) => match args.centered {
- true => set_window_position(
- window,
- WindowPositionTarget::Centered,
- state,
- ),
- false => set_window_position(
- window,
- WindowPositionTarget::Coordinates(
- args.x_pos.clone(),
- args.y_pos.clone(),
- ),
- state,
- ),
- },
- _ => Ok(()),
- }
- }
- InvokeCommand::Resize(args) => {
- match subject_container.as_window_container() {
- Ok(window) => resize_window(
- window,
- args.width.clone(),
- args.height.clone(),
- state,
- ),
- _ => Ok(()),
- }
- }
- InvokeCommand::SetFloating {
- centered,
- shown_on_top,
- x_pos,
- y_pos,
- width,
- height,
- } => match subject_container.as_window_container() {
- Ok(window) => {
- let floating_defaults =
- &config.value.window_behavior.state_defaults.floating;
- let centered = centered.unwrap_or(floating_defaults.centered);
-
- let window = update_window_state(
- window.clone(),
- WindowState::Floating(FloatingStateConfig {
- centered,
- shown_on_top: shown_on_top
- .unwrap_or(floating_defaults.shown_on_top),
- }),
- state,
- config,
- )?;
-
- // Allow size and position to be set if window has not previously
- // been manually placed.
- if !window.has_custom_floating_placement() {
- if width.is_some() || height.is_some() {
- set_window_size(
- window.clone(),
- width.clone(),
- height.clone(),
- state,
- )?;
- }
-
- if centered {
- set_window_position(
- window,
- WindowPositionTarget::Centered,
- state,
- )?;
- } else if x_pos.is_some() || y_pos.is_some() {
- set_window_position(
- window,
- WindowPositionTarget::Coordinates(
- x_pos.clone(),
- y_pos.clone(),
- ),
- state,
- )?;
- }
- }
-
- Ok(())
- }
- _ => Ok(()),
- },
- InvokeCommand::SetFullscreen {
- maximized,
- shown_on_top,
- } => match subject_container.as_window_container() {
- Ok(window) => {
- let fullscreen_defaults =
- &config.value.window_behavior.state_defaults.fullscreen;
-
- update_window_state(
- window.clone(),
- WindowState::Fullscreen(FullscreenStateConfig {
- maximized: maximized
- .unwrap_or(fullscreen_defaults.maximized),
- shown_on_top: shown_on_top
- .unwrap_or(fullscreen_defaults.shown_on_top),
- }),
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- },
- InvokeCommand::SetMinimized => {
- match subject_container.as_window_container() {
- Ok(window) => {
- update_window_state(
- window.clone(),
- WindowState::Minimized,
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::SetTiling => {
- match subject_container.as_window_container() {
- Ok(window) => {
- update_window_state(
- window,
- WindowState::Tiling,
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::SetTitleBarVisibility { visibility } => {
- match subject_container.as_window_container() {
- Ok(window) => {
- _ = window.native().set_title_bar_visibility(
- *visibility == TitleBarVisibility::Shown,
- );
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::SetOpacity { opacity } => {
- match subject_container.as_window_container() {
- Ok(window) => {
- _ = window.native().set_opacity(opacity.clone());
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::ShellExec {
- hide_window,
- command,
- } => shell_exec(&command.join(" "), *hide_window),
- InvokeCommand::Size(args) => {
- match subject_container.as_window_container() {
- Ok(window) => set_window_size(
- window,
- args.width.clone(),
- args.height.clone(),
- state,
- ),
- _ => Ok(()),
- }
- }
- InvokeCommand::ToggleFloating {
- centered,
- shown_on_top,
- } => match subject_container.as_window_container() {
- Ok(window) => {
- let floating_defaults =
- &config.value.window_behavior.state_defaults.floating;
-
- let centered = centered.unwrap_or(floating_defaults.centered);
- let target_state = WindowState::Floating(FloatingStateConfig {
- centered,
- shown_on_top: shown_on_top
- .unwrap_or(floating_defaults.shown_on_top),
- });
-
- let window = update_window_state(
- window.clone(),
- window.toggled_state(target_state, config),
- state,
- config,
- )?;
-
- if !window.has_custom_floating_placement() && centered {
- set_window_position(
- window,
- WindowPositionTarget::Centered,
- state,
- )?;
- }
-
- Ok(())
- }
- _ => Ok(()),
- },
- InvokeCommand::ToggleFullscreen {
- maximized,
- shown_on_top,
- } => match subject_container.as_window_container() {
- Ok(window) => {
- let fullscreen_defaults =
- &config.value.window_behavior.state_defaults.fullscreen;
-
- let target_state =
- WindowState::Fullscreen(FullscreenStateConfig {
- maximized: maximized
- .unwrap_or(fullscreen_defaults.maximized),
- shown_on_top: shown_on_top
- .unwrap_or(fullscreen_defaults.shown_on_top),
- });
-
- update_window_state(
- window.clone(),
- window.toggled_state(target_state, config),
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- },
- InvokeCommand::ToggleMinimized => {
- match subject_container.as_window_container() {
- Ok(window) => {
- update_window_state(
- window.clone(),
- window.toggled_state(WindowState::Minimized, config),
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::ToggleTiling => {
- match subject_container.as_window_container() {
- Ok(window) => {
- update_window_state(
- window.clone(),
- window.toggled_state(WindowState::Tiling, config),
- state,
- config,
- )?;
-
- Ok(())
- }
- _ => Ok(()),
- }
- }
- InvokeCommand::ToggleTilingDirection => {
- toggle_tiling_direction(subject_container, state, config)
- }
- InvokeCommand::SetTilingDirection { tiling_direction } => {
- set_tiling_direction(
- subject_container,
- state,
- config,
- tiling_direction.clone(),
- )
- }
- InvokeCommand::WmCycleFocus {
- omit_fullscreen,
- omit_minimized,
- } => cycle_focus(*omit_fullscreen, *omit_minimized, state, config),
- InvokeCommand::WmDisableBindingMode { name } => {
- disable_binding_mode(name, state);
- Ok(())
- }
- InvokeCommand::WmEnableBindingMode { name } => {
- enable_binding_mode(name, state, config)
- }
- InvokeCommand::WmExit => {
- state.emit_exit();
- Ok(())
- }
- InvokeCommand::WmRedraw => {
- let root_container = state.root_container.clone();
- state
- .pending_sync
- .containers_to_redraw
- .push(root_container.into());
-
- Ok(())
- }
- InvokeCommand::WmReloadConfig => reload_config(state, config),
- InvokeCommand::WmTogglePause => toggle_pause(state),
- }
- }
-
- pub fn run_multiple(
- commands: Vec<InvokeCommand>,
- subject_container: Container,
- state: &mut WmState,
- config: &mut UserConfig,
- ) -> anyhow::Result<Uuid> {
- let mut current_subject_container = subject_container;
-
- for command in commands {
- command.run(current_subject_container.clone(), state, config)?;
-
- // Update the subject container in case the container type changes.
- // For example, when going from a tiling to a floating window.
- current_subject_container =
- match current_subject_container.is_detached() {
- false => current_subject_container,
- true => {
- match state.container_by_id(current_subject_container.id()) {
- Some(container) => container,
- None => break,
- }
- }
- }
- }
-
- Ok(current_subject_container.id())
- }
-}
-
-impl<'de> Deserialize<'de> for InvokeCommand {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: Deserializer<'de>,
- {
- // Clap expects an array of string slices where the first argument is
- // the binary name/path. When deserializing commands from the user
- // config, we therefore have to prepend an additional empty argument.
- let unparsed = String::deserialize(deserializer)?;
- let unparsed_split = iter::once("").chain(unparsed.split_whitespace());
-
- InvokeCommand::try_parse_from(unparsed_split).map_err(|err| {
- // Format the error message and remove the "error: " prefix.
- let err_msg = err.apply::<KindFormatter>().to_string();
- serde::de::Error::custom(err_msg.trim_start_matches("error: "))
- })
- }
-}
-
-#[derive(Clone, Debug, PartialEq, Serialize, ValueEnum)]
-#[clap(rename_all = "snake_case")]
-#[serde(rename_all = "snake_case")]
-pub enum TitleBarVisibility {
- Shown,
- Hidden,
-}
-
-#[derive(Args, Clone, Debug, PartialEq, Serialize)]
-#[group(required = true, multiple = true)]
-pub struct InvokeAdjustBordersCommand {
- #[clap(long, allow_hyphen_values = true)]
- top: Option<LengthValue>,
-
- #[clap(long, allow_hyphen_values = true)]
- right: Option<LengthValue>,
-
- #[clap(long, allow_hyphen_values = true)]
- bottom: Option<LengthValue>,
-
- #[clap(long, allow_hyphen_values = true)]
- left: Option<LengthValue>,
-}
-
-#[derive(Args, Clone, Debug, PartialEq, Serialize)]
-#[group(required = true, multiple = false)]
-pub struct InvokeFocusCommand {
- #[clap(long)]
- direction: Option<Direction>,
-
- #[clap(long)]
- workspace: Option<String>,
-
- #[clap(long)]
- monitor: Option<usize>,
-
- #[clap(long)]
- next_active_workspace: bool,
-
- #[clap(long)]
- prev_active_workspace: bool,
-
- #[clap(long)]
- next_workspace: bool,
-
- #[clap(long)]
- prev_workspace: bool,
-
- #[clap(long)]
- recent_workspace: bool,
-}
-
-#[derive(Args, Clone, Debug, PartialEq, Serialize)]
-#[group(required = true, multiple = false)]
-pub struct InvokeMoveCommand {
- /// Direction to move the window.
- #[clap(long)]
- direction: Option<Direction>,
-
- /// Name of workspace to move the window.
- #[clap(long)]
- workspace: Option<String>,
-
- #[clap(long)]
- next_active_workspace: bool,
-
- #[clap(long)]
- prev_active_workspace: bool,
-
- #[clap(long)]
- next_workspace: bool,
-
- #[clap(long)]
- prev_workspace: bool,
-
- #[clap(long)]
- recent_workspace: bool,
-}
-
-#[derive(Args, Clone, Debug, PartialEq, Serialize)]
-#[group(required = true, multiple = true)]
-pub struct InvokeResizeCommand {
- #[clap(long, allow_hyphen_values = true)]
- width: Option<LengthValue>,
-
- #[clap(long, allow_hyphen_values = true)]
- height: Option<LengthValue>,
-}
-
-#[derive(Args, Clone, Debug, PartialEq, Serialize)]
-#[group(required = true, multiple = true)]
-pub struct InvokePositionCommand {
- #[clap(long, action)]
- centered: bool,
-
- #[clap(long, allow_hyphen_values = true)]
- x_pos: Option<i32>,
-
- #[clap(long, allow_hyphen_values = true)]
- y_pos: Option<i32>,
-}
diff --git a/packages/wm/src/cleanup.rs b/packages/wm/src/cleanup.rs
deleted file mode 100644
index d9e056f5..00000000
--- a/packages/wm/src/cleanup.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use tracing::{info, warn};
-
-use crate::common::platform::NativeWindow;
-
-pub fn run_cleanup(managed_windows: Vec<NativeWindow>) {
- info!("Running WM state cleanup.",);
-
- for window in managed_windows {
- if let Err(err) = window.show() {
- warn!("Failed to show window: {:?}", err);
- }
-
- _ = window.set_taskbar_visibility(true);
- _ = window.set_border_color(None);
- }
-}
diff --git a/packages/wm/src/containers/commands/attach_container.rs b/packages/wm/src/commands/container/attach_container.rs
similarity index 97%
rename from packages/wm/src/containers/commands/attach_container.rs
rename to packages/wm/src/commands/container/attach_container.rs
index c7eb1969..3358b2f4 100644
--- a/packages/wm/src/containers/commands/attach_container.rs
+++ b/packages/wm/src/commands/container/attach_container.rs
@@ -1,9 +1,9 @@
use anyhow::bail;
use super::resize_tiling_container;
-use crate::containers::{
+use crate::{
+ models::Container,
traits::{CommonGetters, TilingSizeGetters},
- Container,
};
/// Inserts a child container at the specified index.
diff --git a/packages/wm/src/containers/commands/detach_container.rs b/packages/wm/src/commands/container/detach_container.rs
similarity index 97%
rename from packages/wm/src/containers/commands/detach_container.rs
rename to packages/wm/src/commands/container/detach_container.rs
index a69fb2af..eaf13d58 100644
--- a/packages/wm/src/containers/commands/detach_container.rs
+++ b/packages/wm/src/commands/container/detach_container.rs
@@ -1,9 +1,9 @@
use anyhow::Context;
use super::flatten_split_container;
-use crate::containers::{
+use crate::{
+ models::Container,
traits::{CommonGetters, TilingSizeGetters, MIN_TILING_SIZE},
- Container,
};
/// Removes a container from the tree.
diff --git a/packages/wm/src/containers/commands/flatten_child_split_containers.rs b/packages/wm/src/commands/container/flatten_child_split_containers.rs
similarity index 97%
rename from packages/wm/src/containers/commands/flatten_child_split_containers.rs
rename to packages/wm/src/commands/container/flatten_child_split_containers.rs
index 3c727f76..0ade487a 100644
--- a/packages/wm/src/containers/commands/flatten_child_split_containers.rs
+++ b/packages/wm/src/commands/container/flatten_child_split_containers.rs
@@ -1,7 +1,7 @@
use super::flatten_split_container;
-use crate::containers::{
+use crate::{
+ models::Container,
traits::{CommonGetters, TilingDirectionGetters},
- Container,
};
/// Flattens any redundant split containers at the top-level of the given
diff --git a/packages/wm/src/containers/commands/flatten_split_container.rs b/packages/wm/src/commands/container/flatten_split_container.rs
similarity index 97%
rename from packages/wm/src/containers/commands/flatten_split_container.rs
rename to packages/wm/src/commands/container/flatten_split_container.rs
index 39ce6d2d..82c341a2 100644
--- a/packages/wm/src/containers/commands/flatten_split_container.rs
+++ b/packages/wm/src/commands/container/flatten_split_container.rs
@@ -2,9 +2,9 @@ use std::collections::VecDeque;
use anyhow::Context;
-use crate::containers::{
+use crate::{
+ models::SplitContainer,
traits::{CommonGetters, TilingSizeGetters},
- SplitContainer,
};
/// Removes a split container from the tree and moves its children
diff --git a/packages/wm/src/containers/commands/focus_in_direction.rs b/packages/wm/src/commands/container/focus_in_direction.rs
similarity index 96%
rename from packages/wm/src/containers/commands/focus_in_direction.rs
rename to packages/wm/src/commands/container/focus_in_direction.rs
index 5af811df..006e0bf8 100644
--- a/packages/wm/src/containers/commands/focus_in_direction.rs
+++ b/packages/wm/src/commands/container/focus_in_direction.rs
@@ -1,13 +1,10 @@
use anyhow::Context;
+use wm_common::{Direction, TilingDirection, WindowState};
use super::set_focused_descendant;
use crate::{
- common::{Direction, TilingDirection},
- containers::{
- traits::{CommonGetters, TilingDirectionGetters},
- Container, TilingContainer,
- },
- windows::{traits::WindowGetters, WindowState},
+ models::{Container, TilingContainer},
+ traits::{CommonGetters, TilingDirectionGetters, WindowGetters},
wm_state::WmState,
};
diff --git a/packages/wm/src/containers/commands/mod.rs b/packages/wm/src/commands/container/mod.rs
similarity index 100%
rename from packages/wm/src/containers/commands/mod.rs
rename to packages/wm/src/commands/container/mod.rs
diff --git a/packages/wm/src/containers/commands/move_container_within_tree.rs b/packages/wm/src/commands/container/move_container_within_tree.rs
similarity index 98%
rename from packages/wm/src/containers/commands/move_container_within_tree.rs
rename to packages/wm/src/commands/container/move_container_within_tree.rs
index 128378b9..005c8f9c 100644
--- a/packages/wm/src/containers/commands/move_container_within_tree.rs
+++ b/packages/wm/src/commands/container/move_container_within_tree.rs
@@ -1,15 +1,11 @@
use anyhow::Context;
+use wm_common::{VecDequeExt, WmEvent};
use super::{
attach_container, detach_container, flatten_child_split_containers,
set_focused_descendant,
};
-use crate::{
- common::VecDequeExt,
- containers::{traits::CommonGetters, Container},
- wm_event::WmEvent,
- wm_state::WmState,
-};
+use crate::{models::Container, traits::CommonGetters, wm_state::WmState};
/// Move a container to a new location in the tree. This detaches the
/// container from its current parent and attaches it to the new parent at
diff --git a/packages/wm/src/containers/commands/replace_container.rs b/packages/wm/src/commands/container/replace_container.rs
similarity index 94%
rename from packages/wm/src/containers/commands/replace_container.rs
rename to packages/wm/src/commands/container/replace_container.rs
index 0b420a01..6e6dc24e 100644
--- a/packages/wm/src/containers/commands/replace_container.rs
+++ b/packages/wm/src/commands/container/replace_container.rs
@@ -1,12 +1,10 @@
use anyhow::{bail, Context};
+use wm_common::VecDequeExt;
use super::{attach_container, detach_container, resize_tiling_container};
use crate::{
- common::VecDequeExt,
- containers::{
- traits::{CommonGetters, TilingSizeGetters},
- Container,
- },
+ models::Container,
+ traits::{CommonGetters, TilingSizeGetters},
};
/// Replaces a container at the specified index.
diff --git a/packages/wm/src/containers/commands/resize_tiling_container.rs b/packages/wm/src/commands/container/resize_tiling_container.rs
similarity index 97%
rename from packages/wm/src/containers/commands/resize_tiling_container.rs
rename to packages/wm/src/commands/container/resize_tiling_container.rs
index c81010b3..5b839797 100644
--- a/packages/wm/src/containers/commands/resize_tiling_container.rs
+++ b/packages/wm/src/commands/container/resize_tiling_container.rs
@@ -1,6 +1,6 @@
-use crate::containers::{
+use crate::{
+ models::TilingContainer,
traits::{CommonGetters, TilingSizeGetters, MIN_TILING_SIZE},
- TilingContainer,
};
pub fn resize_tiling_container(
diff --git a/packages/wm/src/containers/commands/set_focused_descendant.rs b/packages/wm/src/commands/container/set_focused_descendant.rs
similarity index 88%
rename from packages/wm/src/containers/commands/set_focused_descendant.rs
rename to packages/wm/src/commands/container/set_focused_descendant.rs
index e277922d..df96e90d 100644
--- a/packages/wm/src/containers/commands/set_focused_descendant.rs
+++ b/packages/wm/src/commands/container/set_focused_descendant.rs
@@ -1,7 +1,6 @@
-use crate::{
- common::VecDequeExt,
- containers::{traits::CommonGetters, Container},
-};
+use wm_common::VecDequeExt;
+
+use crate::{models::Container, traits::CommonGetters};
/// Set a given container as the focused container up to and including the
/// end ancestor.
diff --git a/packages/wm/src/containers/commands/toggle_tiling_direction.rs b/packages/wm/src/commands/container/toggle_tiling_direction.rs
similarity index 92%
rename from packages/wm/src/containers/commands/toggle_tiling_direction.rs
rename to packages/wm/src/commands/container/toggle_tiling_direction.rs
index 62c74f9d..a0fbb7fa 100644
--- a/packages/wm/src/containers/commands/toggle_tiling_direction.rs
+++ b/packages/wm/src/commands/container/toggle_tiling_direction.rs
@@ -1,15 +1,11 @@
use anyhow::Context;
+use wm_common::{TilingDirection, WmEvent};
use super::{flatten_split_container, wrap_in_split_container};
use crate::{
- common::TilingDirection,
- containers::{
- traits::{CommonGetters, TilingDirectionGetters},
- Container, DirectionContainer, SplitContainer,
- },
+ models::{Container, DirectionContainer, SplitContainer, TilingWindow},
+ traits::{CommonGetters, TilingDirectionGetters},
user_config::UserConfig,
- windows::TilingWindow,
- wm_event::WmEvent,
wm_state::WmState,
};
diff --git a/packages/wm/src/containers/commands/wrap_in_split_container.rs b/packages/wm/src/commands/container/wrap_in_split_container.rs
similarity index 96%
rename from packages/wm/src/containers/commands/wrap_in_split_container.rs
rename to packages/wm/src/commands/container/wrap_in_split_container.rs
index b2056036..33c0f1da 100644
--- a/packages/wm/src/containers/commands/wrap_in_split_container.rs
+++ b/packages/wm/src/commands/container/wrap_in_split_container.rs
@@ -2,9 +2,9 @@ use std::collections::VecDeque;
use anyhow::Context;
-use crate::containers::{
+use crate::{
+ models::{Container, SplitContainer, TilingContainer},
traits::{CommonGetters, TilingSizeGetters},
- Container, SplitContainer, TilingContainer,
};
pub fn wrap_in_split_container(
diff --git a/packages/wm/src/common/commands/cycle_focus.rs b/packages/wm/src/commands/general/cycle_focus.rs
similarity index 95%
rename from packages/wm/src/common/commands/cycle_focus.rs
rename to packages/wm/src/commands/general/cycle_focus.rs
index 15165c11..5f10980a 100644
--- a/packages/wm/src/common/commands/cycle_focus.rs
+++ b/packages/wm/src/commands/general/cycle_focus.rs
@@ -1,9 +1,10 @@
use anyhow::Context;
+use wm_common::WindowState;
use crate::{
- containers::{commands::set_focused_descendant, traits::CommonGetters},
+ commands::container::set_focused_descendant,
+ traits::{CommonGetters, WindowGetters},
user_config::UserConfig,
- windows::{traits::WindowGetters, WindowState},
wm_state::WmState,
};
diff --git a/packages/wm/src/common/commands/disable_binding_mode.rs b/packages/wm/src/commands/general/disable_binding_mode.rs
similarity index 85%
rename from packages/wm/src/common/commands/disable_binding_mode.rs
rename to packages/wm/src/commands/general/disable_binding_mode.rs
index d5464551..aacccd72 100644
--- a/packages/wm/src/common/commands/disable_binding_mode.rs
+++ b/packages/wm/src/commands/general/disable_binding_mode.rs
@@ -1,4 +1,6 @@
-use crate::{wm_event::WmEvent, wm_state::WmState};
+use wm_common::WmEvent;
+
+use crate::wm_state::WmState;
pub fn disable_binding_mode(name: &str, state: &mut WmState) {
state.binding_modes = state
diff --git a/packages/wm/src/common/commands/enable_binding_mode.rs b/packages/wm/src/commands/general/enable_binding_mode.rs
similarity index 86%
rename from packages/wm/src/common/commands/enable_binding_mode.rs
rename to packages/wm/src/commands/general/enable_binding_mode.rs
index 80b7b158..0d8d5b37 100644
--- a/packages/wm/src/common/commands/enable_binding_mode.rs
+++ b/packages/wm/src/commands/general/enable_binding_mode.rs
@@ -1,8 +1,7 @@
use anyhow::Context;
+use wm_common::WmEvent;
-use crate::{
- user_config::UserConfig, wm_event::WmEvent, wm_state::WmState,
-};
+use crate::{user_config::UserConfig, wm_state::WmState};
pub fn enable_binding_mode(
name: &str,
diff --git a/packages/wm/src/common/commands/mod.rs b/packages/wm/src/commands/general/mod.rs
similarity index 100%
rename from packages/wm/src/common/commands/mod.rs
rename to packages/wm/src/commands/general/mod.rs
diff --git a/packages/wm/src/common/commands/platform_sync.rs b/packages/wm/src/commands/general/platform_sync.rs
similarity index 96%
rename from packages/wm/src/common/commands/platform_sync.rs
rename to packages/wm/src/commands/general/platform_sync.rs
index 6d9f4225..0da83fd6 100644
--- a/packages/wm/src/common/commands/platform_sync.rs
+++ b/packages/wm/src/commands/general/platform_sync.rs
@@ -3,19 +3,16 @@ use std::time::Duration;
use anyhow::Context;
use tokio::task;
use tracing::warn;
+use wm_common::{
+ CornerStyle, CursorJumpTrigger, DisplayState, HideMethod, OpacityValue,
+ WindowEffectConfig, WmEvent,
+};
+use wm_platform::Platform;
use crate::{
- common::{platform::Platform, DisplayState, OpacityValue},
- containers::{
- traits::{CommonGetters, PositionGetters},
- Container, WindowContainer,
- },
- user_config::{
- CornerStyle, CursorJumpTrigger, HideMethod, UserConfig,
- WindowEffectConfig,
- },
- windows::traits::WindowGetters,
- wm_event::WmEvent,
+ models::{Container, WindowContainer},
+ traits::{CommonGetters, PositionGetters, WindowGetters},
+ user_config::UserConfig,
wm_state::WmState,
};
diff --git a/packages/wm/src/common/commands/reload_config.rs b/packages/wm/src/commands/general/reload_config.rs
similarity index 93%
rename from packages/wm/src/common/commands/reload_config.rs
rename to packages/wm/src/commands/general/reload_config.rs
index c44b6781..18435ad7 100644
--- a/packages/wm/src/common/commands/reload_config.rs
+++ b/packages/wm/src/commands/general/reload_config.rs
@@ -1,14 +1,13 @@
use anyhow::Context;
use tracing::{info, warn};
+use wm_common::{HideMethod, ParsedConfig, WindowRuleEvent, WmEvent};
use crate::{
- app_command::InvokeCommand,
- containers::traits::{CommonGetters, TilingSizeGetters},
- user_config::{HideMethod, ParsedConfig, UserConfig, WindowRuleEvent},
- windows::{commands::run_window_rules, traits::WindowGetters},
- wm_event::WmEvent,
+ commands::{window::run_window_rules, workspace::sort_workspaces},
+ traits::{CommonGetters, TilingSizeGetters, WindowGetters},
+ user_config::UserConfig,
+ wm::WindowManager,
wm_state::WmState,
- workspaces::commands::sort_workspaces,
};
pub fn reload_config(
@@ -77,8 +76,8 @@ pub fn reload_config(
});
// Run config reload commands.
- InvokeCommand::run_multiple(
- config.value.general.config_reload_commands.clone(),
+ WindowManager::run_commands(
+ &config.value.general.config_reload_commands.clone(),
state.focused_container().context("No focused container.")?,
state,
config,
diff --git a/packages/wm/src/common/commands/shell_exec.rs b/packages/wm/src/commands/general/shell_exec.rs
similarity index 94%
rename from packages/wm/src/common/commands/shell_exec.rs
rename to packages/wm/src/commands/general/shell_exec.rs
index 3d625080..1d22428e 100644
--- a/packages/wm/src/common/commands/shell_exec.rs
+++ b/packages/wm/src/commands/general/shell_exec.rs
@@ -1,6 +1,6 @@
use tracing::{error, info};
-use crate::common::platform::Platform;
+use wm_platform::Platform;
pub fn shell_exec(command: &str, hide_window: bool) -> anyhow::Result<()> {
let res =
diff --git a/packages/wm/src/common/commands/toggle_pause.rs b/packages/wm/src/commands/general/toggle_pause.rs
similarity index 90%
rename from packages/wm/src/common/commands/toggle_pause.rs
rename to packages/wm/src/commands/general/toggle_pause.rs
index 43bdf408..7c51b5c9 100644
--- a/packages/wm/src/common/commands/toggle_pause.rs
+++ b/packages/wm/src/commands/general/toggle_pause.rs
@@ -1,4 +1,6 @@
-use crate::{wm_event::WmEvent, wm_state::WmState};
+use wm_common::WmEvent;
+
+use crate::wm_state::WmState;
/// Pauses or unpauses the WM.
pub fn toggle_pause(state: &mut WmState) -> anyhow::Result<()> {
diff --git a/packages/wm/src/commands/mod.rs b/packages/wm/src/commands/mod.rs
new file mode 100644
index 00000000..752ae679
--- /dev/null
+++ b/packages/wm/src/commands/mod.rs
@@ -0,0 +1,5 @@
+pub mod container;
+pub mod general;
+pub mod monitor;
+pub mod window;
+pub mod workspace;
diff --git a/packages/wm/src/monitors/commands/add_monitor.rs b/packages/wm/src/commands/monitor/add_monitor.rs
similarity index 83%
rename from packages/wm/src/monitors/commands/add_monitor.rs
rename to packages/wm/src/commands/monitor/add_monitor.rs
index a2a36882..371a136c 100644
--- a/packages/wm/src/monitors/commands/add_monitor.rs
+++ b/packages/wm/src/commands/monitor/add_monitor.rs
@@ -1,10 +1,13 @@
use anyhow::Context;
use tracing::info;
+use wm_common::WmEvent;
+use wm_platform::NativeMonitor;
use crate::{
- common::platform::NativeMonitor, containers::commands::attach_container,
- monitors::Monitor, user_config::UserConfig, wm_event::WmEvent,
- wm_state::WmState, workspaces::commands::activate_workspace,
+ commands::{container::attach_container, workspace::activate_workspace},
+ models::Monitor,
+ user_config::UserConfig,
+ wm_state::WmState,
};
pub fn add_monitor(
diff --git a/packages/wm/src/monitors/commands/focus_monitor.rs b/packages/wm/src/commands/monitor/focus_monitor.rs
similarity index 84%
rename from packages/wm/src/monitors/commands/focus_monitor.rs
rename to packages/wm/src/commands/monitor/focus_monitor.rs
index 53838603..4b223dc8 100644
--- a/packages/wm/src/monitors/commands/focus_monitor.rs
+++ b/packages/wm/src/commands/monitor/focus_monitor.rs
@@ -1,9 +1,8 @@
use anyhow::Context;
use crate::{
- user_config::UserConfig,
- wm_state::WmState,
- workspaces::{commands::focus_workspace, WorkspaceTarget},
+ commands::workspace::focus_workspace, models::WorkspaceTarget,
+ user_config::UserConfig, wm_state::WmState,
};
/// Focuses a monitor by a given monitor index.
diff --git a/packages/wm/src/monitors/commands/mod.rs b/packages/wm/src/commands/monitor/mod.rs
similarity index 100%
rename from packages/wm/src/monitors/commands/mod.rs
rename to packages/wm/src/commands/monitor/mod.rs
diff --git a/packages/wm/src/monitors/commands/remove_monitor.rs b/packages/wm/src/commands/monitor/remove_monitor.rs
similarity index 88%
rename from packages/wm/src/monitors/commands/remove_monitor.rs
rename to packages/wm/src/commands/monitor/remove_monitor.rs
index 40e07da2..22da540a 100644
--- a/packages/wm/src/monitors/commands/remove_monitor.rs
+++ b/packages/wm/src/commands/monitor/remove_monitor.rs
@@ -1,16 +1,16 @@
use anyhow::Context;
use tracing::info;
+use wm_common::WmEvent;
use crate::{
- containers::{
- commands::{detach_container, move_container_within_tree},
- traits::CommonGetters,
+ commands::{
+ container::{detach_container, move_container_within_tree},
+ workspace::sort_workspaces,
},
- monitors::Monitor,
+ models::Monitor,
+ traits::CommonGetters,
user_config::UserConfig,
- wm_event::WmEvent,
wm_state::WmState,
- workspaces::commands::sort_workspaces,
};
pub fn remove_monitor(
diff --git a/packages/wm/src/monitors/commands/sort_monitors.rs b/packages/wm/src/commands/monitor/sort_monitors.rs
similarity index 95%
rename from packages/wm/src/monitors/commands/sort_monitors.rs
rename to packages/wm/src/commands/monitor/sort_monitors.rs
index d174a317..bcc1b364 100644
--- a/packages/wm/src/monitors/commands/sort_monitors.rs
+++ b/packages/wm/src/commands/monitor/sort_monitors.rs
@@ -1,6 +1,6 @@
-use crate::containers::{
+use crate::{
+ models::RootContainer,
traits::{CommonGetters, PositionGetters},
- RootContainer,
};
/// Sorts the root container's monitors from left-to-right and
diff --git a/packages/wm/src/monitors/commands/update_monitor.rs b/packages/wm/src/commands/monitor/update_monitor.rs
similarity index 84%
rename from packages/wm/src/monitors/commands/update_monitor.rs
rename to packages/wm/src/commands/monitor/update_monitor.rs
index 6359fc23..7a5dc69e 100644
--- a/packages/wm/src/monitors/commands/update_monitor.rs
+++ b/packages/wm/src/commands/monitor/update_monitor.rs
@@ -1,9 +1,8 @@
use tracing::info;
+use wm_common::WmEvent;
+use wm_platform::NativeMonitor;
-use crate::{
- common::platform::NativeMonitor, monitors::Monitor, wm_event::WmEvent,
- wm_state::WmState,
-};
+use crate::{models::Monitor, wm_state::WmState};
pub fn update_monitor(
monitor: Monitor,
diff --git a/packages/wm/src/windows/commands/ignore_window.rs b/packages/wm/src/commands/window/ignore_window.rs
similarity index 86%
rename from packages/wm/src/windows/commands/ignore_window.rs
rename to packages/wm/src/commands/window/ignore_window.rs
index ea28d95c..079ddd97 100644
--- a/packages/wm/src/windows/commands/ignore_window.rs
+++ b/packages/wm/src/commands/window/ignore_window.rs
@@ -1,12 +1,12 @@
use anyhow::Context;
+use wm_common::WindowState;
use crate::{
- containers::{
- commands::{detach_container, flatten_child_split_containers},
- traits::CommonGetters,
- WindowContainer,
+ commands::container::{
+ detach_container, flatten_child_split_containers,
},
- windows::{traits::WindowGetters, WindowState},
+ models::WindowContainer,
+ traits::{CommonGetters, WindowGetters},
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/manage_window.rs b/packages/wm/src/commands/window/manage_window.rs
similarity index 92%
rename from packages/wm/src/windows/commands/manage_window.rs
rename to packages/wm/src/commands/window/manage_window.rs
index 1194055c..55a1ea78 100644
--- a/packages/wm/src/windows/commands/manage_window.rs
+++ b/packages/wm/src/commands/window/manage_window.rs
@@ -1,21 +1,20 @@
use anyhow::Context;
use tracing::info;
+use wm_common::{
+ try_warn, LengthValue, RectDelta, WindowRuleEvent, WindowState, WmEvent,
+};
+use wm_platform::NativeWindow;
use crate::{
- common::{platform::NativeWindow, LengthValue, RectDelta},
- containers::{
- commands::{attach_container, set_focused_descendant},
- traits::{CommonGetters, PositionGetters},
- Container, WindowContainer,
+ commands::{
+ container::{attach_container, set_focused_descendant},
+ window::run_window_rules,
},
- monitors::Monitor,
- try_warn,
- user_config::{UserConfig, WindowRuleEvent},
- windows::{
- commands::run_window_rules, traits::WindowGetters, NonTilingWindow,
- TilingWindow, WindowState,
+ models::{
+ Container, Monitor, NonTilingWindow, TilingWindow, WindowContainer,
},
- wm_event::WmEvent,
+ traits::{CommonGetters, PositionGetters, WindowGetters},
+ user_config::UserConfig,
wm_state::WmState,
};
@@ -208,7 +207,7 @@ fn window_state_to_create(
));
}
- Ok(WindowState::default_from_config(config))
+ Ok(WindowState::default_from_config(&config.value))
}
fn insertion_target(
diff --git a/packages/wm/src/windows/commands/mod.rs b/packages/wm/src/commands/window/mod.rs
similarity index 100%
rename from packages/wm/src/windows/commands/mod.rs
rename to packages/wm/src/commands/window/mod.rs
diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/commands/window/move_window_in_direction.rs
similarity index 96%
rename from packages/wm/src/windows/commands/move_window_in_direction.rs
rename to packages/wm/src/commands/window/move_window_in_direction.rs
index 5e57a4c5..0216e687 100644
--- a/packages/wm/src/windows/commands/move_window_in_direction.rs
+++ b/packages/wm/src/commands/window/move_window_in_direction.rs
@@ -1,21 +1,20 @@
use anyhow::Context;
+use wm_common::{Direction, Rect, TilingDirection, WindowState};
use crate::{
- common::{Direction, Rect, TilingDirection},
- containers::{
- commands::{
- flatten_child_split_containers, flatten_split_container,
- move_container_within_tree, resize_tiling_container,
- wrap_in_split_container,
- },
- traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
- DirectionContainer, SplitContainer, TilingContainer, WindowContainer,
+ commands::container::{
+ flatten_child_split_containers, flatten_split_container,
+ move_container_within_tree, resize_tiling_container,
+ wrap_in_split_container,
},
- monitors::Monitor,
- user_config::UserConfig,
- windows::{
- traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState,
+ models::{
+ DirectionContainer, Monitor, NonTilingWindow, SplitContainer,
+ TilingContainer, TilingWindow, WindowContainer,
+ },
+ traits::{
+ CommonGetters, PositionGetters, TilingDirectionGetters, WindowGetters,
},
+ user_config::UserConfig,
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/move_window_to_workspace.rs b/packages/wm/src/commands/window/move_window_to_workspace.rs
similarity index 94%
rename from packages/wm/src/windows/commands/move_window_to_workspace.rs
rename to packages/wm/src/commands/window/move_window_to_workspace.rs
index ae9788dc..37a002a1 100644
--- a/packages/wm/src/windows/commands/move_window_to_workspace.rs
+++ b/packages/wm/src/commands/window/move_window_to_workspace.rs
@@ -1,16 +1,16 @@
use anyhow::Context;
use tracing::info;
+use wm_common::WindowState;
use crate::{
- containers::{
- commands::{move_container_within_tree, set_focused_descendant},
- traits::{CommonGetters, PositionGetters},
- WindowContainer,
+ commands::{
+ container::{move_container_within_tree, set_focused_descendant},
+ workspace::activate_workspace,
},
+ models::{WindowContainer, WorkspaceTarget},
+ traits::{CommonGetters, PositionGetters, WindowGetters},
user_config::UserConfig,
- windows::{traits::WindowGetters, WindowState},
wm_state::WmState,
- workspaces::{commands::activate_workspace, WorkspaceTarget},
};
pub fn move_window_to_workspace(
diff --git a/packages/wm/src/windows/commands/resize_window.rs b/packages/wm/src/commands/window/resize_window.rs
similarity index 94%
rename from packages/wm/src/windows/commands/resize_window.rs
rename to packages/wm/src/commands/window/resize_window.rs
index 9a6ffbf3..af43281d 100644
--- a/packages/wm/src/windows/commands/resize_window.rs
+++ b/packages/wm/src/commands/window/resize_window.rs
@@ -1,10 +1,9 @@
+use wm_common::LengthValue;
+
use super::set_window_size;
use crate::{
- common::LengthValue,
- containers::{
- traits::{CommonGetters, PositionGetters, TilingSizeGetters},
- WindowContainer,
- },
+ models::WindowContainer,
+ traits::{CommonGetters, PositionGetters, TilingSizeGetters},
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/run_window_rules.rs b/packages/wm/src/commands/window/run_window_rules.rs
similarity index 82%
rename from packages/wm/src/windows/commands/run_window_rules.rs
rename to packages/wm/src/commands/window/run_window_rules.rs
index 4e1207c0..7fe665e0 100644
--- a/packages/wm/src/windows/commands/run_window_rules.rs
+++ b/packages/wm/src/commands/window/run_window_rules.rs
@@ -1,9 +1,11 @@
use tracing::info;
+use wm_common::WindowRuleEvent;
use crate::{
- containers::{traits::CommonGetters, WindowContainer},
- user_config::{UserConfig, WindowRuleEvent},
- windows::traits::WindowGetters,
+ models::WindowContainer,
+ traits::{CommonGetters, WindowGetters},
+ user_config::UserConfig,
+ wm::WindowManager,
wm_state::WmState,
};
@@ -24,7 +26,12 @@ pub fn run_window_rules(
info!("Running window rule with commands: {:?}.", rule.commands);
for command in &rule.commands {
- command.run(subject_window.clone().into(), state, config)?;
+ WindowManager::run_command(
+ command,
+ subject_window.clone().into(),
+ state,
+ config,
+ )?;
// Update the subject container in case the container type changes.
// For example, when going from a tiling to a floating window.
diff --git a/packages/wm/src/windows/commands/set_window_position.rs b/packages/wm/src/commands/window/set_window_position.rs
similarity index 86%
rename from packages/wm/src/windows/commands/set_window_position.rs
rename to packages/wm/src/commands/window/set_window_position.rs
index 7e95671a..fac403ba 100644
--- a/packages/wm/src/windows/commands/set_window_position.rs
+++ b/packages/wm/src/commands/window/set_window_position.rs
@@ -1,12 +1,9 @@
use anyhow::Context;
+use wm_common::{Rect, WindowState};
use crate::{
- common::Rect,
- containers::{
- traits::{CommonGetters, PositionGetters},
- WindowContainer,
- },
- windows::{traits::WindowGetters, WindowState},
+ models::WindowContainer,
+ traits::{CommonGetters, PositionGetters, WindowGetters},
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/set_window_size.rs b/packages/wm/src/commands/window/set_window_size.rs
similarity index 94%
rename from packages/wm/src/windows/commands/set_window_size.rs
rename to packages/wm/src/commands/window/set_window_size.rs
index 64893b4a..d2983649 100644
--- a/packages/wm/src/windows/commands/set_window_size.rs
+++ b/packages/wm/src/commands/window/set_window_size.rs
@@ -1,14 +1,11 @@
use anyhow::Context;
+use wm_common::{LengthValue, Rect, WindowState};
use crate::{
- common::{LengthValue, Rect},
- containers::{
- commands::resize_tiling_container,
- traits::{CommonGetters, PositionGetters, TilingSizeGetters},
- WindowContainer,
- },
- windows::{
- traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState,
+ commands::container::resize_tiling_container,
+ models::{NonTilingWindow, TilingWindow, WindowContainer},
+ traits::{
+ CommonGetters, PositionGetters, TilingSizeGetters, WindowGetters,
},
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/unmanage_window.rs b/packages/wm/src/commands/window/unmanage_window.rs
similarity index 86%
rename from packages/wm/src/windows/commands/unmanage_window.rs
rename to packages/wm/src/commands/window/unmanage_window.rs
index 9bf449c3..84c178ad 100644
--- a/packages/wm/src/windows/commands/unmanage_window.rs
+++ b/packages/wm/src/commands/window/unmanage_window.rs
@@ -1,16 +1,13 @@
use anyhow::Context;
+use wm_common::{WindowState, WmEvent};
use crate::{
- containers::{
- commands::{
- detach_container, flatten_child_split_containers,
- set_focused_descendant,
- },
- traits::CommonGetters,
- WindowContainer,
+ commands::container::{
+ detach_container, flatten_child_split_containers,
+ set_focused_descendant,
},
- windows::{traits::WindowGetters, WindowState},
- wm_event::WmEvent,
+ models::WindowContainer,
+ traits::{CommonGetters, WindowGetters},
wm_state::WmState,
};
diff --git a/packages/wm/src/windows/commands/update_window_state.rs b/packages/wm/src/commands/window/update_window_state.rs
similarity index 95%
rename from packages/wm/src/windows/commands/update_window_state.rs
rename to packages/wm/src/commands/window/update_window_state.rs
index 5ae3ee54..d10b7fb1 100644
--- a/packages/wm/src/windows/commands/update_window_state.rs
+++ b/packages/wm/src/commands/window/update_window_state.rs
@@ -1,17 +1,14 @@
use anyhow::Context;
use tracing::info;
+use wm_common::WindowState;
use crate::{
- containers::{
- commands::{
- move_container_within_tree, replace_container,
- resize_tiling_container,
- },
- traits::{CommonGetters, TilingSizeGetters},
- WindowContainer,
+ commands::container::{
+ move_container_within_tree, replace_container, resize_tiling_container,
},
+ models::{InsertionTarget, WindowContainer},
+ traits::{CommonGetters, TilingSizeGetters, WindowGetters},
user_config::UserConfig,
- windows::{traits::WindowGetters, InsertionTarget, WindowState},
wm_state::WmState,
};
diff --git a/packages/wm/src/workspaces/commands/activate_workspace.rs b/packages/wm/src/commands/workspace/activate_workspace.rs
similarity index 92%
rename from packages/wm/src/workspaces/commands/activate_workspace.rs
rename to packages/wm/src/commands/workspace/activate_workspace.rs
index 91e9323b..c11d8821 100644
--- a/packages/wm/src/workspaces/commands/activate_workspace.rs
+++ b/packages/wm/src/commands/workspace/activate_workspace.rs
@@ -1,17 +1,13 @@
use anyhow::Context;
+use wm_common::{TilingDirection, WmEvent, WorkspaceConfig};
use super::sort_workspaces;
use crate::{
- common::TilingDirection,
- containers::{
- commands::attach_container,
- traits::{CommonGetters, PositionGetters},
- },
- monitors::Monitor,
- user_config::{UserConfig, WorkspaceConfig},
- wm_event::WmEvent,
+ commands::container::attach_container,
+ models::{Monitor, Workspace},
+ traits::{CommonGetters, PositionGetters},
+ user_config::UserConfig,
wm_state::WmState,
- workspaces::Workspace,
};
/// Activates a workspace on the target monitor.
diff --git a/packages/wm/src/workspaces/commands/deactivate_workspace.rs b/packages/wm/src/commands/workspace/deactivate_workspace.rs
similarity index 76%
rename from packages/wm/src/workspaces/commands/deactivate_workspace.rs
rename to packages/wm/src/commands/workspace/deactivate_workspace.rs
index 5dde4e9c..afb6f419 100644
--- a/packages/wm/src/workspaces/commands/deactivate_workspace.rs
+++ b/packages/wm/src/commands/workspace/deactivate_workspace.rs
@@ -1,8 +1,8 @@
+use wm_common::WmEvent;
+
use crate::{
- containers::{commands::detach_container, traits::CommonGetters},
- wm_event::WmEvent,
- wm_state::WmState,
- workspaces::Workspace,
+ commands::container::detach_container, models::Workspace,
+ traits::CommonGetters, wm_state::WmState,
};
/// Deactivates a given workspace. This removes the container from its
diff --git a/packages/wm/src/workspaces/commands/focus_workspace.rs b/packages/wm/src/commands/workspace/focus_workspace.rs
similarity index 94%
rename from packages/wm/src/workspaces/commands/focus_workspace.rs
rename to packages/wm/src/commands/workspace/focus_workspace.rs
index 0a54924a..d410c550 100644
--- a/packages/wm/src/workspaces/commands/focus_workspace.rs
+++ b/packages/wm/src/commands/workspace/focus_workspace.rs
@@ -1,14 +1,15 @@
use anyhow::Context;
use tracing::info;
+use super::activate_workspace;
use crate::{
- containers::{commands::set_focused_descendant, traits::CommonGetters},
+ commands::{
+ container::set_focused_descendant, workspace::deactivate_workspace,
+ },
+ models::WorkspaceTarget,
+ traits::CommonGetters,
user_config::UserConfig,
wm_state::WmState,
- workspaces::{
- commands::{activate_workspace, deactivate_workspace},
- WorkspaceTarget,
- },
};
/// Focuses a workspace by a given target.
diff --git a/packages/wm/src/workspaces/commands/mod.rs b/packages/wm/src/commands/workspace/mod.rs
similarity index 100%
rename from packages/wm/src/workspaces/commands/mod.rs
rename to packages/wm/src/commands/workspace/mod.rs
diff --git a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs b/packages/wm/src/commands/workspace/move_workspace_in_direction.rs
similarity index 92%
rename from packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
rename to packages/wm/src/commands/workspace/move_workspace_in_direction.rs
index b03e38ae..5a85483c 100644
--- a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
+++ b/packages/wm/src/commands/workspace/move_workspace_in_direction.rs
@@ -1,17 +1,13 @@
use anyhow::Context;
+use wm_common::{Direction, WmEvent};
use super::{activate_workspace, deactivate_workspace, sort_workspaces};
use crate::{
- common::Direction,
- containers::{
- commands::move_container_within_tree,
- traits::{CommonGetters, PositionGetters},
- },
+ commands::container::move_container_within_tree,
+ models::Workspace,
+ traits::{CommonGetters, PositionGetters, WindowGetters},
user_config::UserConfig,
- windows::traits::WindowGetters,
- wm_event::WmEvent,
wm_state::WmState,
- workspaces::Workspace,
};
pub fn move_workspace_in_direction(
diff --git a/packages/wm/src/workspaces/commands/sort_workspaces.rs b/packages/wm/src/commands/workspace/sort_workspaces.rs
similarity index 85%
rename from packages/wm/src/workspaces/commands/sort_workspaces.rs
rename to packages/wm/src/commands/workspace/sort_workspaces.rs
index 0caebeed..a71e2183 100644
--- a/packages/wm/src/workspaces/commands/sort_workspaces.rs
+++ b/packages/wm/src/commands/workspace/sort_workspaces.rs
@@ -1,8 +1,8 @@
use anyhow::Context;
+use wm_common::VecDequeExt;
use crate::{
- common::VecDequeExt, containers::traits::CommonGetters,
- monitors::Monitor, user_config::UserConfig,
+ models::Monitor, traits::CommonGetters, user_config::UserConfig,
};
/// Sorts a monitor's workspaces by config order.
diff --git a/packages/wm/src/containers/mod.rs b/packages/wm/src/containers/mod.rs
deleted file mode 100644
index b20398c2..00000000
--- a/packages/wm/src/containers/mod.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-pub mod commands;
-mod container;
-mod container_dto;
-mod root_container;
-mod split_container;
-pub mod traits;
-
-pub use container::*;
-pub use container_dto::*;
-pub use root_container::*;
-pub use split_container::*;
diff --git a/packages/wm/src/common/events/handle_display_settings_changed.rs b/packages/wm/src/events/handle_display_settings_changed.rs
similarity index 96%
rename from packages/wm/src/common/events/handle_display_settings_changed.rs
rename to packages/wm/src/events/handle_display_settings_changed.rs
index f9dfbd94..9c1d639c 100644
--- a/packages/wm/src/common/events/handle_display_settings_changed.rs
+++ b/packages/wm/src/events/handle_display_settings_changed.rs
@@ -1,14 +1,13 @@
use anyhow::Context;
use tracing::info;
+use wm_platform::Platform;
use crate::{
- common::platform::Platform,
- containers::traits::{CommonGetters, PositionGetters},
- monitors::commands::{
+ commands::monitor::{
add_monitor, remove_monitor, sort_monitors, update_monitor,
},
+ traits::{CommonGetters, PositionGetters, WindowGetters},
user_config::UserConfig,
- windows::traits::WindowGetters,
wm_state::WmState,
};
diff --git a/packages/wm/src/common/events/handle_mouse_move.rs b/packages/wm/src/events/handle_mouse_move.rs
similarity index 85%
rename from packages/wm/src/common/events/handle_mouse_move.rs
rename to packages/wm/src/events/handle_mouse_move.rs
index 4a41ed61..6bbb1f25 100644
--- a/packages/wm/src/common/events/handle_mouse_move.rs
+++ b/packages/wm/src/events/handle_mouse_move.rs
@@ -1,10 +1,9 @@
use anyhow::Context;
+use wm_platform::{MouseMoveEvent, Platform};
use crate::{
- common::platform::{MouseMoveEvent, Platform},
- containers::{commands::set_focused_descendant, traits::CommonGetters},
- user_config::UserConfig,
- wm_state::WmState,
+ commands::container::set_focused_descendant, traits::CommonGetters,
+ user_config::UserConfig, wm_state::WmState,
};
pub fn handle_mouse_move(
diff --git a/packages/wm/src/common/events/handle_window_destroyed.rs b/packages/wm/src/events/handle_window_destroyed.rs
similarity index 82%
rename from packages/wm/src/common/events/handle_window_destroyed.rs
rename to packages/wm/src/events/handle_window_destroyed.rs
index 7ef3551e..f57e18c6 100644
--- a/packages/wm/src/common/events/handle_window_destroyed.rs
+++ b/packages/wm/src/events/handle_window_destroyed.rs
@@ -1,10 +1,11 @@
use anyhow::Context;
use tracing::info;
+use wm_platform::NativeWindow;
use crate::{
- common::platform::NativeWindow, containers::traits::CommonGetters,
- windows::commands::unmanage_window, wm_state::WmState,
- workspaces::commands::deactivate_workspace,
+ commands::{window::unmanage_window, workspace::deactivate_workspace},
+ traits::CommonGetters,
+ wm_state::WmState,
};
pub fn handle_window_destroyed(
diff --git a/packages/wm/src/common/events/handle_window_focused.rs b/packages/wm/src/events/handle_window_focused.rs
similarity index 88%
rename from packages/wm/src/common/events/handle_window_focused.rs
rename to packages/wm/src/events/handle_window_focused.rs
index 7c37f050..98c79881 100644
--- a/packages/wm/src/common/events/handle_window_focused.rs
+++ b/packages/wm/src/events/handle_window_focused.rs
@@ -1,13 +1,17 @@
use anyhow::Context;
use tracing::info;
+use wm_common::{DisplayState, WindowRuleEvent};
+use wm_platform::NativeWindow;
use crate::{
- common::{platform::NativeWindow, DisplayState},
- containers::{commands::set_focused_descendant, traits::CommonGetters},
- user_config::{UserConfig, WindowRuleEvent},
- windows::{commands::run_window_rules, traits::WindowGetters},
+ commands::{
+ container::set_focused_descendant, window::run_window_rules,
+ workspace::focus_workspace,
+ },
+ models::WorkspaceTarget,
+ traits::{CommonGetters, WindowGetters},
+ user_config::UserConfig,
wm_state::WmState,
- workspaces::{commands::focus_workspace, WorkspaceTarget},
};
pub fn handle_window_focused(
diff --git a/packages/wm/src/common/events/handle_window_hidden.rs b/packages/wm/src/events/handle_window_hidden.rs
similarity index 88%
rename from packages/wm/src/common/events/handle_window_hidden.rs
rename to packages/wm/src/events/handle_window_hidden.rs
index e2a08705..13edd430 100644
--- a/packages/wm/src/common/events/handle_window_hidden.rs
+++ b/packages/wm/src/events/handle_window_hidden.rs
@@ -1,8 +1,9 @@
use tracing::info;
+use wm_common::DisplayState;
+use wm_platform::NativeWindow;
use crate::{
- common::{platform::NativeWindow, DisplayState},
- windows::{commands::unmanage_window, traits::WindowGetters},
+ commands::window::unmanage_window, traits::WindowGetters,
wm_state::WmState,
};
diff --git a/packages/wm/src/common/events/handle_window_location_changed.rs b/packages/wm/src/events/handle_window_location_changed.rs
similarity index 93%
rename from packages/wm/src/common/events/handle_window_location_changed.rs
rename to packages/wm/src/events/handle_window_location_changed.rs
index 84c0b5b5..072079b9 100644
--- a/packages/wm/src/common/events/handle_window_location_changed.rs
+++ b/packages/wm/src/events/handle_window_location_changed.rs
@@ -1,19 +1,19 @@
use anyhow::Context;
use tracing::info;
+use wm_common::{
+ try_warn, ActiveDrag, ActiveDragOperation, FloatingStateConfig,
+ FullscreenStateConfig, Rect, WindowState,
+};
+use wm_platform::NativeWindow;
use crate::{
- common::{platform::NativeWindow, Rect},
- containers::{
- commands::{flatten_split_container, move_container_within_tree},
- traits::{CommonGetters, PositionGetters},
- WindowContainer,
- },
- try_warn,
- user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
- windows::{
- commands::update_window_state, traits::WindowGetters, ActiveDrag,
- ActiveDragOperation, TilingWindow, WindowState,
+ commands::{
+ container::{flatten_split_container, move_container_within_tree},
+ window::update_window_state,
},
+ models::{TilingWindow, WindowContainer},
+ traits::{CommonGetters, PositionGetters, WindowGetters},
+ user_config::UserConfig,
wm_state::WmState,
};
@@ -84,7 +84,7 @@ pub fn handle_window_location_changed(
let target_state = window
.prev_state()
- .unwrap_or(WindowState::default_from_config(config));
+ .unwrap_or(WindowState::default_from_config(&config.value));
update_window_state(
window.clone(),
diff --git a/packages/wm/src/common/events/handle_window_minimize_ended.rs b/packages/wm/src/events/handle_window_minimize_ended.rs
similarity index 73%
rename from packages/wm/src/common/events/handle_window_minimize_ended.rs
rename to packages/wm/src/events/handle_window_minimize_ended.rs
index 1b8fe2f8..382c0133 100644
--- a/packages/wm/src/common/events/handle_window_minimize_ended.rs
+++ b/packages/wm/src/events/handle_window_minimize_ended.rs
@@ -1,13 +1,10 @@
use tracing::info;
+use wm_common::{try_warn, WindowState};
+use wm_platform::NativeWindow;
use crate::{
- common::platform::NativeWindow,
- try_warn,
- user_config::UserConfig,
- windows::{
- commands::update_window_state, traits::WindowGetters, WindowState,
- },
- wm_state::WmState,
+ commands::window::update_window_state, traits::WindowGetters,
+ user_config::UserConfig, wm_state::WmState,
};
pub fn handle_window_minimize_ended(
@@ -27,7 +24,7 @@ pub fn handle_window_minimize_ended(
let target_state = window
.prev_state()
- .unwrap_or(WindowState::default_from_config(config));
+ .unwrap_or(WindowState::default_from_config(&config.value));
update_window_state(window.clone(), target_state, state, config)?;
}
diff --git a/packages/wm/src/common/events/handle_window_minimized.rs b/packages/wm/src/events/handle_window_minimized.rs
similarity index 86%
rename from packages/wm/src/common/events/handle_window_minimized.rs
rename to packages/wm/src/events/handle_window_minimized.rs
index 05f6835a..9707df97 100644
--- a/packages/wm/src/common/events/handle_window_minimized.rs
+++ b/packages/wm/src/events/handle_window_minimized.rs
@@ -1,13 +1,13 @@
use tracing::info;
+use wm_common::{try_warn, WindowState};
+use wm_platform::NativeWindow;
use crate::{
- common::platform::NativeWindow,
- containers::commands::set_focused_descendant,
- try_warn,
- user_config::UserConfig,
- windows::{
- commands::update_window_state, traits::WindowGetters, WindowState,
+ commands::{
+ container::set_focused_descendant, window::update_window_state,
},
+ traits::WindowGetters,
+ user_config::UserConfig,
wm_state::WmState,
};
diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs b/packages/wm/src/events/handle_window_moved_or_resized_end.rs
similarity index 93%
rename from packages/wm/src/common/events/handle_window_moved_or_resized_end.rs
rename to packages/wm/src/events/handle_window_moved_or_resized_end.rs
index cb5f73c6..77d46096 100644
--- a/packages/wm/src/common/events/handle_window_moved_or_resized_end.rs
+++ b/packages/wm/src/events/handle_window_moved_or_resized_end.rs
@@ -1,23 +1,24 @@
use anyhow::Context;
use tracing::info;
+use wm_common::{
+ try_warn, ActiveDragOperation, LengthValue, Point, Rect,
+ TilingDirection, WindowState,
+};
+use wm_platform::{NativeWindow, Platform};
use crate::{
- common::{
- platform::{NativeWindow, Platform},
- LengthValue, Point, Rect, TilingDirection,
+ commands::{
+ container::{move_container_within_tree, wrap_in_split_container},
+ window::{resize_window, update_window_state},
},
- containers::{
- commands::{move_container_within_tree, wrap_in_split_container},
- traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
- DirectionContainer, SplitContainer, TilingContainer, WindowContainer,
+ models::{
+ DirectionContainer, NonTilingWindow, SplitContainer, TilingContainer,
+ WindowContainer,
},
- try_warn,
- user_config::UserConfig,
- windows::{
- commands::{resize_window, update_window_state},
- traits::WindowGetters,
- ActiveDragOperation, NonTilingWindow, WindowState,
+ traits::{
+ CommonGetters, PositionGetters, TilingDirectionGetters, WindowGetters,
},
+ user_config::UserConfig,
wm_state::WmState,
};
diff --git a/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs b/packages/wm/src/events/handle_window_moved_or_resized_start.rs
similarity index 81%
rename from packages/wm/src/common/events/handle_window_moved_or_resized_start.rs
rename to packages/wm/src/events/handle_window_moved_or_resized_start.rs
index 07ae6ccf..914ed839 100644
--- a/packages/wm/src/common/events/handle_window_moved_or_resized_start.rs
+++ b/packages/wm/src/events/handle_window_moved_or_resized_start.rs
@@ -1,8 +1,7 @@
-use crate::{
- common::platform::NativeWindow,
- windows::{traits::WindowGetters, ActiveDrag},
- wm_state::WmState,
-};
+use wm_common::ActiveDrag;
+use wm_platform::NativeWindow;
+
+use crate::{traits::WindowGetters, wm_state::WmState};
/// Handles the event for when a window is started being moved or resized
/// by the user (e.g. via the window's drag handles).
diff --git a/packages/wm/src/common/events/handle_window_shown.rs b/packages/wm/src/events/handle_window_shown.rs
similarity index 83%
rename from packages/wm/src/common/events/handle_window_shown.rs
rename to packages/wm/src/events/handle_window_shown.rs
index a9b795e7..146c5991 100644
--- a/packages/wm/src/common/events/handle_window_shown.rs
+++ b/packages/wm/src/events/handle_window_shown.rs
@@ -1,10 +1,10 @@
use tracing::info;
+use wm_common::DisplayState;
+use wm_platform::NativeWindow;
use crate::{
- common::{platform::NativeWindow, DisplayState},
- user_config::UserConfig,
- windows::{commands::manage_window, traits::WindowGetters},
- wm_state::WmState,
+ commands::window::manage_window, traits::WindowGetters,
+ user_config::UserConfig, wm_state::WmState,
};
pub fn handle_window_shown(
diff --git a/packages/wm/src/common/events/handle_window_title_changed.rs b/packages/wm/src/events/handle_window_title_changed.rs
similarity index 74%
rename from packages/wm/src/common/events/handle_window_title_changed.rs
rename to packages/wm/src/events/handle_window_title_changed.rs
index 8989c703..5ff3e875 100644
--- a/packages/wm/src/common/events/handle_window_title_changed.rs
+++ b/packages/wm/src/events/handle_window_title_changed.rs
@@ -1,11 +1,10 @@
use tracing::info;
+use wm_common::{try_warn, WindowRuleEvent};
+use wm_platform::NativeWindow;
use crate::{
- common::platform::NativeWindow,
- try_warn,
- user_config::{UserConfig, WindowRuleEvent},
- windows::{commands::run_window_rules, traits::WindowGetters},
- wm_state::WmState,
+ commands::window::run_window_rules, traits::WindowGetters,
+ user_config::UserConfig, wm_state::WmState,
};
pub fn handle_window_title_changed(
diff --git a/packages/wm/src/common/events/mod.rs b/packages/wm/src/events/mod.rs
similarity index 100%
rename from packages/wm/src/common/events/mod.rs
rename to packages/wm/src/events/mod.rs
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index f4752f97..14b12d20 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -3,7 +3,6 @@ use std::{iter, net::SocketAddr};
use anyhow::{bail, Context};
use clap::Parser;
use futures_util::{SinkExt, StreamExt};
-use serde::{Deserialize, Serialize};
use tokio::{
net::{TcpListener, TcpStream},
sync::{broadcast, mpsc},
@@ -12,117 +11,20 @@ use tokio::{
use tokio_tungstenite::{accept_async, tungstenite::Message};
use tracing::{info, warn};
use uuid::Uuid;
+use wm_common::{
+ AppCommand, AppMetadataData, BindingModesData, ClientResponseData,
+ ClientResponseMessage, CommandData, EventSubscribeData,
+ EventSubscriptionMessage, FocusedData, MonitorsData, QueryCommand,
+ ServerMessage, SubscribableEvent, TilingDirectionData, WindowsData,
+ WmEvent, WorkspacesData, DEFAULT_IPC_PORT,
+};
use crate::{
- app_command::{AppCommand, QueryCommand, SubscribableEvent},
- common::TilingDirection,
- containers::{
- traits::{CommonGetters, TilingDirectionGetters},
- ContainerDto,
- },
- user_config::{BindingModeConfig, UserConfig},
+ traits::{CommonGetters, TilingDirectionGetters},
+ user_config::UserConfig,
wm::WindowManager,
- wm_event::WmEvent,
};
-pub const DEFAULT_IPC_PORT: u32 = 6123;
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(tag = "messageType", rename_all = "snake_case")]
-pub enum ServerMessage {
- ClientResponse(ClientResponseMessage),
- EventSubscription(EventSubscriptionMessage),
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ClientResponseMessage {
- pub client_message: String,
- pub data: Option<ClientResponseData>,
- pub error: Option<String>,
- pub success: bool,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(untagged)]
-pub enum ClientResponseData {
- AppMetadata(AppMetadataData),
- BindingModes(BindingModesData),
- Command(CommandData),
- EventSubscribe(EventSubscribeData),
- EventUnsubscribe,
- Focused(FocusedData),
- Monitors(MonitorsData),
- TilingDirection(TilingDirectionData),
- Windows(WindowsData),
- Workspaces(WorkspacesData),
- Paused(bool),
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct AppMetadataData {
- pub version: String,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct BindingModesData {
- pub binding_modes: Vec<BindingModeConfig>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct CommandData {
- pub subject_container_id: Uuid,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct EventSubscribeData {
- pub subscription_id: Uuid,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct FocusedData {
- pub focused: ContainerDto,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct MonitorsData {
- pub monitors: Vec<ContainerDto>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct TilingDirectionData {
- pub tiling_direction: TilingDirection,
- pub direction_container: ContainerDto,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct WindowsData {
- pub windows: Vec<ContainerDto>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct WorkspacesData {
- pub workspaces: Vec<ContainerDto>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct EventSubscriptionMessage {
- pub data: Option<WmEvent>,
- pub error: Option<String>,
- pub subscription_id: Uuid,
- pub success: bool,
-}
-
pub struct IpcServer {
abort_handle: task::AbortHandle,
pub message_rx: mpsc::UnboundedReceiver<(
diff --git a/packages/wm/src/lib.rs b/packages/wm/src/lib.rs
deleted file mode 100644
index 451845ad..00000000
--- a/packages/wm/src/lib.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-#![feature(iterator_try_collect)]
-#![feature(once_cell_try)]
-
-pub mod app_command;
-pub mod cleanup;
-pub mod common;
-pub mod containers;
-pub mod ipc_client;
-pub mod ipc_server;
-pub mod monitors;
-pub mod sys_tray;
-pub mod user_config;
-pub mod windows;
-pub mod wm;
-pub mod wm_event;
-pub mod wm_state;
-pub mod workspaces;
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index b4495fa1..8b17e801 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -1,7 +1,11 @@
-// Conditionally build the application with either a `windows` or `console`
-// subsystem (default is `console`). This determines whether a console
-// window is spawned on launch, if not already ran through a console.
-#![cfg_attr(feature = "no_console", windows_subsystem = "windows")]
+// The `windows` or `console` subsystem (default is `console`) determines
+// whether a console window is spawned on launch, if not already ran
+// through a console. The following prevents this additional console window
+// in release mode.
+#![cfg_attr(
+ all(not(debug_assertions), target_os = "windows"),
+ windows_subsystem = "windows"
+)]
#![feature(iterator_try_collect)]
#![feature(once_cell_try)]
@@ -14,32 +18,23 @@ use tracing_subscriber::{
fmt::{self, writer::MakeWriterExt},
layer::SubscriberExt,
};
+use wm_common::{AppCommand, InvokeCommand, Verbosity, WmEvent};
+use wm_platform::Platform;
use crate::{
- app_command::{AppCommand, InvokeCommand, Verbosity},
- common::platform::Platform,
- ipc_client::IpcClient,
- ipc_server::{ClientResponseData, IpcServer},
- sys_tray::SystemTray,
- user_config::UserConfig,
+ ipc_server::IpcServer, sys_tray::SystemTray, user_config::UserConfig,
wm::WindowManager,
- wm_event::WmEvent,
};
-mod app_command;
-mod cleanup;
-mod common;
-mod containers;
-mod ipc_client;
+mod commands;
+mod events;
mod ipc_server;
-mod monitors;
+mod models;
mod sys_tray;
+mod traits;
mod user_config;
-mod windows;
mod wm;
-mod wm_event;
mod wm_state;
-mod workspaces;
/// Main entry point for the application.
///
@@ -66,7 +61,7 @@ async fn main() -> Result<()> {
res
}
- _ => start_cli(args).await,
+ _ => wm_cli::start(args).await,
}
}
@@ -117,7 +112,7 @@ async fn start_wm(
let mut ipc_server = IpcServer::start().await?;
// Start listening for platform events after populating initial state.
- let mut event_listener = Platform::start_event_listener(&config)?;
+ let mut event_listener = Platform::start_event_listener(&config.value)?;
// Run startup commands.
let startup_commands = config.value.general.startup_commands.clone();
@@ -168,7 +163,7 @@ async fn start_wm(
| WmEvent::PauseChanged { .. }
) {
event_listener.update(
- &config,
+ &config.value,
&wm.state.binding_modes,
wm.state.is_paused,
);
@@ -209,41 +204,6 @@ async fn start_wm(
Ok(())
}
-async fn start_cli(args: Vec<String>) -> Result<()> {
- let mut client = IpcClient::connect().await?;
-
- let message = args[1..].join(" ");
- client
- .send(&message)
- .await
- .context("Failed to send command to IPC server.")?;
-
- let client_response = client
- .client_response(&message)
- .await
- .context("Failed to receive response from IPC server.")?;
-
- match client_response.data {
- // For event subscriptions, omit the initial response message and
- // continuously output subsequent event messages.
- Some(ClientResponseData::EventSubscribe(data)) => loop {
- let event_subscription = client
- .event_subscription(&data.subscription_id)
- .await
- .context("Failed to receive response from IPC server.")?;
-
- println!("{}", serde_json::to_string(&event_subscription)?);
- },
- // For all other messages, output and exit when the first response
- // message is received.
- _ => {
- println!("{}", serde_json::to_string(&client_response)?);
- }
- }
-
- Ok(())
-}
-
/// Launches watcher binary. This is a separate process that is responsible
/// for restoring hidden windows in case the main WM process crashes.
///
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/models/container.rs
similarity index 94%
rename from packages/wm/src/containers/container.rs
rename to packages/wm/src/models/container.rs
index 6ea19cef..44c6de3a 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/models/container.rs
@@ -6,20 +6,19 @@ use std::{
use ambassador::Delegate;
use enum_as_inner::EnumAsInner;
use uuid::Uuid;
+use wm_common::{
+ ActiveDrag, ContainerDto, Direction, DisplayState, GapsConfig, Rect,
+ RectDelta, TilingDirection, WindowRuleConfig, WindowState,
+};
+use wm_platform::NativeWindow;
-use super::{RootContainer, SplitContainer};
use crate::{
- common::{
- platform::NativeWindow, Direction, DisplayState, Rect, RectDelta,
- TilingDirection,
- },
- containers::{traits::*, ContainerDto},
- monitors::Monitor,
- user_config::{GapsConfig, UserConfig, WindowRuleConfig},
- windows::{
- traits::*, ActiveDrag, NonTilingWindow, TilingWindow, WindowState,
+ models::{
+ Monitor, NonTilingWindow, RootContainer, SplitContainer, TilingWindow,
+ Workspace,
},
- workspaces::Workspace,
+ traits::*,
+ user_config::UserConfig,
};
/// A container of any type.
diff --git a/packages/wm/src/windows/insertion_target.rs b/packages/wm/src/models/insertion_target.rs
similarity index 83%
rename from packages/wm/src/windows/insertion_target.rs
rename to packages/wm/src/models/insertion_target.rs
index 905b3a82..7b2fa331 100644
--- a/packages/wm/src/windows/insertion_target.rs
+++ b/packages/wm/src/models/insertion_target.rs
@@ -1,4 +1,4 @@
-use crate::containers::Container;
+use crate::models::Container;
#[derive(Debug, Clone)]
pub struct InsertionTarget {
diff --git a/packages/wm/src/models/mod.rs b/packages/wm/src/models/mod.rs
new file mode 100644
index 00000000..58464c2d
--- /dev/null
+++ b/packages/wm/src/models/mod.rs
@@ -0,0 +1,19 @@
+mod container;
+mod insertion_target;
+mod monitor;
+mod non_tiling_window;
+mod root_container;
+mod split_container;
+mod tiling_window;
+mod workspace;
+mod workspace_target;
+
+pub use container::*;
+pub use insertion_target::*;
+pub use monitor::*;
+pub use non_tiling_window::*;
+pub use root_container::*;
+pub use split_container::*;
+pub use tiling_window::*;
+pub use workspace::*;
+pub use workspace_target::*;
diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/models/monitor.rs
similarity index 78%
rename from packages/wm/src/monitors/monitor.rs
rename to packages/wm/src/models/monitor.rs
index f970cd45..8229c99b 100644
--- a/packages/wm/src/monitors/monitor.rs
+++ b/packages/wm/src/models/monitor.rs
@@ -5,18 +5,17 @@ use std::{
};
use anyhow::Context;
-use serde::{Deserialize, Serialize};
use uuid::Uuid;
+use wm_common::{ContainerDto, MonitorDto, Rect};
+use wm_platform::NativeMonitor;
use crate::{
- common::{platform::NativeMonitor, Rect},
- containers::{
- traits::{CommonGetters, PositionGetters},
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
- },
impl_common_getters, impl_container_debug,
- workspaces::Workspace,
+ models::{
+ Container, DirectionContainer, TilingContainer, WindowContainer,
+ Workspace,
+ },
+ traits::{CommonGetters, PositionGetters},
};
#[derive(Clone)]
@@ -30,30 +29,6 @@ struct MonitorInner {
native: NativeMonitor,
}
-/// User-friendly representation of a monitor.
-///
-/// Used for IPC and debug logging.
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct MonitorDto {
- id: Uuid,
- parent_id: Option<Uuid>,
- children: Vec<ContainerDto>,
- child_focus_order: Vec<Uuid>,
- has_focus: bool,
- width: i32,
- height: i32,
- x: i32,
- y: i32,
- dpi: u32,
- scale_factor: f32,
- handle: isize,
- device_name: String,
- device_path: Option<String>,
- hardware_id: Option<String>,
- working_rect: Rect,
-}
-
impl Monitor {
pub fn new(native_monitor: NativeMonitor) -> Self {
let monitor = MonitorInner {
diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/models/non_tiling_window.rs
similarity index 90%
rename from packages/wm/src/windows/non_tiling_window.rs
rename to packages/wm/src/models/non_tiling_window.rs
index 1a946e31..0380930e 100644
--- a/packages/wm/src/windows/non_tiling_window.rs
+++ b/packages/wm/src/models/non_tiling_window.rs
@@ -6,20 +6,19 @@ use std::{
use anyhow::Context;
use uuid::Uuid;
-
-use super::{
- traits::WindowGetters, ActiveDrag, InsertionTarget, TilingWindow,
- WindowDto, WindowState,
+use wm_common::{
+ ActiveDrag, ContainerDto, DisplayState, GapsConfig, Rect, RectDelta,
+ WindowDto, WindowRuleConfig, WindowState,
};
+use wm_platform::NativeWindow;
+
use crate::{
- common::{platform::NativeWindow, DisplayState, Rect, RectDelta},
- containers::{
- traits::{CommonGetters, PositionGetters},
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
- },
impl_common_getters, impl_container_debug, impl_window_getters,
- user_config::{GapsConfig, WindowRuleConfig},
+ models::{
+ Container, DirectionContainer, InsertionTarget, TilingContainer,
+ TilingWindow, WindowContainer,
+ },
+ traits::{CommonGetters, PositionGetters, WindowGetters},
};
#[derive(Clone)]
diff --git a/packages/wm/src/containers/root_container.rs b/packages/wm/src/models/root_container.rs
similarity index 74%
rename from packages/wm/src/containers/root_container.rs
rename to packages/wm/src/models/root_container.rs
index 427fd1a7..0623af94 100644
--- a/packages/wm/src/containers/root_container.rs
+++ b/packages/wm/src/models/root_container.rs
@@ -5,17 +5,16 @@ use std::{
};
use anyhow::bail;
-use serde::{Deserialize, Serialize};
use uuid::Uuid;
+use wm_common::{ContainerDto, Rect, RootContainerDto};
-use super::{
- traits::{CommonGetters, PositionGetters},
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
-};
use crate::{
- common::Rect, impl_common_getters, impl_container_debug,
- monitors::Monitor,
+ impl_common_getters, impl_container_debug,
+ models::{
+ Container, DirectionContainer, Monitor, TilingContainer,
+ WindowContainer,
+ },
+ traits::{CommonGetters, PositionGetters},
};
/// Root node of the container tree.
@@ -29,18 +28,6 @@ struct RootContainerInner {
child_focus_order: VecDeque<Uuid>,
}
-/// User-friendly representation of a root container.
-///
-/// Used for IPC and debug logging.
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct RootContainerDto {
- id: Uuid,
- parent_id: Option<Uuid>,
- children: Vec<ContainerDto>,
- child_focus_order: Vec<Uuid>,
-}
-
impl Default for RootContainer {
fn default() -> Self {
let root = RootContainerInner {
diff --git a/packages/wm/src/containers/split_container.rs b/packages/wm/src/models/split_container.rs
similarity index 75%
rename from packages/wm/src/containers/split_container.rs
rename to packages/wm/src/models/split_container.rs
index 0d06a5e4..f5a2ebb5 100644
--- a/packages/wm/src/containers/split_container.rs
+++ b/packages/wm/src/models/split_container.rs
@@ -5,23 +5,22 @@ use std::{
};
use anyhow::Context;
-use serde::{Deserialize, Serialize};
use uuid::Uuid;
-
-use super::{
- traits::{
- CommonGetters, PositionGetters, TilingDirectionGetters,
- TilingSizeGetters,
- },
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
+use wm_common::{
+ ContainerDto, GapsConfig, Rect, SplitContainerDto, TilingDirection,
};
+
use crate::{
- common::{Rect, TilingDirection},
impl_common_getters, impl_container_debug,
impl_position_getters_as_resizable, impl_tiling_direction_getters,
impl_tiling_size_getters,
- user_config::GapsConfig,
+ models::{
+ Container, DirectionContainer, TilingContainer, WindowContainer,
+ },
+ traits::{
+ CommonGetters, PositionGetters, TilingDirectionGetters,
+ TilingSizeGetters,
+ },
};
#[derive(Clone)]
@@ -37,25 +36,6 @@ struct SplitContainerInner {
gaps_config: GapsConfig,
}
-/// User-friendly representation of a split container.
-///
-/// Used for IPC and debug logging.
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct SplitContainerDto {
- id: Uuid,
- parent_id: Option<Uuid>,
- children: Vec<ContainerDto>,
- child_focus_order: Vec<Uuid>,
- has_focus: bool,
- tiling_size: f32,
- width: i32,
- height: i32,
- x: i32,
- y: i32,
- tiling_direction: TilingDirection,
-}
-
impl SplitContainer {
pub fn new(
tiling_direction: TilingDirection,
diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/models/tiling_window.rs
similarity index 87%
rename from packages/wm/src/windows/tiling_window.rs
rename to packages/wm/src/models/tiling_window.rs
index 5a3f2432..94afcf11 100644
--- a/packages/wm/src/windows/tiling_window.rs
+++ b/packages/wm/src/models/tiling_window.rs
@@ -6,28 +6,24 @@ use std::{
use anyhow::Context;
use uuid::Uuid;
-
-use super::{
- traits::WindowGetters, InsertionTarget, NonTilingWindow, WindowDto,
- WindowState,
+use wm_common::{
+ ActiveDrag, ContainerDto, DisplayState, GapsConfig, Rect, RectDelta,
+ TilingDirection, WindowDto, WindowRuleConfig, WindowState,
};
+use wm_platform::NativeWindow;
+
use crate::{
- common::{
- platform::NativeWindow, DisplayState, Rect, RectDelta, TilingDirection,
- },
- containers::{
- traits::{
- CommonGetters, PositionGetters, TilingDirectionGetters,
- TilingSizeGetters,
- },
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
- },
impl_common_getters, impl_container_debug,
impl_position_getters_as_resizable, impl_tiling_size_getters,
impl_window_getters,
- user_config::{GapsConfig, WindowRuleConfig},
- windows::active_drag::ActiveDrag,
+ models::{
+ Container, DirectionContainer, InsertionTarget, NonTilingWindow,
+ TilingContainer, WindowContainer,
+ },
+ traits::{
+ CommonGetters, PositionGetters, TilingDirectionGetters,
+ TilingSizeGetters, WindowGetters,
+ },
};
#[derive(Clone)]
diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/models/workspace.rs
similarity index 81%
rename from packages/wm/src/workspaces/workspace.rs
rename to packages/wm/src/models/workspace.rs
index 8f3f0f19..a7ff3132 100644
--- a/packages/wm/src/workspaces/workspace.rs
+++ b/packages/wm/src/models/workspace.rs
@@ -5,19 +5,19 @@ use std::{
};
use anyhow::Context;
-use serde::{Deserialize, Serialize};
use uuid::Uuid;
+use wm_common::{
+ ContainerDto, GapsConfig, Rect, TilingDirection, WorkspaceConfig,
+ WorkspaceDto,
+};
use crate::{
- common::{Rect, TilingDirection},
- containers::{
- traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
- },
impl_common_getters, impl_container_debug,
impl_tiling_direction_getters,
- user_config::{GapsConfig, WorkspaceConfig},
+ models::{
+ Container, DirectionContainer, TilingContainer, WindowContainer,
+ },
+ traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
};
#[derive(Clone)]
@@ -34,27 +34,6 @@ struct WorkspaceInner {
tiling_direction: TilingDirection,
}
-/// User-friendly representation of a workspace.
-///
-/// Used for IPC and debug logging.
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct WorkspaceDto {
- id: Uuid,
- name: String,
- display_name: Option<String>,
- parent_id: Option<Uuid>,
- children: Vec<ContainerDto>,
- child_focus_order: Vec<Uuid>,
- has_focus: bool,
- is_displayed: bool,
- width: i32,
- height: i32,
- x: i32,
- y: i32,
- tiling_direction: TilingDirection,
-}
-
impl Workspace {
pub fn new(
config: WorkspaceConfig,
diff --git a/packages/wm/src/workspaces/workspace_target.rs b/packages/wm/src/models/workspace_target.rs
similarity index 81%
rename from packages/wm/src/workspaces/workspace_target.rs
rename to packages/wm/src/models/workspace_target.rs
index 41d138a9..941b2b50 100644
--- a/packages/wm/src/workspaces/workspace_target.rs
+++ b/packages/wm/src/models/workspace_target.rs
@@ -1,4 +1,4 @@
-use crate::common::Direction;
+use wm_common::Direction;
pub enum WorkspaceTarget {
Name(String),
diff --git a/packages/wm/src/monitors/mod.rs b/packages/wm/src/monitors/mod.rs
deleted file mode 100644
index e75205b2..00000000
--- a/packages/wm/src/monitors/mod.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-pub mod commands;
-mod monitor;
-
-pub use monitor::*;
diff --git a/packages/wm/src/sys_tray.rs b/packages/wm/src/sys_tray.rs
index bbdc8d00..1c083beb 100644
--- a/packages/wm/src/sys_tray.rs
+++ b/packages/wm/src/sys_tray.rs
@@ -7,8 +7,7 @@ use tray_icon::{
menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem},
Icon, TrayIconBuilder,
};
-
-use crate::common::platform::Platform;
+use wm_platform::Platform;
/// Ordinal to IDI_ICON definition in embedded resource file.
const IDI_ICON: u16 = 32512;
diff --git a/packages/wm/src/containers/traits/common_getters.rs b/packages/wm/src/traits/common_getters.rs
similarity index 98%
rename from packages/wm/src/containers/traits/common_getters.rs
rename to packages/wm/src/traits/common_getters.rs
index 186f8869..9940db22 100644
--- a/packages/wm/src/containers/traits/common_getters.rs
+++ b/packages/wm/src/traits/common_getters.rs
@@ -5,14 +5,11 @@ use std::{
use ambassador::delegatable_trait;
use uuid::Uuid;
+use wm_common::ContainerDto;
-use crate::{
- containers::{
- Container, ContainerDto, DirectionContainer, TilingContainer,
- WindowContainer,
- },
- monitors::Monitor,
- workspaces::Workspace,
+use crate::models::{
+ Container, DirectionContainer, Monitor, TilingContainer,
+ WindowContainer, Workspace,
};
#[delegatable_trait]
diff --git a/packages/wm/src/containers/traits/mod.rs b/packages/wm/src/traits/mod.rs
similarity index 82%
rename from packages/wm/src/containers/traits/mod.rs
rename to packages/wm/src/traits/mod.rs
index abe387a1..bf67320e 100644
--- a/packages/wm/src/containers/traits/mod.rs
+++ b/packages/wm/src/traits/mod.rs
@@ -2,8 +2,10 @@ mod common_getters;
mod position_getters;
mod tiling_direction_getters;
mod tiling_size_getters;
+mod window_getters;
pub use common_getters::*;
pub use position_getters::*;
pub use tiling_direction_getters::*;
pub use tiling_size_getters::*;
+pub use window_getters::*;
diff --git a/packages/wm/src/containers/traits/position_getters.rs b/packages/wm/src/traits/position_getters.rs
similarity index 99%
rename from packages/wm/src/containers/traits/position_getters.rs
rename to packages/wm/src/traits/position_getters.rs
index d37b3a6a..28e5b6bc 100644
--- a/packages/wm/src/containers/traits/position_getters.rs
+++ b/packages/wm/src/traits/position_getters.rs
@@ -1,6 +1,5 @@
use ambassador::delegatable_trait;
-
-use crate::common::Rect;
+use wm_common::Rect;
#[delegatable_trait]
pub trait PositionGetters {
diff --git a/packages/wm/src/containers/traits/tiling_direction_getters.rs b/packages/wm/src/traits/tiling_direction_getters.rs
similarity index 94%
rename from packages/wm/src/containers/traits/tiling_direction_getters.rs
rename to packages/wm/src/traits/tiling_direction_getters.rs
index 60d873eb..b06cf534 100644
--- a/packages/wm/src/containers/traits/tiling_direction_getters.rs
+++ b/packages/wm/src/traits/tiling_direction_getters.rs
@@ -1,11 +1,8 @@
use ambassador::delegatable_trait;
+use wm_common::{Direction, TilingDirection};
use super::CommonGetters;
-use crate::{
- common::{Direction, TilingDirection},
- containers::TilingContainer,
- windows::TilingWindow,
-};
+use crate::models::{TilingContainer, TilingWindow};
#[delegatable_trait]
pub trait TilingDirectionGetters: CommonGetters {
diff --git a/packages/wm/src/containers/traits/tiling_size_getters.rs b/packages/wm/src/traits/tiling_size_getters.rs
similarity index 95%
rename from packages/wm/src/containers/traits/tiling_size_getters.rs
rename to packages/wm/src/traits/tiling_size_getters.rs
index ffdbe04c..940fbe78 100644
--- a/packages/wm/src/containers/traits/tiling_size_getters.rs
+++ b/packages/wm/src/traits/tiling_size_getters.rs
@@ -2,13 +2,10 @@ use std::cell::Ref;
use ambassador::delegatable_trait;
use anyhow::Context;
+use wm_common::{GapsConfig, TilingDirection};
use super::{CommonGetters, PositionGetters, TilingDirectionGetters};
-use crate::{
- common::TilingDirection,
- containers::{Container, DirectionContainer, TilingContainer},
- user_config::GapsConfig,
-};
+use crate::models::{Container, DirectionContainer, TilingContainer};
pub const MIN_TILING_SIZE: f32 = 0.01;
diff --git a/packages/wm/src/windows/traits/window_getters.rs b/packages/wm/src/traits/window_getters.rs
similarity index 96%
rename from packages/wm/src/windows/traits/window_getters.rs
rename to packages/wm/src/traits/window_getters.rs
index bdaabe78..ba426f2d 100644
--- a/packages/wm/src/windows/traits/window_getters.rs
+++ b/packages/wm/src/traits/window_getters.rs
@@ -1,14 +1,13 @@
use std::cell::Ref;
use ambassador::delegatable_trait;
-
-use crate::{
- common::{
- platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta,
- },
- user_config::{UserConfig, WindowRuleConfig},
- windows::{active_drag::ActiveDrag, WindowState},
+use wm_common::{
+ ActiveDrag, DisplayState, LengthValue, Rect, RectDelta,
+ WindowRuleConfig, WindowState,
};
+use wm_platform::NativeWindow;
+
+use crate::user_config::UserConfig;
#[delegatable_trait]
pub trait WindowGetters {
@@ -37,7 +36,7 @@ pub trait WindowGetters {
let possible_states = [
Some(target_state),
self.prev_state(),
- Some(WindowState::default_from_config(config)),
+ Some(WindowState::default_from_config(&config.value)),
];
// Return the first possible state with a different discriminant.
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 35f144a8..46dca9bd 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -1,15 +1,14 @@
use std::{collections::HashMap, env, fs, path::PathBuf};
use anyhow::{Context, Result};
-use serde::{Deserialize, Serialize};
+use wm_common::{
+ InvokeCommand, MatchType, ParsedConfig, WindowMatchConfig,
+ WindowRuleConfig, WindowRuleEvent, WorkspaceConfig,
+};
use crate::{
- app_command::InvokeCommand,
- common::{Color, LengthValue, OpacityValue, RectDelta},
- containers::{traits::CommonGetters, WindowContainer},
- monitors::Monitor,
- windows::traits::WindowGetters,
- workspaces::Workspace,
+ models::{Monitor, WindowContainer, Workspace},
+ traits::{CommonGetters, WindowGetters},
};
/// Resource string for the sample config file.
@@ -345,363 +344,3 @@ impl UserConfig {
|| outer_gap.top.amount > 1.0
}
}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct ParsedConfig {
- pub binding_modes: Vec<BindingModeConfig>,
- pub gaps: GapsConfig,
- pub general: GeneralConfig,
- pub keybindings: Vec<KeybindingConfig>,
- pub window_behavior: WindowBehaviorConfig,
- pub window_effects: WindowEffectsConfig,
- pub window_rules: Vec<WindowRuleConfig>,
- pub workspaces: Vec<WorkspaceConfig>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct BindingModeConfig {
- /// Name of the binding mode.
- pub name: String,
-
- /// Display name of the binding mode.
- pub display_name: Option<String>,
-
- /// Keybindings that will be active when the binding mode is active.
- pub keybindings: Vec<KeybindingConfig>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct GapsConfig {
- /// Whether to scale the gaps with the DPI of the monitor.
- #[serde(default = "default_bool::<true>")]
- pub scale_with_dpi: bool,
-
- /// Gap between adjacent windows.
- pub inner_gap: LengthValue,
-
- /// Gap between windows and the screen edge.
- pub outer_gap: RectDelta,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct GeneralConfig {
- /// Config for automatically moving the cursor.
- pub cursor_jump: CursorJumpConfig,
-
- /// Whether to automatically focus windows underneath the cursor.
- #[serde(default = "default_bool::<false>")]
- pub focus_follows_cursor: bool,
-
- /// Whether to switch back and forth between the previously focused
- /// workspace when focusing the current workspace.
- #[serde(default = "default_bool::<true>")]
- pub toggle_workspace_on_refocus: bool,
-
- /// Commands to run when the WM has started (e.g. to run a script or
- /// launch another application).
- #[serde(default)]
- pub startup_commands: Vec<InvokeCommand>,
-
- /// Commands to run just before the WM is shutdown.
- #[serde(default)]
- pub shutdown_commands: Vec<InvokeCommand>,
-
- /// Commands to run after the WM config has reloaded.
- #[serde(default)]
- pub config_reload_commands: Vec<InvokeCommand>,
-
- /// How windows should be hidden when switching workspaces.
- #[serde(default)]
- pub hide_method: HideMethod,
-
- /// Affects which windows get shown in the native Windows taskbar.
- #[serde(default = "default_bool::<false>")]
- pub show_all_in_taskbar: bool,
-}
-
-#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all = "snake_case")]
-pub enum HideMethod {
- Hide,
- #[default]
- Cloak,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct CursorJumpConfig {
- /// Whether to automatically move the cursor on the specified trigger.
- #[serde(default = "default_bool::<true>")]
- pub enabled: bool,
-
- /// Trigger for cursor jump.
- #[serde(default)]
- pub trigger: CursorJumpTrigger,
-}
-
-#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all = "snake_case")]
-pub enum CursorJumpTrigger {
- #[default]
- MonitorFocus,
- WindowFocus,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct KeybindingConfig {
- /// Keyboard shortcut to trigger the keybinding.
- pub bindings: Vec<String>,
-
- /// WM commands to run when the keybinding is triggered.
- pub commands: Vec<InvokeCommand>,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowBehaviorConfig {
- /// New windows are created in this state whenever possible.
- #[serde(default)]
- pub initial_state: InitialWindowState,
-
- /// Sets the default options for when a new window is created. This also
- /// changes the defaults for when the state change commands, like
- /// `set_floating`, are used without any flags.
- pub state_defaults: WindowStateDefaultsConfig,
-}
-
-#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all = "snake_case")]
-pub enum InitialWindowState {
- #[default]
- Tiling,
- Floating,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowStateDefaultsConfig {
- pub floating: FloatingStateConfig,
- pub fullscreen: FullscreenStateConfig,
-}
-
-#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct FloatingStateConfig {
- /// Whether to center new floating windows.
- #[serde(default = "default_bool::<true>")]
- pub centered: bool,
-
- /// Whether to show floating windows as always on top.
- #[serde(default = "default_bool::<false>")]
- pub shown_on_top: bool,
-}
-
-#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct FullscreenStateConfig {
- /// Whether to prefer fullscreen windows to be maximized.
- #[serde(default = "default_bool::<true>")]
- pub maximized: bool,
-
- /// Whether to show fullscreen windows as always on top.
- #[serde(default = "default_bool::<false>")]
- pub shown_on_top: bool,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowEffectsConfig {
- /// Visual effects to apply to the focused window.
- pub focused_window: WindowEffectConfig,
-
- /// Visual effects to apply to non-focused windows.
- pub other_windows: WindowEffectConfig,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowEffectConfig {
- /// Config for optionally applying a colored border.
- pub border: BorderEffectConfig,
-
- /// Config for optionally hiding the title bar.
- #[serde(default)]
- pub hide_title_bar: HideTitleBarEffectConfig,
-
- /// Config for optionally changing the corner style.
- #[serde(default)]
- pub corner_style: CornerEffectConfig,
-
- /// Config for optionally applying transparency.
- #[serde(default)]
- pub transparency: TransparencyEffectConfig,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct BorderEffectConfig {
- /// Whether to enable the effect.
- #[serde(default = "default_bool::<false>")]
- pub enabled: bool,
-
- /// Color of the window border.
- #[serde(default = "default_blue")]
- pub color: Color,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize, Default)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct HideTitleBarEffectConfig {
- /// Whether to enable the effect.
- #[serde(default = "default_bool::<false>")]
- pub enabled: bool,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize, Default)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct TransparencyEffectConfig {
- /// Whether to enable the effect.
- #[serde(default = "default_bool::<false>")]
- pub enabled: bool,
-
- /// The opacity to apply.
- #[serde(default)]
- pub opacity: OpacityValue,
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct CornerEffectConfig {
- /// Whether to enable the effect.
- #[serde(default = "default_bool::<false>")]
- pub enabled: bool,
-
- /// Style of the window corners.
- #[serde(default)]
- pub style: CornerStyle,
-}
-
-#[derive(
- Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default,
-)]
-#[serde(rename_all = "snake_case")]
-pub enum CornerStyle {
- #[default]
- Default,
- Square,
- Rounded,
- SmallRounded,
-}
-
-#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowRuleConfig {
- pub commands: Vec<InvokeCommand>,
-
- #[serde(rename = "match")]
- pub match_window: Vec<WindowMatchConfig>,
-
- #[serde(default = "default_window_rule_on")]
- pub on: Vec<WindowRuleEvent>,
-
- #[serde(default = "default_bool::<true>")]
- pub run_once: bool,
-}
-
-#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WindowMatchConfig {
- #[serde(default)]
- pub window_process: Option<MatchType>,
-
- #[serde(default)]
- pub window_class: Option<MatchType>,
-
- #[serde(default)]
- pub window_title: Option<MatchType>,
-}
-
-/// Due to limitations in `serde_yaml`, we need to use an untagged enum
-/// instead of a regular enum for serialization. Using a regular enum
-/// causes issues with flow-style objects in YAML.
-#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
-#[serde(untagged)]
-pub enum MatchType {
- Equals { equals: String },
- Includes { includes: String },
- Regex { regex: String },
- NotEquals { not_equals: String },
- NotRegex { not_regex: String },
-}
-
-impl MatchType {
- /// Whether the given value is a match for the match type.
- fn is_match(&self, value: &str) -> bool {
- match self {
- MatchType::Equals { equals } => value == equals,
- MatchType::Includes { includes } => value.contains(includes),
- MatchType::Regex { regex } => regex::Regex::new(regex)
- .map(|re| re.is_match(value))
- .unwrap_or(false),
- MatchType::NotEquals { not_equals } => value != not_equals,
- MatchType::NotRegex { not_regex } => regex::Regex::new(not_regex)
- .map(|re| !re.is_match(value))
- .unwrap_or(false),
- }
- }
-}
-
-#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
-#[serde(rename_all = "snake_case")]
-pub enum WindowRuleEvent {
- /// When a window receives native focus.
- Focus,
- /// When a window is initially managed.
- Manage,
- /// When the title of a window changes.
- TitleChange,
-}
-
-#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
-#[serde(rename_all(serialize = "camelCase"))]
-pub struct WorkspaceConfig {
- pub name: String,
- pub display_name: Option<String>,
- pub bind_to_monitor: Option<u32>,
- #[serde(default = "default_bool::<false>")]
- pub keep_alive: bool,
-}
-
-/// Helper function for setting a default value for a boolean field.
-const fn default_bool<const V: bool>() -> bool {
- V
-}
-
-/// Helper function for setting a default value for a color field.
-const fn default_blue() -> Color {
- Color {
- r: 140,
- g: 190,
- b: 255,
- a: 255,
- }
-}
-
-/// Helper function for setting a default value for window rule events.
-fn default_window_rule_on() -> Vec<WindowRuleEvent> {
- vec![WindowRuleEvent::Manage, WindowRuleEvent::TitleChange]
-}
-
-impl Default for CornerEffectConfig {
- fn default() -> Self {
- CornerEffectConfig {
- enabled: false,
- style: CornerStyle::Default,
- }
- }
-}
diff --git a/packages/wm/src/windows/mod.rs b/packages/wm/src/windows/mod.rs
deleted file mode 100644
index 213c28d5..00000000
--- a/packages/wm/src/windows/mod.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-mod active_drag;
-pub mod commands;
-mod insertion_target;
-mod non_tiling_window;
-mod tiling_window;
-pub mod traits;
-mod window_dto;
-mod window_state;
-
-pub use active_drag::*;
-pub use insertion_target::*;
-pub use non_tiling_window::*;
-pub use tiling_window::*;
-pub use window_dto::*;
-pub use window_state::*;
diff --git a/packages/wm/src/windows/traits/mod.rs b/packages/wm/src/windows/traits/mod.rs
deleted file mode 100644
index 32c249b5..00000000
--- a/packages/wm/src/windows/traits/mod.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-mod window_getters;
-
-pub use window_getters::*;
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 9fe5cb1b..3230af9a 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -1,24 +1,41 @@
-use anyhow::Context;
+use anyhow::{bail, Context};
use tokio::sync::mpsc::{self};
+use tracing::warn;
use uuid::Uuid;
+use wm_common::{
+ FloatingStateConfig, FullscreenStateConfig, InvokeCommand, LengthValue,
+ RectDelta, TitleBarVisibility, WindowState, WmEvent,
+};
+use wm_platform::PlatformEvent;
use crate::{
- app_command::InvokeCommand,
- common::{
- commands::platform_sync,
- events::{
- handle_display_settings_changed, handle_mouse_move,
- handle_window_destroyed, handle_window_focused,
- handle_window_hidden, handle_window_location_changed,
- handle_window_minimize_ended, handle_window_minimized,
- handle_window_moved_or_resized_end,
- handle_window_moved_or_resized_start, handle_window_shown,
- handle_window_title_changed,
+ commands::{
+ container::{
+ focus_in_direction, set_tiling_direction, toggle_tiling_direction,
+ },
+ general::{
+ cycle_focus, disable_binding_mode, enable_binding_mode,
+ platform_sync, reload_config, shell_exec, toggle_pause,
+ },
+ monitor::focus_monitor,
+ window::{
+ ignore_window, move_window_in_direction, move_window_to_workspace,
+ resize_window, set_window_position, set_window_size,
+ update_window_state, WindowPositionTarget,
},
- platform::PlatformEvent,
+ workspace::{focus_workspace, move_workspace_in_direction},
},
+ events::{
+ handle_display_settings_changed, handle_mouse_move,
+ handle_window_destroyed, handle_window_focused, handle_window_hidden,
+ handle_window_location_changed, handle_window_minimize_ended,
+ handle_window_minimized, handle_window_moved_or_resized_end,
+ handle_window_moved_or_resized_start, handle_window_shown,
+ handle_window_title_changed,
+ },
+ models::{Container, WorkspaceTarget},
+ traits::{CommonGetters, WindowGetters},
user_config::UserConfig,
- wm_event::WmEvent,
wm_state::WmState,
};
@@ -116,8 +133,8 @@ impl WindowManager {
.context("No subject container for command.")?,
};
- let new_subject_container_id = InvokeCommand::run_multiple(
- commands,
+ let new_subject_container_id = WindowManager::run_commands(
+ &commands,
subject_container,
state,
config,
@@ -127,4 +144,516 @@ impl WindowManager {
Ok(new_subject_container_id)
}
+
+ pub fn run_commands(
+ commands: &Vec<InvokeCommand>,
+ subject_container: Container,
+ state: &mut WmState,
+ config: &mut UserConfig,
+ ) -> anyhow::Result<Uuid> {
+ let mut current_subject_container = subject_container;
+
+ for command in commands {
+ WindowManager::run_command(
+ &command,
+ current_subject_container.clone(),
+ state,
+ config,
+ )?;
+
+ // Update the subject container in case the container type changes.
+ // For example, when going from a tiling to a floating window.
+ current_subject_container =
+ match current_subject_container.is_detached() {
+ false => current_subject_container,
+ true => {
+ match state.container_by_id(current_subject_container.id()) {
+ Some(container) => container,
+ None => break,
+ }
+ }
+ }
+ }
+
+ Ok(current_subject_container.id())
+ }
+
+ pub fn run_command(
+ command: &InvokeCommand,
+ subject_container: Container,
+ state: &mut WmState,
+ config: &mut UserConfig,
+ ) -> anyhow::Result<()> {
+ if subject_container.is_detached() {
+ bail!("Cannot run command because subject container is detached.");
+ }
+
+ match &command {
+ InvokeCommand::AdjustBorders(args) => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ let args = args.clone();
+ let border_delta = RectDelta::new(
+ args.left.unwrap_or(LengthValue::from_px(0)),
+ args.top.unwrap_or(LengthValue::from_px(0)),
+ args.right.unwrap_or(LengthValue::from_px(0)),
+ args.bottom.unwrap_or(LengthValue::from_px(0)),
+ );
+
+ window.set_border_delta(border_delta);
+ state.pending_sync.containers_to_redraw.push(window.into());
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::Close => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ // Window handle might no longer be valid here.
+ if let Err(err) = window.native().close() {
+ warn!("Failed to close window: {:?}", err);
+ }
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::Focus(args) => {
+ if let Some(direction) = &args.direction {
+ focus_in_direction(subject_container, direction, state)?;
+ }
+
+ if let Some(name) = &args.workspace {
+ focus_workspace(
+ WorkspaceTarget::Name(name.to_string()),
+ state,
+ config,
+ )?;
+ }
+
+ if let Some(monitor_index) = &args.monitor {
+ focus_monitor(*monitor_index, state, config)?;
+ }
+
+ if args.next_active_workspace {
+ focus_workspace(WorkspaceTarget::NextActive, state, config)?;
+ }
+
+ if args.prev_active_workspace {
+ focus_workspace(WorkspaceTarget::PreviousActive, state, config)?;
+ }
+
+ if args.next_workspace {
+ focus_workspace(WorkspaceTarget::Next, state, config)?;
+ }
+
+ if args.prev_workspace {
+ focus_workspace(WorkspaceTarget::Previous, state, config)?;
+ }
+
+ if args.recent_workspace {
+ focus_workspace(WorkspaceTarget::Recent, state, config)?;
+ }
+
+ Ok(())
+ }
+ InvokeCommand::Ignore => {
+ match subject_container.as_window_container() {
+ Ok(window) => ignore_window(window, state),
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::Move(args) => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ if let Some(direction) = &args.direction {
+ move_window_in_direction(
+ window.clone(),
+ direction,
+ state,
+ config,
+ )?;
+ };
+
+ if let Some(name) = &args.workspace {
+ move_window_to_workspace(
+ window.clone(),
+ WorkspaceTarget::Name(name.to_string()),
+ state,
+ config,
+ )?;
+ }
+
+ if args.next_active_workspace {
+ move_window_to_workspace(
+ window.clone(),
+ WorkspaceTarget::NextActive,
+ state,
+ config,
+ )?;
+ }
+
+ if args.prev_active_workspace {
+ move_window_to_workspace(
+ window.clone(),
+ WorkspaceTarget::PreviousActive,
+ state,
+ config,
+ )?;
+ }
+
+ if args.next_workspace {
+ move_window_to_workspace(
+ window.clone(),
+ WorkspaceTarget::Next,
+ state,
+ config,
+ )?;
+ }
+
+ if args.prev_workspace {
+ move_window_to_workspace(
+ window.clone(),
+ WorkspaceTarget::Previous,
+ state,
+ config,
+ )?;
+ }
+
+ if args.recent_workspace {
+ move_window_to_workspace(
+ window,
+ WorkspaceTarget::Recent,
+ state,
+ config,
+ )?;
+ }
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::MoveWorkspace { direction } => {
+ let workspace =
+ subject_container.workspace().context("No workspace.")?;
+
+ move_workspace_in_direction(
+ workspace,
+ direction.clone(),
+ state,
+ config,
+ )
+ }
+ InvokeCommand::Position(args) => {
+ match subject_container.as_window_container() {
+ Ok(window) => match args.centered {
+ true => set_window_position(
+ window,
+ WindowPositionTarget::Centered,
+ state,
+ ),
+ false => set_window_position(
+ window,
+ WindowPositionTarget::Coordinates(
+ args.x_pos.clone(),
+ args.y_pos.clone(),
+ ),
+ state,
+ ),
+ },
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::Resize(args) => {
+ match subject_container.as_window_container() {
+ Ok(window) => resize_window(
+ window,
+ args.width.clone(),
+ args.height.clone(),
+ state,
+ ),
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::SetFloating {
+ centered,
+ shown_on_top,
+ x_pos,
+ y_pos,
+ width,
+ height,
+ } => match subject_container.as_window_container() {
+ Ok(window) => {
+ let floating_defaults =
+ &config.value.window_behavior.state_defaults.floating;
+ let centered = centered.unwrap_or(floating_defaults.centered);
+
+ let window = update_window_state(
+ window.clone(),
+ WindowState::Floating(FloatingStateConfig {
+ centered,
+ shown_on_top: shown_on_top
+ .unwrap_or(floating_defaults.shown_on_top),
+ }),
+ state,
+ config,
+ )?;
+
+ // Allow size and position to be set if window has not previously
+ // been manually placed.
+ if !window.has_custom_floating_placement() {
+ if width.is_some() || height.is_some() {
+ set_window_size(
+ window.clone(),
+ width.clone(),
+ height.clone(),
+ state,
+ )?;
+ }
+
+ if centered {
+ set_window_position(
+ window,
+ WindowPositionTarget::Centered,
+ state,
+ )?;
+ } else if x_pos.is_some() || y_pos.is_some() {
+ set_window_position(
+ window,
+ WindowPositionTarget::Coordinates(
+ x_pos.clone(),
+ y_pos.clone(),
+ ),
+ state,
+ )?;
+ }
+ }
+
+ Ok(())
+ }
+ _ => Ok(()),
+ },
+ InvokeCommand::SetFullscreen {
+ maximized,
+ shown_on_top,
+ } => match subject_container.as_window_container() {
+ Ok(window) => {
+ let fullscreen_defaults =
+ &config.value.window_behavior.state_defaults.fullscreen;
+
+ update_window_state(
+ window.clone(),
+ WindowState::Fullscreen(FullscreenStateConfig {
+ maximized: maximized
+ .unwrap_or(fullscreen_defaults.maximized),
+ shown_on_top: shown_on_top
+ .unwrap_or(fullscreen_defaults.shown_on_top),
+ }),
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ },
+ InvokeCommand::SetMinimized => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ update_window_state(
+ window.clone(),
+ WindowState::Minimized,
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::SetTiling => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ update_window_state(
+ window,
+ WindowState::Tiling,
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::SetTitleBarVisibility { visibility } => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ _ = window.native().set_title_bar_visibility(
+ *visibility == TitleBarVisibility::Shown,
+ );
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::SetOpacity { opacity } => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ _ = window.native().set_opacity(opacity.clone());
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::ShellExec {
+ hide_window,
+ command,
+ } => shell_exec(&command.join(" "), *hide_window),
+ InvokeCommand::Size(args) => {
+ match subject_container.as_window_container() {
+ Ok(window) => set_window_size(
+ window,
+ args.width.clone(),
+ args.height.clone(),
+ state,
+ ),
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::ToggleFloating {
+ centered,
+ shown_on_top,
+ } => match subject_container.as_window_container() {
+ Ok(window) => {
+ let floating_defaults =
+ &config.value.window_behavior.state_defaults.floating;
+
+ let centered = centered.unwrap_or(floating_defaults.centered);
+ let target_state = WindowState::Floating(FloatingStateConfig {
+ centered,
+ shown_on_top: shown_on_top
+ .unwrap_or(floating_defaults.shown_on_top),
+ });
+
+ let window = update_window_state(
+ window.clone(),
+ window.toggled_state(target_state, config),
+ state,
+ config,
+ )?;
+
+ if !window.has_custom_floating_placement() && centered {
+ set_window_position(
+ window,
+ WindowPositionTarget::Centered,
+ state,
+ )?;
+ }
+
+ Ok(())
+ }
+ _ => Ok(()),
+ },
+ InvokeCommand::ToggleFullscreen {
+ maximized,
+ shown_on_top,
+ } => match subject_container.as_window_container() {
+ Ok(window) => {
+ let fullscreen_defaults =
+ &config.value.window_behavior.state_defaults.fullscreen;
+
+ let target_state =
+ WindowState::Fullscreen(FullscreenStateConfig {
+ maximized: maximized
+ .unwrap_or(fullscreen_defaults.maximized),
+ shown_on_top: shown_on_top
+ .unwrap_or(fullscreen_defaults.shown_on_top),
+ });
+
+ update_window_state(
+ window.clone(),
+ window.toggled_state(target_state, config),
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ },
+ InvokeCommand::ToggleMinimized => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ update_window_state(
+ window.clone(),
+ window.toggled_state(WindowState::Minimized, config),
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::ToggleTiling => {
+ match subject_container.as_window_container() {
+ Ok(window) => {
+ update_window_state(
+ window.clone(),
+ window.toggled_state(WindowState::Tiling, config),
+ state,
+ config,
+ )?;
+
+ Ok(())
+ }
+ _ => Ok(()),
+ }
+ }
+ InvokeCommand::ToggleTilingDirection => {
+ toggle_tiling_direction(subject_container, state, config)
+ }
+ InvokeCommand::SetTilingDirection { tiling_direction } => {
+ set_tiling_direction(
+ subject_container,
+ state,
+ config,
+ tiling_direction.clone(),
+ )
+ }
+ InvokeCommand::WmCycleFocus {
+ omit_fullscreen,
+ omit_minimized,
+ } => cycle_focus(*omit_fullscreen, *omit_minimized, state, config),
+ InvokeCommand::WmDisableBindingMode { name } => {
+ disable_binding_mode(name, state);
+ Ok(())
+ }
+ InvokeCommand::WmEnableBindingMode { name } => {
+ enable_binding_mode(name, state, config)
+ }
+ InvokeCommand::WmExit => {
+ state.emit_exit();
+ Ok(())
+ }
+ InvokeCommand::WmRedraw => {
+ let root_container = state.root_container.clone();
+ state
+ .pending_sync
+ .containers_to_redraw
+ .push(root_container.into());
+
+ Ok(())
+ }
+ InvokeCommand::WmReloadConfig => reload_config(state, config),
+ InvokeCommand::WmTogglePause => toggle_pause(state),
+ }
+ }
}
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index 2d2dd5f2..8f309500 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -4,24 +4,22 @@ use anyhow::Context;
use tokio::sync::mpsc::{self};
use tracing::warn;
use uuid::Uuid;
+use wm_common::{
+ BindingModeConfig, Direction, Point, WindowState, WmEvent,
+};
+use wm_platform::{NativeMonitor, NativeWindow, Platform};
use crate::{
- cleanup::run_cleanup,
- common::{
- commands::platform_sync,
- platform::{NativeMonitor, NativeWindow, Platform},
- Direction, Point,
+ commands::{
+ container::set_focused_descendant, general::platform_sync,
+ monitor::add_monitor, window::manage_window,
},
- containers::{
- commands::set_focused_descendant,
- traits::{CommonGetters, PositionGetters},
- Container, RootContainer, WindowContainer,
+ models::{
+ Container, Monitor, RootContainer, WindowContainer, Workspace,
+ WorkspaceTarget,
},
- monitors::{commands::add_monitor, Monitor},
- user_config::{BindingModeConfig, UserConfig},
- windows::{commands::manage_window, traits::WindowGetters, WindowState},
- wm_event::WmEvent,
- workspaces::{Workspace, WorkspaceTarget},
+ traits::{CommonGetters, PositionGetters, WindowGetters},
+ user_config::UserConfig,
};
pub struct WmState {
@@ -548,6 +546,8 @@ impl Drop for WmState {
.map(|window| window.native().clone())
.collect::<Vec<_>>();
- run_cleanup(managed_windows);
+ for window in managed_windows {
+ window.cleanup();
+ }
}
}
diff --git a/packages/wm/src/workspaces/mod.rs b/packages/wm/src/workspaces/mod.rs
deleted file mode 100644
index 9ddbb32c..00000000
--- a/packages/wm/src/workspaces/mod.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-pub mod commands;
-mod workspace;
-mod workspace_target;
-
-pub use workspace::*;
-pub use workspace_target::*;
diff --git a/resources/scripts/package.ps1 b/resources/scripts/package.ps1
index 588053f5..5e6e8b36 100644
--- a/resources/scripts/package.ps1
+++ b/resources/scripts/package.ps1
@@ -81,22 +81,14 @@ function BuildExes() {
$outDir = if ($target -eq "x86_64-pc-windows-msvc") { "out/x64" } else { "out/arm64" }
$sourceDir = "target/$target/release"
- Write-Output "Creating output directories for executables"
- New-Item -ItemType Directory -Force -Path "$outDir/noconsole", "$outDir/console"
-
- Write-Output "Building for $target (windows subsystem)"
- cargo build --locked --release --target $target --features no_console,ui_access
- Move-Item -Force -Path "$sourceDir/glazewm.exe", "$sourceDir/glazewm-watcher.exe" -Destination "$outDir/noconsole"
-
- Write-Output "Building for $target (console subsystem)"
+ Write-Output "Building for $target"
cargo build --locked --release --target $target --features ui_access
- Move-Item -Force -Path "$sourceDir/glazewm.exe", "$sourceDir/glazewm-watcher.exe" -Destination "$outDir/console"
+ Move-Item -Force -Path "$sourceDir/glazewm.exe", "$sourceDir/glazewm-cli.exe", "$sourceDir/glazewm-watcher.exe" -Destination $outDir
SignFiles @(
- "$outDir/noconsole/glazewm.exe",
- "$outDir/noconsole/glazewm-watcher.exe",
- "$outDir/console/glazewm.exe",
- "$outDir/console/glazewm-watcher.exe"
+ "$outDir/glazewm.exe",
+ "$outDir/glazewm-cli.exe",
+ "$outDir/glazewm-watcher.exe"
)
}
}
diff --git a/resources/wix/standalone.wxs b/resources/wix/standalone.wxs
index b52a53ea..c0a29800 100644
--- a/resources/wix/standalone.wxs
+++ b/resources/wix/standalone.wxs
@@ -52,17 +52,16 @@
/>
</Component>
- <!-- Add main executable + watcher (windows subsystem). -->
+ <!-- Add main + watcher executable. -->
<Component Id="Custom_InstallRootFiles" Guid="73752F94-6589-4C7B-ABED-39D655A19714">
- <File Id="Custom_RootExe" Source="$(var.EXE_DIR)/noconsole/glazewm.exe" KeyPath="yes" />
- <File Id="Custom_RootWatcherExe" Source="$(var.EXE_DIR)/noconsole/glazewm-watcher.exe" />
+ <File Id="Custom_RootExe" Source="$(var.EXE_DIR)/glazewm.exe" KeyPath="yes" />
+ <File Id="Custom_RootWatcherExe" Source="$(var.EXE_DIR)/glazewm-watcher.exe" />
</Component>
- <!-- Add main executable + watcher (console subsystem). -->
+ <!-- Add CLI executable. -->
<Directory Id="Custom_CliDir" Name="cli">
<Component Id="Custom_InstallCliFiles" Guid="916284d8-100c-4f37-8d8c-2722b01cb3dd">
- <File Id="Custom_CliExe" Source="$(var.EXE_DIR)/console/glazewm.exe" KeyPath="yes" />
- <File Id="Custom_CliWatcherExe" Source="$(var.EXE_DIR)/console/glazewm-watcher.exe" />
+ <File Id="Custom_CliExe" Source="$(var.EXE_DIR)/glazewm-cli.exe" Name="glazewm.exe" KeyPath="yes" />
</Component>
</Directory>
</Directory>