refactor(grid): use matches! for early returns

This commit is contained in:
Javier Portillo
2024-02-20 14:34:41 -06:00
committed by جاد
parent d33df04f38
commit 2c156e9a99
+18 -24
View File
@@ -1484,19 +1484,15 @@ impl WindowManager {
pub fn promote_container_to_front(&mut self) -> Result<()> { pub fn promote_container_to_front(&mut self) -> Result<()> {
self.handle_unmanaged_window_behaviour()?; self.handle_unmanaged_window_behaviour()?;
tracing::info!("promoting container");
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
// NoOp on Grid layout if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) {
match workspace.layout() { tracing::debug!("ignoring promote command for grid layout");
Layout::Default(layout) => match layout { return Ok(())
DefaultLayout::Grid => return Ok(()),
_ => (),
},
_ => (),
} }
tracing::info!("promoting container");
workspace.promote_container()?; workspace.promote_container()?;
self.update_focused_workspace(self.mouse_follows_focus) self.update_focused_workspace(self.mouse_follows_focus)
} }
@@ -1505,15 +1501,17 @@ impl WindowManager {
pub fn promote_focus_to_front(&mut self) -> Result<()> { pub fn promote_focus_to_front(&mut self) -> Result<()> {
self.handle_unmanaged_window_behaviour()?; self.handle_unmanaged_window_behaviour()?;
let workspace = self.focused_workspace_mut()?;
if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) {
tracing::info!("ignoring promote focus command for grid layout");
return Ok(())
}
tracing::info!("promoting focus"); tracing::info!("promoting focus");
let workspace = self.focused_workspace_mut()?;
let target_idx = match workspace.layout() { let target_idx = match workspace.layout() {
Layout::Default(layout) => match layout { Layout::Default(_) => 0,
// NoOp on Grid layout
DefaultLayout::Grid => return Ok(()),
_ => 0,
},
Layout::Custom(custom) => custom Layout::Custom(custom) => custom
.first_container_idx(custom.primary_idx().map_or(0, |primary_idx| primary_idx)), .first_container_idx(custom.primary_idx().map_or(0, |primary_idx| primary_idx)),
}; };
@@ -1658,19 +1656,15 @@ impl WindowManager {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn flip_layout(&mut self, layout_flip: Axis) -> Result<()> { pub fn flip_layout(&mut self, layout_flip: Axis) -> Result<()> {
tracing::info!("flipping layout");
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
// don't flip on Grid layout if matches!(workspace.layout(), Layout::Default(DefaultLayout::Grid)) {
match workspace.layout() { tracing::debug!("ignoring flip layout command for grid layout");
Layout::Default(layout) => match layout { return Ok(())
DefaultLayout::Grid => return Ok(()),
_ => (),
},
_ => (),
} }
tracing::info!("flipping layout");
#[allow(clippy::match_same_arms)] #[allow(clippy::match_same_arms)]
match workspace.layout_flip() { match workspace.layout_flip() {
None => { None => {