wzrd

An ICCCM & EWMH compliant X11 reparenting, dynamic window manager, written in Rust
git clone git://git.deurzen.net/wzrd
Log | Files | Refs | LICENSE

commit 7229b607954e78832f51b81b07a8b641bf203562
parent c6e735be3825c516c1fcd80844c3bf3dc31597e9
Author: deurzen <m.deurzen@tum.de>
Date:   Tue, 16 Mar 2021 13:28:29 +0100

implements prev_layout data copying

Diffstat:
Msrc/core/main.rs | 3++-
Msrc/core/model.rs | 15+++++++++++++--
Msrc/core/workspace.rs | 24+++++++++++++++++++++++-
Msrc/core/zone.rs | 38++++++++++++++++++++++++++++++--------
4 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/src/core/main.rs b/src/core/main.rs @@ -213,7 +213,8 @@ fn init_bindings() -> (MouseBindings, KeyBindings) { "1-S-Right" => do_internal!(change_margin, Edge::Right, Change::Inc), "1-C-S-Right" => do_internal!(change_margin, Edge::Right, Change::Dec), "1-C-S-equal" => do_internal!(reset_margin), - "1-2-C-S-equal" => do_internal!(reset_layout), + "1-2-C-S-l" => do_internal!(copy_prev_layout_data), + "1-2-C-S-equal" => do_internal!(reset_layout_data), // workspace activators "1-Escape" => do_internal!(toggle_workspace), diff --git a/src/core/model.rs b/src/core/model.rs @@ -1606,11 +1606,22 @@ impl<'a> Model<'a> { Ok(()) } - pub fn reset_layout(&mut self) -> Result<(), StateChangeError> { + pub fn copy_prev_layout_data(&mut self) -> Result<(), StateChangeError> { let workspace_index = self.active_workspace(); if let Some(workspace) = self.workspaces.get(workspace_index) { - workspace.reset_layout(&mut self.zone_manager)?; + workspace.copy_prev_layout_data(&mut self.zone_manager)?; + } + + self.apply_layout(workspace_index, true); + Ok(()) + } + + pub fn reset_layout_data(&mut self) -> Result<(), StateChangeError> { + let workspace_index = self.active_workspace(); + + if let Some(workspace) = self.workspaces.get(workspace_index) { + workspace.reset_layout_data(&mut self.zone_manager)?; } self.apply_layout(workspace_index, true); diff --git a/src/core/workspace.rs b/src/core/workspace.rs @@ -436,7 +436,29 @@ impl Workspace { } } - pub fn reset_layout( + pub fn copy_prev_layout_data( + &self, + zone_manager: &mut ZoneManager, + ) -> Result<(), StateChangeError> { + let &id = self + .zones + .active_element() + .ok_or(StateChangeError::EarlyStop)?; + + let prev_data = *zone_manager + .active_prev_data(id) + .ok_or(StateChangeError::EarlyStop)?; + + let data = zone_manager + .active_data_mut(id) + .ok_or(StateChangeError::EarlyStop)?; + + println!("PREV DATA TO DATA {:?}", prev_data); + + Ok(*data = prev_data) + } + + pub fn reset_layout_data( &self, zone_manager: &mut ZoneManager, ) -> Result<(), StateChangeError> { diff --git a/src/core/zone.rs b/src/core/zone.rs @@ -677,22 +677,27 @@ impl Layout { } #[inline] - fn get_config(&self) -> LayoutConfig { + fn config(&self) -> LayoutConfig { self.kind.config() } #[inline] - fn get_data(&self) -> &LayoutData { + fn prev_data(&self) -> &LayoutData { + self.data.get(&self.prev_kind).unwrap() + } + + #[inline] + fn data(&self) -> &LayoutData { self.data.get(&self.kind).unwrap() } #[inline] - fn get_data_mut(&mut self) -> &mut LayoutData { + fn data_mut(&mut self) -> &mut LayoutData { self.data.get_mut(&self.kind).unwrap() } #[inline] - fn get_default_data(&self) -> LayoutData { + fn default_data(&self) -> LayoutData { self.kind.default_data() } @@ -765,7 +770,7 @@ impl Apply for Layout { active_map: Vec<bool>, ) -> (PlacementMethod, Vec<(Disposition, bool)>) { let config = self.kind.config(); - let data = self.get_data(); + let data = self.data(); let region = if config.margin { Self::adjust_for_margin(region, &data.margin) @@ -881,21 +886,28 @@ impl Zone { pub fn default_data(&self) -> Option<LayoutData> { match &self.content { - ZoneContent::Layout(layout, _) => Some(layout.get_default_data()), + ZoneContent::Layout(layout, _) => Some(layout.default_data()), _ => None, } } pub fn data(&self) -> Option<&LayoutData> { match self.content { - ZoneContent::Layout(ref layout, _) => Some(layout.get_data()), + ZoneContent::Layout(ref layout, _) => Some(layout.data()), _ => None, } } pub fn data_mut(&mut self) -> Option<&mut LayoutData> { match self.content { - ZoneContent::Layout(ref mut layout, _) => Some(layout.get_data_mut()), + ZoneContent::Layout(ref mut layout, _) => Some(layout.data_mut()), + _ => None, + } + } + + pub fn prev_data(&self) -> Option<&LayoutData> { + match self.content { + ZoneContent::Layout(ref layout, _) => Some(layout.prev_data()), _ => None, } } @@ -978,6 +990,16 @@ impl ZoneManager { cycle.default_data() } + pub fn active_prev_data( + &mut self, + id: ZoneId, + ) -> Option<&LayoutData> { + let cycle = self.nearest_cycle(id); + let cycle = self.zone_mut(cycle); + + cycle.prev_data() + } + pub fn active_data_mut( &mut self, id: ZoneId,