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> {
241241 self.windows().any(|win| win.id() == window)
242242 }
243243
244- pub fn add_workspace_top(&mut self) {
244+ pub fn add_workspace_at(&mut self, idx: usize) {
245245 let ws = Workspace::new(
246246 self.output.clone(),
247247 self.clock.clone(),
248248 self.options.clone(),
249249 );
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+ }
252255
253256 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+ }
255260 }
256261 }
257262
263+ pub fn add_workspace_top(&mut self) {
264+ self.add_workspace_at(0);
265+ }
266+
258267 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());
265269 }
266270
267271 fn activate_workspace(&mut self, idx: usize) {