diff --git a/src/display_server/x11/testing.rs b/src/display_server/x11/testing.rs index 87afba24..7fdabeb9 100644 --- a/src/display_server/x11/testing.rs +++ b/src/display_server/x11/testing.rs @@ -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)) }, diff --git a/src/layout.rs b/src/layout.rs index f0fe1247..ad628f73 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -71,6 +71,12 @@ pub enum CurrentLayout { /// [layout manager]: TilingLayoutManager pub struct TilingLayout { root: GroupNode, + + x: i32, + y: i32, + + width: u32, + height: u32, } #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] diff --git a/src/layout/implementations.rs b/src/layout/implementations.rs index a70d6598..47e95faa 100644 --- a/src/layout/implementations.rs +++ b/src/layout/implementations.rs @@ -18,11 +18,11 @@ impl CurrentLayout { /// /// [tiled layout]: Self::Tiled #[inline(always)] - pub(crate) fn new_tiled(x: i32, y: i32, width: u32, height: u32) -> Self + pub(crate) fn new_tiled(x: i32, y: i32, width: u32, height: u32, settings: &LayoutSettings) -> Self where Manager: TilingLayoutManager, { - Self::tiled_with_windows::>(x, y, width, height, std::iter::empty()) + Self::tiled_with_windows::>(x, y, width, height, std::iter::empty(), settings) } /// Creates a new [tiled layout] using the given layout `Manager` type parameter containing the @@ -36,13 +36,14 @@ impl CurrentLayout { width: u32, height: u32, windows: Windows, + settings: &LayoutSettings, ) -> Self where Manager: TilingLayoutManager, Windows: IntoIterator, 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))) } @@ -51,11 +52,53 @@ impl CurrentLayout { impl TilingLayout { /// 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 Borrow> for TilingLayout { diff --git a/src/state.rs b/src/state.rs index a32c36de..a91c277e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -96,7 +96,7 @@ impl AquariWm { Manager: layout::TilingLayoutManager, { Self { - layout: CurrentLayout::new_tiled::(x, y, width, height), + layout: CurrentLayout::new_tiled::(x, y, width, height, &settings), settings, windows: HashMap::new(), @@ -131,7 +131,7 @@ impl AquariWm { Manager: layout::TilingLayoutManager, { let mut aquariwm = Self { - layout: CurrentLayout::new_tiled::(x, y, width, height), + layout: CurrentLayout::new_tiled::(x, y, width, height, &settings), settings, windows: HashMap::new(),