Skip to content

Commit

Permalink
layouts: add padding to tiling layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Antikyth committed Nov 22, 2023
1 parent a14735e commit 744374f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/display_server/x11/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ impl Xephyr {
// Sleep for 1s to wait for Xephyr to launch. Not ideal.
thread::sleep(Duration::from_secs(1));

// Spawn the `picom` compositor, if possible.
let _ = process::Command::new("picom").spawn();

Ok(Self(process))
},

Expand Down
6 changes: 6 additions & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub enum CurrentLayout<Window> {
/// [layout manager]: TilingLayoutManager
pub struct TilingLayout<Window> {
root: GroupNode<Window>,

x: i32,
y: i32,

width: u32,
height: u32,
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
Expand Down
53 changes: 48 additions & 5 deletions src/layout/implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ impl<Window> CurrentLayout<Window> {
///
/// [tiled layout]: Self::Tiled
#[inline(always)]
pub(crate) fn new_tiled<Manager>(x: i32, y: i32, width: u32, height: u32) -> Self
pub(crate) fn new_tiled<Manager>(x: i32, y: i32, width: u32, height: u32, settings: &LayoutSettings) -> Self
where
Manager: TilingLayoutManager<Window>,
{
Self::tiled_with_windows::<Manager, std::iter::Empty<Window>>(x, y, width, height, std::iter::empty())
Self::tiled_with_windows::<Manager, std::iter::Empty<Window>>(x, y, width, height, std::iter::empty(), settings)
}

/// Creates a new [tiled layout] using the given layout `Manager` type parameter containing the
Expand All @@ -36,13 +36,14 @@ impl<Window> CurrentLayout<Window> {
width: u32,
height: u32,
windows: Windows,
settings: &LayoutSettings,
) -> Self
where
Manager: TilingLayoutManager<Window>,
Windows: IntoIterator<Item = Window>,
Windows::IntoIter: ExactSizeIterator,
{
let layout = TilingLayout::new(Manager::orientation(), x, y, width, height);
let layout = TilingLayout::new(Manager::orientation(), x, y, width, height, settings);

Self::Tiled(Box::new(Manager::init(layout, windows)))
}
Expand All @@ -51,11 +52,53 @@ impl<Window> CurrentLayout<Window> {
impl<Window> TilingLayout<Window> {
/// Creates an empty layout of the given `orientation`.
#[inline]
pub(crate) const fn new(orientation: Orientation, x: i32, y: i32, width: u32, height: u32) -> Self {
pub(crate) const fn new(
orientation: Orientation,
x: i32,
y: i32,
width: u32,
height: u32,
settings: &LayoutSettings,
) -> Self {
let padding = settings.window_gap;

Self {
root: GroupNode::with(orientation, x, y, width, height),
x,
y,

width,
height,

root: GroupNode::with(
orientation,
x + (padding as i32),
y + (padding as i32),
width - (2 * padding),
height - (2 * padding),
),
}
}

/// Updates the tiling layout with the given `settings`.
///
/// Please note that for the nodes in the layout to be updated, [state::AquariWm::apply_changes]
#[cfg_attr(feature = "async", doc = "or [state::AquariWm::apply_changes_async]")]
/// must be called.
///
/// [state::AquariWm::apply]: crate::state::AquariWm::apply_changes
#[cfg_attr(
feature = "async",
doc = "[state::AquariWm::apply_changes_async]: crate::state::AquariWm::apply_changes_async"
)]
pub(crate) fn update_settings(&mut self, settings: &LayoutSettings) {
let padding = settings.window_gap;

self.root.new_x = Some(self.x + (padding as i32));
self.root.new_y = Some(self.y + (padding as i32));

self.root.new_width = Some(self.width - (2 * padding));
self.root.new_height = Some(self.height - (2 * padding));
}
}

impl<Window> Borrow<GroupNode<Window>> for TilingLayout<Window> {
Expand Down
4 changes: 2 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<Window: Eq + Hash + Clone> AquariWm<Window> {
Manager: layout::TilingLayoutManager<Window>,
{
Self {
layout: CurrentLayout::new_tiled::<Manager>(x, y, width, height),
layout: CurrentLayout::new_tiled::<Manager>(x, y, width, height, &settings),
settings,

windows: HashMap::new(),
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<Window: Eq + Hash + Clone> AquariWm<Window> {
Manager: layout::TilingLayoutManager<Window>,
{
let mut aquariwm = Self {
layout: CurrentLayout::new_tiled::<Manager>(x, y, width, height),
layout: CurrentLayout::new_tiled::<Manager>(x, y, width, height, &settings),
settings,

windows: HashMap::new(),
Expand Down

0 comments on commit 744374f

Please sign in to comment.