-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new
position
command; allow size and position to be set w…
…ith `set-floating` command (#817)
- Loading branch information
1 parent
bc7839a
commit 04e6c2f
Showing
4 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use anyhow::Context; | ||
|
||
use crate::{ | ||
common::Rect, | ||
containers::{ | ||
traits::{CommonGetters, PositionGetters}, | ||
WindowContainer, | ||
}, | ||
windows::{traits::WindowGetters, WindowState}, | ||
wm_state::WmState, | ||
}; | ||
|
||
pub fn set_window_position( | ||
window: WindowContainer, | ||
target_x_pos: Option<i32>, | ||
target_y_pos: Option<i32>, | ||
state: &mut WmState, | ||
) -> anyhow::Result<()> { | ||
if matches!(window.state(), WindowState::Floating(_)) { | ||
let window_rect = window.floating_placement(); | ||
let new_x_pos = target_x_pos.unwrap_or(window_rect.x()); | ||
let new_y_pos = target_y_pos.unwrap_or(window_rect.y()); | ||
window.set_floating_placement(Rect::from_xy( | ||
new_x_pos, | ||
new_y_pos, | ||
window.floating_placement().width(), | ||
window.floating_placement().height(), | ||
)); | ||
|
||
state | ||
.pending_sync | ||
.containers_to_redraw | ||
.push(window.clone().into()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn set_window_position_to_center( | ||
window: WindowContainer, | ||
state: &mut WmState, | ||
) -> anyhow::Result<()> { | ||
if matches!(window.state(), WindowState::Floating(_)) { | ||
let window_rect = window.floating_placement(); | ||
let workspace = window.workspace().context("no workspace find.")?; | ||
window.set_floating_placement( | ||
window_rect.translate_to_center(&workspace.to_rect()?), | ||
); | ||
|
||
state | ||
.pending_sync | ||
.containers_to_redraw | ||
.push(window.clone().into()); | ||
} | ||
|
||
Ok(()) | ||
} |