layout/monitor: Extract add_workspace_at()
Browse files at this commit3f09352067434c8ff84ef3f359e784cd63138c21Parent: 5059cce1 changed file +14 -10
- src/layout/monitor.rs +14 -10
src/layout/monitor.rsmodified+14 -10
| @@ -241,27 +241,31 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 241 | 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 | 245 | let ws = Workspace::new( |
| 246 | 246 | self.output.clone(), |
| 247 | 247 | self.clock.clone(), |
| 248 | 248 | self.options.clone(), |
| 249 | 249 | ); |
| 250 | - self.workspaces.insert(0, ws); | |
| 251 | - self.active_workspace_idx += 1; | |
| 250 | + | |
| 251 | + self.workspaces.insert(idx, ws); | |
| 252 | + if idx <= self.active_workspace_idx { | |
| 253 | + self.active_workspace_idx += 1; | |
| 254 | + } | |
| 252 | 255 | |
| 253 | 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 | 267 | pub fn add_workspace_bottom(&mut self) { |
| 259 | - let ws = Workspace::new( | |
| 260 | - self.output.clone(), | |
| 261 | - self.clock.clone(), | |
| 262 | - self.options.clone(), | |
| 263 | - ); | |
| 264 | - self.workspaces.push(ws); | |
| 268 | + self.add_workspace_at(self.workspaces.len()); | |
| 265 | 269 | } |
| 266 | 270 | |
| 267 | 271 | fn activate_workspace(&mut self, idx: usize) { |