Skip to content

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

feat: add `toggle_tiling_direction` command; wip `resize_window` command

Lars Berger68358449a820
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
index 0a5dc105..6204ebda 100644
--- a/packages/wm/src/app_command.rs
+++ b/packages/wm/src/app_command.rs
@@ -7,7 +7,9 @@ use tracing::Level;
use crate::{
common::{Direction, LengthValue},
- containers::{traits::CommonGetters, Container},
+ containers::{
+ commands::toggle_tiling_direction, traits::CommonGetters, Container,
+ },
user_config::{FloatingStateConfig, FullscreenStateConfig, UserConfig},
windows::{
commands::{toggle_window_state, update_window_state},
@@ -353,7 +355,9 @@ impl InvokeCommand {
_ => Ok(()),
}
}
- InvokeCommand::ToggleTilingDirection => todo!(),
+ InvokeCommand::ToggleTilingDirection => {
+ toggle_tiling_direction(subject_container, state, config)
+ }
InvokeCommand::WmDisableBindingMode { name } => todo!(),
InvokeCommand::WmExit => todo!(),
InvokeCommand::WmEnableBindingMode { name } => todo!(),
diff --git a/packages/wm/src/common/events/handle_window_hidden.rs b/packages/wm/src/common/events/handle_window_hidden.rs
index 835ff515..4add5aec 100644
--- a/packages/wm/src/common/events/handle_window_hidden.rs
+++ b/packages/wm/src/common/events/handle_window_hidden.rs
@@ -2,7 +2,6 @@ use tracing::info;
use crate::{
common::{platform::NativeWindow, DisplayState},
- user_config::UserConfig,
windows::{commands::unmanage_window, traits::WindowGetters},
wm_state::WmState,
};
@@ -10,7 +9,6 @@ use crate::{
pub fn handle_window_hidden(
native_window: NativeWindow,
state: &mut WmState,
- config: &UserConfig,
) -> anyhow::Result<()> {
let found_window = state.window_from_native(&native_window);
diff --git a/packages/wm/src/common/mod.rs b/packages/wm/src/common/mod.rs
index a859780a..4c160b6d 100644
--- a/packages/wm/src/common/mod.rs
+++ b/packages/wm/src/common/mod.rs
@@ -7,6 +7,7 @@ pub mod platform;
mod point;
mod rect;
mod rect_delta;
+mod resize_dimension;
mod tiling_direction;
mod units;
mod vec_deque_ext;
@@ -17,6 +18,7 @@ pub use focus_mode::*;
pub use point::*;
pub use rect::*;
pub use rect_delta::*;
+pub use resize_dimension::*;
pub use tiling_direction::*;
pub use units::*;
pub use vec_deque_ext::*;
diff --git a/packages/wm/src/common/resize_dimension.rs b/packages/wm/src/common/resize_dimension.rs
new file mode 100644
index 00000000..fc059bb3
--- /dev/null
+++ b/packages/wm/src/common/resize_dimension.rs
@@ -0,0 +1,5 @@
+#[derive(Clone, Debug, PartialEq)]
+pub enum ResizeDimension {
+ Width,
+ Height,
+}
diff --git a/packages/wm/src/containers/commands/exec_process.rs b/packages/wm/src/containers/commands/exec_process.rs
index 259fec66..3c3f5b9b 100644
--- a/packages/wm/src/containers/commands/exec_process.rs
+++ b/packages/wm/src/containers/commands/exec_process.rs
@@ -1,34 +1,37 @@
-use std::process::Command;
-use std::env;
-use anyhow::{Result, Context};
+use anyhow::{Context, Result};
use regex::Regex;
+use std::env;
+use std::process::Command;
pub fn exec_process(process_name: &str, args: &[String]) -> Result<()> {
- // Expand user profile environment variable
- let user_profile = env::var("USERPROFILE")
- .context("Failed to get environment variable for user profile directory")?;
+ // Expand user profile environment variable
+ let user_profile = env::var("USERPROFILE").context(
+ "Failed to get environment variable for user profile directory",
+ )?;
- let re = Regex::new(r"(?i)%userprofile%").unwrap();
+ let re = Regex::new(r"(?i)%userprofile%").unwrap();
- let args: Vec<String> = args.iter().map(|arg| {
- re.replace_all(arg, &user_profile).into_owned()
- }).collect();
+ let args: Vec<String> = args
+ .iter()
+ .map(|arg| re.replace_all(arg, &user_profile).into_owned())
+ .collect();
- let process_name = re.replace_all(&process_name, &user_profile).into_owned();
-
- // Start external process
- let output = Command::new(process_name)
- .args(args) // pass the args vector directly
- .current_dir(env::var("USERPROFILE")
- .context("Failed to get environment variable for user profile directory")?)
- .output()
- .context("Failed to execute command")?;
+ let process_name =
+ re.replace_all(&process_name, &user_profile).into_owned();
- if !output.status.success() {
- eprintln!("Error: {}", String::from_utf8_lossy(&output.stderr));
- return Err(anyhow::anyhow!("Process execution failed"));
- }
+ // Start external process
+ let output = Command::new(process_name)
+ .args(args) // pass the args vector directly
+ .current_dir(env::var("USERPROFILE").context(
+ "Failed to get environment variable for user profile directory",
+ )?)
+ .output()
+ .context("Failed to execute command")?;
- Ok(())
-}
+ if !output.status.success() {
+ error!("Error: {}", String::from_utf8_lossy(&output.stderr));
+ return Err(anyhow::anyhow!("Process execution failed"));
+ }
+ Ok(())
+}
diff --git a/packages/wm/src/containers/commands/flatten_split_container.rs b/packages/wm/src/containers/commands/flatten_split_container.rs
index 1d920033..259b15ba 100644
--- a/packages/wm/src/containers/commands/flatten_split_container.rs
+++ b/packages/wm/src/containers/commands/flatten_split_container.rs
@@ -37,7 +37,6 @@ pub fn flatten_split_container(
let index = split_container.index();
let focus_index = split_container.focus_index();
- let child_focus_order = split_container.borrow_child_focus_order();
// Insert child at its original index in the parent.
for (child_index, child) in updated_children.enumerate() {
@@ -47,7 +46,10 @@ pub fn flatten_split_container(
}
// Insert child at its original focus index in the parent.
- for (child_focus_index, child_id) in child_focus_order.iter().enumerate()
+ for (child_focus_index, child_id) in split_container
+ .borrow_child_focus_order()
+ .iter()
+ .enumerate()
{
parent
.borrow_child_focus_order_mut()
diff --git a/packages/wm/src/containers/commands/mod.rs b/packages/wm/src/containers/commands/mod.rs
index 51e4c308..6ec0b014 100644
--- a/packages/wm/src/containers/commands/mod.rs
+++ b/packages/wm/src/containers/commands/mod.rs
@@ -9,6 +9,7 @@ mod replace_container;
mod resize_tiling_container;
mod set_active_window_border;
mod set_focused_descendant;
+mod toggle_tiling_direction;
pub use attach_container::*;
pub use center_cursor_on_container::*;
@@ -21,3 +22,4 @@ pub use replace_container::*;
pub use resize_tiling_container::*;
pub use set_active_window_border::*;
pub use set_focused_descendant::*;
+pub use toggle_tiling_direction::*;
diff --git a/packages/wm/src/containers/commands/redraw.rs b/packages/wm/src/containers/commands/redraw.rs
index be130b74..87da161a 100644
--- a/packages/wm/src/containers/commands/redraw.rs
+++ b/packages/wm/src/containers/commands/redraw.rs
@@ -9,9 +9,8 @@ use crate::{
pub fn redraw(state: &mut WmState) -> anyhow::Result<()> {
for window in &state.windows_to_redraw() {
- let workspace = window
- .parent_workspace()
- .context("Window has no workspace.")?;
+ let workspace =
+ window.workspace().context("Window has no workspace.")?;
// Transition display state depending on whether window will be
// shown or hidden.
diff --git a/packages/wm/src/containers/commands/resize_tiling_container.rs b/packages/wm/src/containers/commands/resize_tiling_container.rs
index 06ac10c2..8c0ee366 100644
--- a/packages/wm/src/containers/commands/resize_tiling_container.rs
+++ b/packages/wm/src/containers/commands/resize_tiling_container.rs
@@ -14,29 +14,26 @@ pub fn resize_tiling_container(
// Ignore cases where the container is the only child.
if tiling_siblings.is_empty() {
+ container_to_resize.set_tiling_size(1.);
return;
}
- // Get available tiling size amongst siblings.
let available_size = available_size(&tiling_siblings);
// Prevent the container from being smaller than the minimum size, and
// larger than the space available from sibling containers.
- let clamped_target_size = target_size
- .max(MIN_TILING_SIZE - container_to_resize.tiling_size())
- .min(available_size);
+ let clamped_target_size =
+ target_size.clamp(MIN_TILING_SIZE, available_size);
- // Resize the container.
- container_to_resize.set_tiling_size(
- container_to_resize.tiling_size() + clamped_target_size,
- );
+ let size_delta = clamped_target_size - container_to_resize.tiling_size();
+ container_to_resize.set_tiling_size(clamped_target_size);
// Distribute the available tiling size amongst its siblings.
for sibling in &tiling_siblings {
let sibling_size_delta = sibling_size_delta(
&sibling,
tiling_siblings.len(),
- clamped_target_size,
+ size_delta,
available_size,
);
@@ -44,16 +41,18 @@ pub fn resize_tiling_container(
}
}
+/// Gets available tiling size amongst siblings.
fn available_size(containers: &Vec<TilingContainer>) -> f32 {
containers.iter().fold(0.0, |sum, container| {
sum + container.tiling_size() - MIN_TILING_SIZE
})
}
+/// Gets the size delta for a sibling of the resized container.
fn sibling_size_delta(
sibling_to_resize: &TilingContainer,
sibling_count: usize,
- target_size: f32,
+ size_delta: f32,
available_size: f32,
) -> f32 {
let con_available_size =
@@ -62,11 +61,11 @@ fn sibling_size_delta(
// Get percentage of resize that affects this container. The available
// tiling size here can be 0 when the main container to resize is shrunk
// from the max tiling size.
- let resize_factor = if available_size == 0.0 || target_size < 0.0 {
+ let resize_factor = if available_size == 0.0 || size_delta < 0.0 {
1.0 / sibling_count as f32
} else {
con_available_size / available_size
};
- resize_factor * target_size
+ resize_factor * size_delta
}
diff --git a/packages/wm/src/containers/commands/toggle_tiling_direction.rs b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
new file mode 100644
index 00000000..f2d3ec4f
--- /dev/null
+++ b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
@@ -0,0 +1,127 @@
+use anyhow::Context;
+use uuid::Uuid;
+
+use crate::{
+ common::TilingDirection,
+ containers::{
+ traits::{CommonGetters, TilingDirectionGetters, TilingSizeGetters},
+ Container, DirectionContainer, SplitContainer,
+ },
+ user_config::UserConfig,
+ windows::TilingWindow,
+ wm_event::WmEvent,
+ wm_state::WmState,
+ workspaces::Workspace,
+};
+
+use super::{
+ attach_container, detach_container, flatten_split_container,
+ replace_container,
+};
+
+pub fn toggle_tiling_direction(
+ container: Container,
+ state: &mut WmState,
+ config: &UserConfig,
+) -> anyhow::Result<()> {
+ let (modified_id, new_tiling_direction) = match container {
+ Container::TilingWindow(tiling_window) => {
+ toggle_window_direction(tiling_window, state, config)
+ }
+ Container::Workspace(workspace) => {
+ toggle_workspace_direction(workspace, state)
+ }
+ // Can only toggle tiling direction from a tiling window or workspace.
+ _ => return Ok(()),
+ }?;
+
+ state.emit_event(WmEvent::TilingDirectionChanged {
+ modified_id,
+ new_tiling_direction,
+ });
+
+ Ok(())
+}
+
+fn toggle_window_direction(
+ tiling_window: TilingWindow,
+ state: &mut WmState,
+ config: &UserConfig,
+) -> anyhow::Result<(Uuid, TilingDirection)> {
+ let parent = tiling_window
+ .direction_container()
+ .context("No direction container.")?;
+
+ // If the window is an only child, then either change the tiling
+ // direction of its parent workspace or flatten its parent split
+ // container.
+ if !tiling_window.has_siblings() {
+ match parent {
+ DirectionContainer::Workspace(workspace) => {
+ return toggle_workspace_direction(workspace, state);
+ }
+ DirectionContainer::Split(split_container) => {
+ flatten_split_container(split_container.clone())?;
+
+ return Ok((
+ split_container.id(),
+ split_container.tiling_direction().inverse(),
+ ));
+ }
+ };
+ }
+
+ // Create a new split container to wrap the window.
+ let split_container = SplitContainer::new(
+ parent.tiling_direction().inverse(),
+ config.value.gaps.inner_gap.clone(),
+ );
+
+ // Replace the window with the wrapping split container. The window
+ // has to be attached to the split container after the replacement.
+ replace_container(
+ split_container.clone().into(),
+ parent.clone().into(),
+ tiling_window.index(),
+ )?;
+
+ // Add the window as a child to the new split container.
+ attach_container(
+ &tiling_window.clone().into(),
+ &split_container.clone().into(),
+ None,
+ )?;
+
+ Ok((split_container.id(), split_container.tiling_direction()))
+}
+
+fn toggle_workspace_direction(
+ workspace: Workspace,
+ state: &mut WmState,
+) -> anyhow::Result<(Uuid, TilingDirection)> {
+ workspace.set_tiling_direction(workspace.tiling_direction().inverse());
+
+ let inverse_split_containers = workspace
+ .children()
+ .iter()
+ .filter_map(|child| match child.as_split() {
+ Some(split)
+ if split.tiling_direction() == workspace.tiling_direction() =>
+ {
+ Some(split)
+ }
+ _ => None,
+ })
+ .cloned()
+ .collect::<Vec<_>>();
+
+ // Flatten any top-level split containers with the same tiling
+ // direction as the workspace.
+ for split_container in inverse_split_containers {
+ flatten_split_container(split_container)?;
+ }
+
+ state.add_container_to_redraw(workspace.clone().into());
+
+ Ok((workspace.id(), workspace.tiling_direction()))
+}
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs
index 4e36e582..1dc27fad 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/containers/container.rs
@@ -39,6 +39,15 @@ impl From<WindowContainer> for Container {
}
}
+impl From<DirectionContainer> for Container {
+ fn from(direction_container: DirectionContainer) -> Self {
+ match direction_container {
+ DirectionContainer::Split(c) => Container::Split(c),
+ DirectionContainer::Workspace(c) => Container::Workspace(c),
+ }
+ }
+}
+
impl PartialEq for Container {
fn eq(&self, other: &Self) -> bool {
self.id() == other.id()
diff --git a/packages/wm/src/containers/traits/common_getters.rs b/packages/wm/src/containers/traits/common_getters.rs
index 097d43ee..413d8db6 100644
--- a/packages/wm/src/containers/traits/common_getters.rs
+++ b/packages/wm/src/containers/traits/common_getters.rs
@@ -64,6 +64,11 @@ pub trait CommonGetters {
!self.borrow_children().is_empty()
}
+ /// Whether this container has any siblings.
+ fn has_siblings(&self) -> bool {
+ self.siblings().count() > 0
+ }
+
/// Whether this container is detached from the tree (i.e. it does not
/// have a parent).
fn is_detached(&self) -> bool {
@@ -184,19 +189,28 @@ pub trait CommonGetters {
}
}
- fn parent_workspace(&self) -> Option<Workspace> {
+ /// Workspace that this container belongs to.
+ ///
+ /// Note that this might return the container itself.
+ fn workspace(&self) -> Option<Workspace> {
self
.self_and_ancestors()
.find_map(|container| container.as_workspace().cloned())
}
- fn parent_monitor(&self) -> Option<Monitor> {
+ /// Monitor that this container belongs to.
+ ///
+ /// Note that this might return the container itself.
+ fn monitor(&self) -> Option<Monitor> {
self
.self_and_ancestors()
.find_map(|container| container.as_monitor().cloned())
}
- fn parent_direction_container(&self) -> Option<DirectionContainer> {
+ /// Nearest direction container (i.e. split container or workspace).
+ ///
+ /// Note that this might return the container itself.
+ fn direction_container(&self) -> Option<DirectionContainer> {
self
.self_and_ancestors()
.find_map(|container| container.try_into().ok())
diff --git a/packages/wm/src/containers/traits/position_getters.rs b/packages/wm/src/containers/traits/position_getters.rs
index 3d9a9710..da061957 100644
--- a/packages/wm/src/containers/traits/position_getters.rs
+++ b/packages/wm/src/containers/traits/position_getters.rs
@@ -46,10 +46,7 @@ macro_rules! impl_position_getters_as_resizable {
TilingDirection::Vertical => parent.width(),
TilingDirection::Horizontal => {
let inner_gap = self.inner_gap().to_pixels(
- self
- .parent_monitor()
- .context("No parent monitor.")?
- .width()?,
+ self.monitor().context("No parent monitor.")?.width()?,
);
let available_width = parent.width()?
@@ -70,10 +67,7 @@ macro_rules! impl_position_getters_as_resizable {
TilingDirection::Horizontal => parent.height(),
TilingDirection::Vertical => {
let inner_gap = self.inner_gap().to_pixels(
- self
- .parent_monitor()
- .context("No parent monitor.")?
- .width()?,
+ self.monitor().context("No parent monitor.")?.width()?,
);
let available_height = parent.height()?
@@ -102,10 +96,7 @@ macro_rules! impl_position_getters_as_resizable {
}
let inner_gap = self.inner_gap().to_pixels(
- self
- .parent_monitor()
- .context("No parent monitor.")?
- .width()?,
+ self.monitor().context("No parent monitor.")?.width()?,
);
Ok(prev_sibling.x()? + prev_sibling.width()? + inner_gap)
@@ -131,10 +122,7 @@ macro_rules! impl_position_getters_as_resizable {
}
let inner_gap = self.inner_gap().to_pixels(
- self
- .parent_monitor()
- .context("No parent monitor.")?
- .width()?,
+ self.monitor().context("No parent monitor.")?.width()?,
);
Ok(prev_sibling.y()? + prev_sibling.height()? + inner_gap)
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 03251463..d6bbe91f 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -43,7 +43,7 @@ async fn main() {
);
if let Err(err) = start_wm(config_path).await {
- eprintln!("Failed to start GlazeWM: {}", err);
+ error!("Failed to start GlazeWM: {}", err);
}
}
_ => todo!(),
diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rs
index 7fe27b7e..8a54c13b 100644
--- a/packages/wm/src/monitors/monitor.rs
+++ b/packages/wm/src/monitors/monitor.rs
@@ -69,8 +69,7 @@ impl Monitor {
&self,
other: &Container,
) -> anyhow::Result<bool> {
- let other_monitor =
- other.parent_monitor().context("No parent monitor.")?;
+ let other_monitor = other.monitor().context("No parent monitor.")?;
Ok(self.native().dpi != other_monitor.native().dpi)
}
diff --git a/packages/wm/src/windows/commands/manage_window.rs b/packages/wm/src/windows/commands/manage_window.rs
index 428590e1..f8ad78a3 100644
--- a/packages/wm/src/windows/commands/manage_window.rs
+++ b/packages/wm/src/windows/commands/manage_window.rs
@@ -77,9 +77,8 @@ fn create_window(
None => insertion_target(state)?,
};
- let target_workspace = target_parent
- .parent_workspace()
- .context("No target workspace.")?;
+ let target_workspace =
+ target_parent.workspace().context("No target workspace.")?;
let nearest_monitor = state
.nearest_monitor(&native_window)
diff --git a/packages/wm/src/windows/commands/mod.rs b/packages/wm/src/windows/commands/mod.rs
index e1f0022b..f197b98f 100644
--- a/packages/wm/src/windows/commands/mod.rs
+++ b/packages/wm/src/windows/commands/mod.rs
@@ -1,9 +1,11 @@
mod manage_window;
+mod resize_window;
mod toggle_window_state;
mod unmanage_window;
mod update_window_state;
pub use manage_window::*;
+pub use resize_window::*;
pub use toggle_window_state::*;
pub use unmanage_window::*;
pub use update_window_state::*;
diff --git a/packages/wm/src/windows/commands/resize_window.rs b/packages/wm/src/windows/commands/resize_window.rs
new file mode 100644
index 00000000..8ba7dd71
--- /dev/null
+++ b/packages/wm/src/windows/commands/resize_window.rs
@@ -0,0 +1,159 @@
+use anyhow::Context;
+
+use crate::{
+ common::{LengthValue, Rect, ResizeDimension, TilingDirection},
+ containers::{
+ commands::resize_tiling_container,
+ traits::{CommonGetters, PositionGetters, TilingDirectionGetters},
+ Container, WindowContainer,
+ },
+ user_config::UserConfig,
+ windows::{
+ traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState,
+ },
+ wm_state::WmState,
+};
+
+const MIN_FLOATING_WIDTH: i32 = 250;
+const MIN_FLOATING_HEIGHT: i32 = 140;
+
+pub fn resize_window(
+ window: WindowContainer,
+ resize_dimension: ResizeDimension,
+ resize_amount: LengthValue,
+ state: &mut WmState,
+ config: &UserConfig,
+) -> anyhow::Result<()> {
+ match window {
+ WindowContainer::TilingWindow(window) => resize_tiling_window(
+ window,
+ resize_dimension,
+ resize_amount,
+ state,
+ config,
+ ),
+ WindowContainer::NonTilingWindow(window) => {
+ if matches!(window.state(), WindowState::Floating(_)) {
+ resize_floating_window(
+ window,
+ resize_dimension,
+ resize_amount,
+ state,
+ config,
+ )?;
+ }
+
+ Ok(())
+ }
+ }
+}
+
+fn resize_tiling_window(
+ window: TilingWindow,
+ resize_dimension: ResizeDimension,
+ resize_amount: LengthValue,
+ state: &mut WmState,
+ config: &UserConfig,
+) -> anyhow::Result<()> {
+ // When resizing a tiling window, the container to resize can actually be
+ // an ancestor split container.
+ if let Some(container_to_resize) =
+ container_to_resize(window.clone(), resize_dimension)?
+ {
+ // Convert to a percentage to increase/decrease the window size by.
+ // let tiling_size_delta =
+ // resize_amount.to_percentage(container_to_resize.tiling_size());
+
+ // resize_tiling_container(container_to_resize, tiling_size_delta);
+
+ // // TODO: Return early if `clamped_resize_percentage` is 0 to avoid
+ // // unnecessary redraws.
+ // state.add_container_to_redraw(
+ // container_to_resize.parent().context("No parent.")?,
+ // );
+ }
+
+ Ok(())
+}
+
+fn container_to_resize(
+ window: TilingWindow,
+ resize_dimension: ResizeDimension,
+) -> anyhow::Result<Option<Container>> {
+ let parent = window.direction_container().context("No parent.")?;
+ let tiling_direction = parent.tiling_direction();
+
+ // Whether the resize is in the inverse of its tiling direction.
+ let is_inverse_resize = match tiling_direction {
+ TilingDirection::Horizontal => {
+ resize_dimension == ResizeDimension::Height
+ }
+ TilingDirection::Vertical => {
+ resize_dimension == ResizeDimension::Width
+ }
+ };
+
+ let container_to_resize = match is_inverse_resize {
+ true => parent.into(),
+ false => {
+ let grandparent = parent.parent().context("No grandparent.")?;
+
+ // Resize grandparent in layouts like H[1 V[2 H[3]]], where container
+ // 3 is resized horizontally.
+ if window.tiling_siblings().count() == 0 && grandparent.is_split() {
+ grandparent
+ } else {
+ window.into()
+ }
+ }
+ };
+
+ // Ignore cases where the container to resize is a workspace or the only
+ // child.
+ if container_to_resize.tiling_siblings().count() > 0
+ || container_to_resize.is_workspace()
+ {
+ return Ok(None);
+ }
+
+ Ok(Some(container_to_resize))
+}
+
+fn resize_floating_window(
+ window: NonTilingWindow,
+ resize_dimension: ResizeDimension,
+ resize_amount: LengthValue,
+ state: &mut WmState,
+ config: &UserConfig,
+) -> anyhow::Result<()> {
+ let monitor = window.monitor().context("No monitor")?;
+ let amount = resize_amount.to_pixels(monitor.width()?);
+
+ let mut width = window.floating_placement().width();
+ let mut height = window.floating_placement().height();
+
+ match resize_dimension {
+ ResizeDimension::Width => width += amount,
+ ResizeDimension::Height => height += amount,
+ }
+
+ // Prevent resize from making the window smaller than minimum dimensions.
+ // Always allow the size to be increased, even if the window would still
+ // be within minimum dimension values.
+ if amount < 0
+ && (width < MIN_FLOATING_WIDTH || height < MIN_FLOATING_HEIGHT)
+ {
+ return Ok(());
+ }
+
+ window.set_floating_placement(Rect::from_xy(
+ window.floating_placement().x(),
+ window.floating_placement().y(),
+ width,
+ height,
+ ));
+
+ state.add_container_to_redraw(window.clone().into());
+
+ Ok(())
+}
diff --git a/packages/wm/src/windows/commands/update_window_state.rs b/packages/wm/src/windows/commands/update_window_state.rs
index 836cde05..32bd3dc5 100644
--- a/packages/wm/src/windows/commands/update_window_state.rs
+++ b/packages/wm/src/windows/commands/update_window_state.rs
@@ -37,7 +37,7 @@ fn set_tiling(
) -> anyhow::Result<()> {
if let WindowContainer::NonTilingWindow(window) = window {
let workspace = window
- .parent_workspace()
+ .workspace()
.context("Window has no workspace.")?;
// Get the position in the tree to insert the new tiling window. This
@@ -90,7 +90,7 @@ fn set_non_tiling(
}
WindowContainer::TilingWindow(window) => {
let workspace = window
- .parent_workspace()
+ .workspace()
.context("Window has no workspace.")?;
move_container_within_tree(
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 6f318074..6215de2a 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -71,7 +71,7 @@ impl WindowManager {
handle_window_focused(window, &mut state, config)
}
PlatformEvent::WindowHidden(window) => {
- handle_window_hidden(window, &mut state, config)
+ handle_window_hidden(window, &mut state)
}
PlatformEvent::WindowLocationChanged(window) => {
handle_window_location_changed(window, &mut state, config)
diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rs
index 7497c3d5..d21ba344 100644
--- a/packages/wm/src/wm_event.rs
+++ b/packages/wm/src/wm_event.rs
@@ -30,6 +30,7 @@ pub enum WmEvent {
focused_container: Container,
},
TilingDirectionChanged {
+ modified_id: Uuid,
new_tiling_direction: TilingDirection,
},
UserConfigReloaded,
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index 56c5d016..66add6b6 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -231,7 +231,7 @@ impl WmState {
}
// Get descendant focus order excluding the removed container.
- let workspace = removed_window.parent_workspace()?;
+ let workspace = removed_window.workspace()?;
let descendant_focus_order = workspace
.descendant_focus_order()
.filter(|descendant| descendant.id() != removed_window.id())