Skip to content

Commit

Permalink
Symmetrical stack layouts (#224)
Browse files Browse the repository at this point in the history
* Implement left_stack layout

This layout is a mirror image of the provided side_stack layout, where
the main window is on the right and the stack is on the left.

* Implement top_stack layout

This layout is a mirror image of the provided bottom_stack layout, where
the main window is on the bottom and the stack is on the top.
  • Loading branch information
beaumccartney authored Jul 2, 2022
1 parent 21c708f commit af84307
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/contrib/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,65 @@ pub fn dwindle(
) -> Vec<ResizeAction> {
dwindle_recurisive(clients, monitor_region, true, 50)
}

/// A simple layout that places the main region at the bottom of the screen and tiles
/// remaining windows in a single row above.
pub fn top_stack(
clients: &[&Client],
_: Option<Xid>,
monitor_region: &Region,
max_main: u32,
ratio: f32,
) -> Vec<ResizeAction> {
let n = clients.len() as u32;

if n <= max_main || max_main == 0 {
return monitor_region
.as_columns(n)
.iter()
.zip(clients)
.map(|(r, c)| (c.id(), Some(*r)))
.collect();
}

let split = ((monitor_region.h as f32) * (1. - ratio)) as u32;
let (stack, main) = monitor_region.split_at_height(split).unwrap();

main.as_columns(max_main)
.into_iter()
.chain(stack.as_columns(n.saturating_sub(max_main)))
.zip(clients)
.map(|(r, c)| (c.id(), Some(r)))
.collect()
}

/// A simple layout that places the main region on the right and tiles remaining
/// windows in a single column to the left.
pub fn left_stack(
clients: &[&Client],
_: Option<Xid>,
monitor_region: &Region,
max_main: u32,
ratio: f32,
) -> Vec<ResizeAction> {
let n = clients.len() as u32;

if n <= max_main || max_main == 0 {
return monitor_region
.as_rows(n)
.iter()
.zip(clients)
.map(|(r, c)| (c.id(), Some(*r)))
.collect();
}

let split = ((monitor_region.w as f32) * (1. - ratio)) as u32;
let (stack, main) = monitor_region.split_at_width(split).unwrap();

main.as_rows(max_main)
.into_iter()
.chain(stack.as_rows(n.saturating_sub(max_main)))
.zip(clients)
.map(|(r, c)| (c.id(), Some(r)))
.collect()
}

0 comments on commit af84307

Please sign in to comment.