forge
Explore
Log in

Don't you dare go Hollow

layout/monitor: Extract add_workspace_at()

Browse files at this commit

3f09352067434c8ff84ef3f359e784cd63138c21Ivan MolodetskikhParent: 5059cce
src/layout/monitor.rsmodified+14 -10
@@ -241,27 +241,31 @@ impl<W: LayoutElement> Monitor<W> {
241 self.windows().any(|win| win.id() == window)241 self.windows().any(|win| win.id() == window)
242 }242 }
243 243
244- pub fn add_workspace_top(&mut self) {244+ pub fn add_workspace_at(&mut self, idx: usize) {
245 let ws = Workspace::new(245 let ws = Workspace::new(
246 self.output.clone(),246 self.output.clone(),
247 self.clock.clone(),247 self.clock.clone(),
248 self.options.clone(),248 self.options.clone(),
249 );249 );
250- self.workspaces.insert(0, ws);250+
251- self.active_workspace_idx += 1;251+ self.workspaces.insert(idx, ws);
252+ if idx <= self.active_workspace_idx {
253+ self.active_workspace_idx += 1;
254+ }
252 255
253 if let Some(switch) = &mut self.workspace_switch {256 if let Some(switch) = &mut self.workspace_switch {
254- switch.offset(1);257+ if idx as f64 <= switch.target_idx() {
258+ switch.offset(1);
259+ }
255 }260 }
256 }261 }
257 262
263+ pub fn add_workspace_top(&mut self) {
264+ self.add_workspace_at(0);
265+ }
266+
258 pub fn add_workspace_bottom(&mut self) {267 pub fn add_workspace_bottom(&mut self) {
259- let ws = Workspace::new(268+ self.add_workspace_at(self.workspaces.len());
260- self.output.clone(),
261- self.clock.clone(),
262- self.options.clone(),
263- );
264- self.workspaces.push(ws);
265 }269 }
266 270
267 fn activate_workspace(&mut self, idx: usize) {271 fn activate_workspace(&mut self, idx: usize) {