Skip to content

Commit

Permalink
Separate function functions for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamMaoMao committed Nov 7, 2024
1 parent 56de6b5 commit 8e646c3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
22 changes: 11 additions & 11 deletions packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ use crate::{
commands::{
cycle_focus, disable_binding_mode, enable_binding_mode,
reload_config, shell_exec,
}, Direction, LengthValue, Rect, RectDelta, TilingDirection
}, Direction, LengthValue, RectDelta, TilingDirection
},
containers::{
commands::{
focus_in_direction, set_tiling_direction, toggle_tiling_direction,
},
traits::{CommonGetters, PositionGetters},
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
ignore_window, move_window_in_direction, move_window_to_workspace, resize_window, set_floating_placement_position, set_floating_placement_size, set_window_position, set_window_size, update_window_state
},
traits::WindowGetters,
WindowState,
Expand Down Expand Up @@ -475,22 +475,22 @@ impl InvokeCommand {
&config.value.window_behavior.state_defaults.floating;
let is_centered =
centered.unwrap_or(floating_defaults.centered);

if width.is_some() || height.is_some() {
set_window_size(window.clone(),
set_floating_placement_size(
window.clone(),
width.clone(),
height.clone(),
state)?;
height.clone())?;
}

if is_centered || x_pos.is_some() || y_pos.is_some() {
set_window_position(
set_floating_placement_position(
window.clone(),
is_centered,
x_pos.clone(),
y_pos.clone(), state)?;
y_pos.clone())?;
}

update_window_state(
window.clone(),
WindowState::Floating(FloatingStateConfig {
Expand Down
35 changes: 26 additions & 9 deletions packages/wm/src/windows/commands/set_window_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,29 @@ fn set_floating_window_position(
target_y_pos: Option<LengthValue>,
state: &mut WmState,
) -> anyhow::Result<()> {
let window_rect = window.to_rect()?;
let window_container = window.as_window_container()?;

set_floating_placement_position(
window_container,
centered,
target_x_pos,
target_y_pos)?;

state
.pending_sync
.containers_to_redraw
.push(window.clone().into());

Ok(())
}

pub fn set_floating_placement_position(
window: WindowContainer,
centered: bool,
target_x_pos: Option<LengthValue>,
target_y_pos: Option<LengthValue>,
) -> anyhow::Result<()> {
let window_rect = window.floating_placement();

match centered {
true => {
Expand All @@ -55,7 +77,8 @@ fn set_floating_window_position(
window.set_floating_placement(
window_rect
.translate_to_center(&workspace.to_rect()?),
)
);
Ok(())
},
false => {
let monitor = window.monitor().context("No monitor")?;
Expand All @@ -75,13 +98,7 @@ fn set_floating_window_position(
window.floating_placement().width(),
window.floating_placement().height(),
));
Ok(())
}
}

state
.pending_sync
.containers_to_redraw
.push(window.clone().into());

Ok(())
}
29 changes: 22 additions & 7 deletions packages/wm/src/windows/commands/set_window_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
WindowContainer,
},
windows::{
traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState,
traits::WindowGetters, NonTilingWindow, TilingWindow, WindowState
},
wm_state::WmState,
};
Expand Down Expand Up @@ -108,6 +108,26 @@ fn set_floating_window_size(
target_width: Option<LengthValue>,
target_height: Option<LengthValue>,
state: &mut WmState,
) -> anyhow::Result<()> {
let window_container = window.as_window_container()?;

set_floating_placement_size(
window_container,
target_width,
target_height)?;

state
.pending_sync
.containers_to_redraw
.push(window.clone().into());

Ok(())
}

pub fn set_floating_placement_size(
window: WindowContainer,
target_width: Option<LengthValue>,
target_height: Option<LengthValue>,
) -> anyhow::Result<()> {
let monitor = window.monitor().context("No monitor")?;
let monitor_rect = monitor.to_rect()?;
Expand Down Expand Up @@ -154,10 +174,5 @@ fn set_floating_window_size(
new_height,
));

state
.pending_sync
.containers_to_redraw
.push(window.clone().into());

Ok(())
}
}

0 comments on commit 8e646c3

Please sign in to comment.