forge
Explore
Log in

Don't you dare go Hollow

layout: Extract Monitor::remove_workspace_by_idx()

Browse files at this commit

3b4cf1ec8f0eea992740a33e143917edb761eb7dIvan MolodetskikhParent: 1484175
src/layout/mod.rsmodified+2 -30
@@ -3414,19 +3414,7 @@ impl<W: LayoutElement> Layout<W> {
3414 return false;3414 return false;
3415 }3415 }
3416 3416
3417- if current.active_workspace_idx == current.workspaces.len() - 1 {3417+ let mut ws = current.remove_workspace_by_idx(current.active_workspace_idx);
3418- // Insert a new empty workspace.
3419- current.add_workspace_bottom();
3420- }
3421- if current.options.layout.empty_workspace_above_first && current.active_workspace_idx == 0 {
3422- current.add_workspace_top();
3423- }
3424-
3425- let mut ws = current.workspaces.remove(current.active_workspace_idx);
3426- current.active_workspace_idx = current.active_workspace_idx.saturating_sub(1);
3427- current.workspace_switch = None;
3428- current.clean_up_workspaces();
3429-
3430 ws.set_output(Some(output.clone()));3418 ws.set_output(Some(output.clone()));
3431 ws.original_output = OutputId::new(output);3419 ws.original_output = OutputId::new(output);
3432 3420
@@ -3500,23 +3488,7 @@ impl<W: LayoutElement> Layout<W> {
3500 3488
3501 let current_active_ws_idx = current.active_workspace_idx;3489 let current_active_ws_idx = current.active_workspace_idx;
3502 3490
3503- if old_idx == current.workspaces.len() - 1 {3491+ let mut ws = current.remove_workspace_by_idx(old_idx);
3504- // Insert a new empty workspace.
3505- current.add_workspace_bottom();
3506- }
3507-
3508- let mut ws = current.workspaces.remove(old_idx);
3509-
3510- if current.options.layout.empty_workspace_above_first && old_idx == 0 {
3511- current.add_workspace_top();
3512- }
3513-
3514- if old_idx < current.active_workspace_idx {
3515- current.active_workspace_idx -= 1;
3516- }
3517- current.workspace_switch = None;
3518- current.clean_up_workspaces();
3519-
3520 ws.set_output(Some(new_output.clone()));3492 ws.set_output(Some(new_output.clone()));
3521 ws.original_output = OutputId::new(&new_output);3493 ws.original_output = OutputId::new(&new_output);
3522 3494
src/layout/monitor.rsmodified+25 -0
@@ -604,6 +604,31 @@ impl<W: LayoutElement> Monitor<W> {
604 true604 true
605 }605 }
606 606
607+ pub fn remove_workspace_by_idx(&mut self, mut idx: usize) -> Workspace<W> {
608+ if idx == self.workspaces.len() - 1 {
609+ self.add_workspace_bottom();
610+ }
611+ if self.options.layout.empty_workspace_above_first && idx == 0 {
612+ self.add_workspace_top();
613+ idx += 1;
614+ }
615+
616+ let mut ws = self.workspaces.remove(idx);
617+ ws.set_output(None);
618+
619+ // For monitor current workspace removal, we focus previous rather than next (<= rather
620+ // than <). This is different from columns and tiles, but it lets move-workspace-to-monitor
621+ // back and forth to preserve position.
622+ if idx <= self.active_workspace_idx && self.active_workspace_idx > 0 {
623+ self.active_workspace_idx -= 1;
624+ }
625+
626+ self.workspace_switch = None;
627+ self.clean_up_workspaces();
628+
629+ ws
630+ }
631+
607 pub fn move_down_or_to_workspace_down(&mut self) {632 pub fn move_down_or_to_workspace_down(&mut self) {
608 if !self.active_workspace().move_down() {633 if !self.active_workspace().move_down() {
609 self.move_to_workspace_down(true);634 self.move_to_workspace_down(true);