From d25473188528b9e9b69e2fb70dccaf8c3605128d Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 21 Oct 2023 20:49:29 +0400 Subject: Use correct workspace vertical position for rendering --- src/layout.rs | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/layout.rs b/src/layout.rs index 41dc0d4a..5c4a633e 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -835,20 +835,6 @@ impl Layout { )) } - pub fn workspace_for_output(&self, output: &Output) -> Option<&Workspace> { - let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { - return None; - }; - - monitors.iter().find_map(|monitor| { - if &monitor.output == output { - Some(&monitor.workspaces[monitor.active_workspace_idx]) - } else { - None - } - }) - } - pub fn windows_for_output(&self, output: &Output) -> impl Iterator + '_ { let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { panic!() @@ -1019,8 +1005,12 @@ impl Layout { output: &Output, pos_within_output: Point, ) -> Option<(&W, Point)> { - let ws = self.workspace_for_output(output).unwrap(); - ws.window_under(pos_within_output) + let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { + return None; + }; + + let mon = monitors.iter().find(|mon| &mon.output == output)?; + mon.window_under(pos_within_output) } #[cfg(test)] @@ -1698,6 +1688,37 @@ impl Monitor { self.clean_up_workspaces(); } + + pub fn window_under( + &self, + pos_within_output: Point, + ) -> Option<(&W, Point)> { + match &self.workspace_switch { + Some(switch) => { + let size = output_size(&self.output); + + let render_idx = switch.current_idx(); + let before_idx = render_idx.floor() as usize; + let after_idx = render_idx.ceil() as usize; + + let offset = ((render_idx - before_idx as f64) * size.h as f64).round() as i32; + + let (idx, ws_offset) = if pos_within_output.y < (size.h - offset) as f64 { + (before_idx, Point::from((0, offset))) + } else { + (after_idx, Point::from((0, -size.h + offset))) + }; + + let ws = &self.workspaces[idx]; + let (win, win_pos) = ws.window_under(pos_within_output + ws_offset.to_f64())?; + Some((win, win_pos - ws_offset)) + } + None => { + let ws = &self.workspaces[self.active_workspace_idx]; + ws.window_under(pos_within_output) + } + } + } } impl Monitor { -- cgit