mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-18 17:56:56 +02:00
feat(wm): add grid layout
Based on the Grid layout on LeftWM Co-authored-by: LGUG2Z <LGUG2Z@fastmail.com>
This commit is contained in:
@@ -131,6 +131,42 @@ impl Arrangement for DefaultLayout {
|
||||
layouts
|
||||
}
|
||||
Self::UltrawideVerticalStack => ultrawide(area, len, layout_flip, resize_dimensions),
|
||||
Self::Grid => {
|
||||
// Shamelessly lifted from LeftWM
|
||||
// https://github.com/leftwm/leftwm/blob/18675067b8450e520ef75db2ebbb0d973aa1199e/leftwm-core/src/layouts/grid_horizontal.rs
|
||||
let mut layouts: Vec<Rect> = vec![];
|
||||
layouts.resize(len, Rect::default());
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
let len = len as i32;
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
let num_cols = (len as f32).sqrt().ceil() as i32;
|
||||
let mut iter = layouts.iter_mut().enumerate().peekable();
|
||||
|
||||
for col in 0..num_cols {
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
let iter_peek = iter.peek().map(|x| x.0).unwrap_or_default() as i32;
|
||||
let remaining_windows = len - iter_peek;
|
||||
let remaining_columns = num_cols - col;
|
||||
let num_rows_in_this_col = remaining_windows / remaining_columns;
|
||||
|
||||
let win_height = area.bottom / num_rows_in_this_col;
|
||||
let win_width = area.right / num_cols;
|
||||
|
||||
for row in 0..num_rows_in_this_col {
|
||||
if let Some((_idx, win)) = iter.next() {
|
||||
win.bottom = win_height;
|
||||
win.right = win_width;
|
||||
|
||||
win.left = area.left + win_width * col;
|
||||
win.top = area.top + win_height * row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layouts
|
||||
}
|
||||
};
|
||||
|
||||
dimensions
|
||||
|
||||
Reference in New Issue
Block a user