forge
Explore
Log in

Don't you dare go Hollow

layout/monitor: Extract workspaces_render_geo()

Browse files at this commit

21630ddb5ebd078c5a6400d6d56c44f0903f1d44Ivan MolodetskikhParent: 9e5e0c8
src/layout/mod.rsmodified+29 -18
@@ -2601,6 +2601,17 @@ impl<W: LayoutElement> Layout<W> {
2601 }2601 }
2602 saw_view_offset_gesture = has_view_offset_gesture;2602 saw_view_offset_gesture = has_view_offset_gesture;
2603 }2603 }
2604+
2605+ let scale = monitor.output.current_scale().fractional_scale();
2606+ let iter = monitor.workspaces_with_render_geo();
2607+ for (_ws, ws_geo) in iter {
2608+ let pos = ws_geo.loc;
2609+ let rounded_pos = pos.to_physical_precise_round(scale).to_logical(scale);
2610+
2611+ // Workspace positions must be rounded to physical pixels.
2612+ assert_abs_diff_eq!(pos.x, rounded_pos.x, epsilon = 1e-5);
2613+ assert_abs_diff_eq!(pos.y, rounded_pos.y, epsilon = 1e-5);
2614+ }
2604 }2615 }
2605 }2616 }
2606 2617
@@ -2623,14 +2634,14 @@ impl<W: LayoutElement> Layout<W> {
2623 // Scroll the view if needed.2634 // Scroll the view if needed.
2624 if let Some((output, pos_within_output)) = dnd_scroll {2635 if let Some((output, pos_within_output)) = dnd_scroll {
2625 if let Some(mon) = self.monitor_for_output_mut(&output) {2636 if let Some(mon) = self.monitor_for_output_mut(&output) {
2626- if let Some((ws, offset)) = mon.workspace_under(pos_within_output) {2637+ if let Some((ws, geo)) = mon.workspace_under(pos_within_output) {
2627 let ws_id = ws.id();2638 let ws_id = ws.id();
2628 let ws = mon2639 let ws = mon
2629 .workspaces2640 .workspaces
2630 .iter_mut()2641 .iter_mut()
2631 .find(|ws| ws.id() == ws_id)2642 .find(|ws| ws.id() == ws_id)
2632 .unwrap();2643 .unwrap();
2633- ws.dnd_scroll_gesture_scroll(pos_within_output - offset);2644+ ws.dnd_scroll_gesture_scroll(pos_within_output - geo.loc);
2634 }2645 }
2635 }2646 }
2636 }2647 }
@@ -2770,7 +2781,7 @@ impl<W: LayoutElement> Layout<W> {
2770 let _span = tracy_client::span!("Layout::update_insert_hint::update");2781 let _span = tracy_client::span!("Layout::update_insert_hint::update");
2771 2782
2772 if let Some(mon) = self.monitor_for_output_mut(&move_.output) {2783 if let Some(mon) = self.monitor_for_output_mut(&move_.output) {
2773- if let Some((ws, offset)) = mon.workspace_under(move_.pointer_pos_within_output) {2784+ if let Some((ws, geo)) = mon.workspace_under(move_.pointer_pos_within_output) {
2774 let ws_id = ws.id();2785 let ws_id = ws.id();
2775 let ws = mon2786 let ws = mon
2776 .workspaces2787 .workspaces
@@ -2778,7 +2789,7 @@ impl<W: LayoutElement> Layout<W> {
2778 .find(|ws| ws.id() == ws_id)2789 .find(|ws| ws.id() == ws_id)
2779 .unwrap();2790 .unwrap();
2780 2791
2781- let position = ws.get_insert_position(move_.pointer_pos_within_output - offset);2792+ let position = ws.get_insert_position(move_.pointer_pos_within_output - geo.loc);
2782 2793
2783 let rules = move_.tile.window().rules();2794 let rules = move_.tile.window().rules();
2784 let border_width = move_.tile.effective_border_width().unwrap_or(0.);2795 let border_width = move_.tile.effective_border_width().unwrap_or(0.);
@@ -3661,8 +3672,8 @@ impl<W: LayoutElement> Layout<W> {
3661 return false;3672 return false;
3662 };3673 };
3663 3674
3664- let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {3675+ let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
3665- mon.workspaces_with_render_positions()3676+ mon.workspaces_with_render_geo()
3666 .find(|(ws, _)| ws.has_window(&window_id))3677 .find(|(ws, _)| ws.has_window(&window_id))
3667 .map(|rv| (mon, rv))3678 .map(|rv| (mon, rv))
3668 }) else {3679 }) else {
@@ -3680,7 +3691,7 @@ impl<W: LayoutElement> Layout<W> {
3680 .unwrap();3691 .unwrap();
3681 let window_offset = tile.window_loc();3692 let window_offset = tile.window_loc();
3682 3693
3683- let tile_pos = ws_offset + tile_offset;3694+ let tile_pos = ws_geo.loc + tile_offset;
3684 3695
3685 let pointer_offset_within_window = start_pos_within_output - tile_pos - window_offset;3696 let pointer_offset_within_window = start_pos_within_output - tile_pos - window_offset;
3686 let window_size = tile.window_size();3697 let window_size = tile.window_size();
@@ -3776,8 +3787,8 @@ impl<W: LayoutElement> Layout<W> {
3776 // potentially animatable.3787 // potentially animatable.
3777 let mut tile_pos = None;3788 let mut tile_pos = None;
3778 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {3789 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
3779- if let Some((mon, (ws, ws_offset))) = monitors.iter().find_map(|mon| {3790+ if let Some((mon, (ws, ws_geo))) = monitors.iter().find_map(|mon| {
3780- mon.workspaces_with_render_positions()3791+ mon.workspaces_with_render_geo()
3781 .find(|(ws, _)| ws.has_window(window))3792 .find(|(ws, _)| ws.has_window(window))
3782 .map(|rv| (mon, rv))3793 .map(|rv| (mon, rv))
3783 }) {3794 }) {
@@ -3787,7 +3798,7 @@ impl<W: LayoutElement> Layout<W> {
3787 .find(|(tile, _, _)| tile.window().id() == window)3798 .find(|(tile, _, _)| tile.window().id() == window)
3788 .unwrap();3799 .unwrap();
3789 3800
3790- tile_pos = Some(ws_offset + tile_offset);3801+ tile_pos = Some(ws_geo.loc + tile_offset);
3791 }3802 }
3792 }3803 }
3793 }3804 }
@@ -3979,12 +3990,12 @@ impl<W: LayoutElement> Layout<W> {
3979 let (mon, ws_idx, position, offset) = if let Some(mon) =3990 let (mon, ws_idx, position, offset) = if let Some(mon) =
3980 monitors.iter_mut().find(|mon| mon.output == move_.output)3991 monitors.iter_mut().find(|mon| mon.output == move_.output)
3981 {3992 {
3982- let (ws, offset) = mon3993+ let (ws, ws_geo) = mon
3983 .workspace_under(move_.pointer_pos_within_output)3994 .workspace_under(move_.pointer_pos_within_output)
3984 // If the pointer is somehow outside the move output and a workspace switch3995 // If the pointer is somehow outside the move output and a workspace switch
3985 // is in progress, this won't necessarily do the expected thing, but also3996 // is in progress, this won't necessarily do the expected thing, but also
3986 // that is not really supposed to happen so eh?3997 // that is not really supposed to happen so eh?
3987- .unwrap_or_else(|| mon.workspaces_with_render_positions().next().unwrap());3998+ .unwrap_or_else(|| mon.workspaces_with_render_geo().next().unwrap());
3988 3999
3989 let ws_id = ws.id();4000 let ws_id = ws.id();
3990 let ws_idx = mon4001 let ws_idx = mon
@@ -3997,14 +4008,14 @@ impl<W: LayoutElement> Layout<W> {
3997 InsertPosition::Floating4008 InsertPosition::Floating
3998 } else {4009 } else {
3999 let ws = &mut mon.workspaces[ws_idx];4010 let ws = &mut mon.workspaces[ws_idx];
4000- ws.get_insert_position(move_.pointer_pos_within_output - offset)4011+ ws.get_insert_position(move_.pointer_pos_within_output - ws_geo.loc)
4001 };4012 };
4002 4013
4003- (mon, ws_idx, position, offset)4014+ (mon, ws_idx, position, ws_geo.loc)
4004 } else {4015 } else {
4005 let mon = &mut monitors[*active_monitor_idx];4016 let mon = &mut monitors[*active_monitor_idx];
4006 // No point in trying to use the pointer position on the wrong output.4017 // No point in trying to use the pointer position on the wrong output.
4007- let (ws, offset) = mon.workspaces_with_render_positions().next().unwrap();4018+ let (ws, ws_geo) = mon.workspaces_with_render_geo().next().unwrap();
4008 4019
4009 let position = if move_.is_floating {4020 let position = if move_.is_floating {
4010 InsertPosition::Floating4021 InsertPosition::Floating
@@ -4018,7 +4029,7 @@ impl<W: LayoutElement> Layout<W> {
4018 .iter_mut()4029 .iter_mut()
4019 .position(|ws| ws.id() == ws_id)4030 .position(|ws| ws.id() == ws_id)
4020 .unwrap();4031 .unwrap();
4021- (mon, ws_idx, position, offset)4032+ (mon, ws_idx, position, ws_geo.loc)
4022 };4033 };
4023 4034
4024 let win_id = move_.tile.window().id().clone();4035 let win_id = move_.tile.window().id().clone();
@@ -4435,7 +4446,7 @@ impl<W: LayoutElement> Layout<W> {
4435 let Some(mon) = self.monitor_for_output_mut(&output) else {4446 let Some(mon) = self.monitor_for_output_mut(&output) else {
4436 return;4447 return;
4437 };4448 };
4438- let Some((ws, offset)) = mon.workspace_under(pointer_pos_within_output) else {4449+ let Some((ws, ws_geo)) = mon.workspace_under(pointer_pos_within_output) else {
4439 return;4450 return;
4440 };4451 };
4441 let ws_id = ws.id();4452 let ws_id = ws.id();
@@ -4445,7 +4456,7 @@ impl<W: LayoutElement> Layout<W> {
4445 .find(|ws| ws.id() == ws_id)4456 .find(|ws| ws.id() == ws_id)
4446 .unwrap();4457 .unwrap();
4447 4458
4448- let tile_pos = tile_pos - offset;4459+ let tile_pos = tile_pos - ws_geo.loc;
4449 ws.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);4460 ws.start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker);
4450 return;4461 return;
4451 }4462 }
src/layout/monitor.rsmodified+65 -81
@@ -1,4 +1,5 @@
1 use std::cmp::min;1 use std::cmp::min;
2+use std::iter::zip;
2 use std::rc::Rc;3 use std::rc::Rc;
3 use std::time::Duration;4 use std::time::Duration;
4 5
@@ -20,7 +21,7 @@ use crate::render_helpers::renderer::NiriRenderer;
20 use crate::render_helpers::RenderTarget;21 use crate::render_helpers::RenderTarget;
21 use crate::rubber_band::RubberBand;22 use crate::rubber_band::RubberBand;
22 use crate::utils::transaction::Transaction;23 use crate::utils::transaction::Transaction;
23-use crate::utils::{output_size, round_logical_in_physical, ResizeEdge};24+use crate::utils::{output_size, ResizeEdge};
24 25
25 /// Amount of touchpad movement to scroll the height of one workspace.26 /// Amount of touchpad movement to scroll the height of one workspace.
26 const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.;27 const WORKSPACE_GESTURE_MOVEMENT: f64 = 300.;
@@ -680,31 +681,8 @@ impl<W: LayoutElement> Monitor<W> {
680 }681 }
681 682
682 pub fn update_render_elements(&mut self, is_active: bool) {683 pub fn update_render_elements(&mut self, is_active: bool) {
683- match &self.workspace_switch {684+ for (ws, _) in self.workspaces_with_render_geo_mut() {
684- Some(switch) => {685+ ws.update_render_elements(is_active);
685- let render_idx = switch.current_idx();
686- let before_idx = render_idx.floor();
687- let after_idx = render_idx.ceil();
688-
689- if after_idx < 0. || before_idx as usize >= self.workspaces.len() {
690- return;
691- }
692-
693- let after_idx = after_idx as usize;
694- if after_idx < self.workspaces.len() {
695- self.workspaces[after_idx].update_render_elements(is_active);
696-
697- if before_idx < 0. {
698- return;
699- }
700- }
701-
702- let before_idx = before_idx as usize;
703- self.workspaces[before_idx].update_render_elements(is_active);
704- }
705- None => {
706- self.workspaces[self.active_workspace_idx].update_render_elements(is_active);
707- }
708 }686 }
709 }687 }
710 688
@@ -855,72 +833,78 @@ impl<W: LayoutElement> Monitor<W> {
855 Some(rect)833 Some(rect)
856 }834 }
857 835
858- pub fn workspaces_with_render_positions(836+ pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> {
837+ let scale = self.output.current_scale().fractional_scale();
838+ let size = output_size(&self.output);
839+
840+ // Ceil the workspace size in physical pixels.
841+ let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale);
842+
843+ let render_idx = if let Some(switch) = &self.workspace_switch {
844+ switch.current_idx()
845+ } else {
846+ self.active_workspace_idx as f64
847+ };
848+
849+ let first_ws_y = -render_idx * ws_size.h;
850+
851+ (0..self.workspaces.len()).map(move |idx| {
852+ let y = first_ws_y + idx as f64 * ws_size.h;
853+ let loc = Point::from((0., y));
854+ let loc = loc.to_physical_precise_round(scale).to_logical(scale);
855+ Rectangle::new(loc, ws_size)
856+ })
857+ }
858+
859+ pub fn workspaces_with_render_geo(
859 &self,860 &self,
860- ) -> impl Iterator<Item = (&Workspace<W>, Point<f64, Logical>)> {861+ ) -> impl Iterator<Item = (&Workspace<W>, Rectangle<f64, Logical>)> {
861- let mut first = None;862+ let output_size = output_size(&self.output);
862- let mut second = None;863+ let output_geo = Rectangle::new(Point::from((0., 0.)), output_size);
863-864+
864- match &self.workspace_switch {865+ let geo = self.workspaces_render_geo();
865- Some(switch) => {866+ zip(self.workspaces.iter(), geo)
866- let render_idx = switch.current_idx();867+ // Cull out workspaces outside the output.
867- let before_idx = render_idx.floor();868+ .filter(move |(_ws, geo)| geo.intersection(output_geo).is_some())
868- let after_idx = render_idx.ceil();869+ }
869-
870- if after_idx >= 0. && before_idx < self.workspaces.len() as f64 {
871- let scale = self.output.current_scale().fractional_scale();
872- let size = output_size(&self.output);
873- let offset =
874- round_logical_in_physical(scale, (render_idx - before_idx) * size.h);
875-
876- // Ceil the height in physical pixels.
877- let height = (size.h * scale).ceil() / scale;
878-
879- if before_idx >= 0. {
880- let before_idx = before_idx as usize;
881- let before_offset = Point::from((0., -offset));
882- first = Some((&self.workspaces[before_idx], before_offset));
883- }
884-
885- let after_idx = after_idx as usize;
886- if after_idx < self.workspaces.len() {
887- let after_offset = Point::from((0., -offset + height));
888- second = Some((&self.workspaces[after_idx], after_offset));
889- }
890- }
891- }
892- None => {
893- first = Some((
894- &self.workspaces[self.active_workspace_idx],
895- Point::from((0., 0.)),
896- ));
897- }
898- }
899 870
900- first.into_iter().chain(second)871+ pub fn workspaces_with_render_geo_mut(
872+ &mut self,
873+ ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> {
874+ let output_size = output_size(&self.output);
875+ let output_geo = Rectangle::new(Point::from((0., 0.)), output_size);
876+
877+ let geo = self.workspaces_render_geo();
878+ zip(self.workspaces.iter_mut(), geo)
879+ // Cull out workspaces outside the output.
880+ .filter(move |(_ws, geo)| geo.intersection(output_geo).is_some())
901 }881 }
902 882
903 pub fn workspace_under(883 pub fn workspace_under(
904 &self,884 &self,
905 pos_within_output: Point<f64, Logical>,885 pos_within_output: Point<f64, Logical>,
906- ) -> Option<(&Workspace<W>, Point<f64, Logical>)> {886+ ) -> Option<(&Workspace<W>, Rectangle<f64, Logical>)> {
907 let size = output_size(&self.output);887 let size = output_size(&self.output);
908- let (ws, bounds) = self888+ let (ws, geo) = self.workspaces_with_render_geo().find_map(|(ws, geo)| {
909- .workspaces_with_render_positions()889+ // Extend width to entire output.
910- .map(|(ws, offset)| (ws, Rectangle::new(offset, size)))890+ let loc = Point::from((0., geo.loc.y));
911- .find(|(_, bounds)| bounds.contains(pos_within_output))?;891+ let size = Size::from((size.w, geo.size.h));
912- Some((ws, bounds.loc))892+ let bounds = Rectangle::new(loc, size);
893+
894+ bounds.contains(pos_within_output).then_some((ws, geo))
895+ })?;
896+ Some((ws, geo))
913 }897 }
914 898
915 pub fn window_under(&self, pos_within_output: Point<f64, Logical>) -> Option<(&W, HitType)> {899 pub fn window_under(&self, pos_within_output: Point<f64, Logical>) -> Option<(&W, HitType)> {
916- let (ws, offset) = self.workspace_under(pos_within_output)?;900+ let (ws, geo) = self.workspace_under(pos_within_output)?;
917- let (win, hit) = ws.window_under(pos_within_output - offset)?;901+ let (win, hit) = ws.window_under(pos_within_output - geo.loc)?;
918- Some((win, hit.offset_win_pos(offset)))902+ Some((win, hit.offset_win_pos(geo.loc)))
919 }903 }
920 904
921 pub fn resize_edges_under(&self, pos_within_output: Point<f64, Logical>) -> Option<ResizeEdge> {905 pub fn resize_edges_under(&self, pos_within_output: Point<f64, Logical>) -> Option<ResizeEdge> {
922- let (ws, offset) = self.workspace_under(pos_within_output)?;906+ let (ws, geo) = self.workspace_under(pos_within_output)?;
923- ws.resize_edges_under(pos_within_output - offset)907+ ws.resize_edges_under(pos_within_output - geo.loc)
924 }908 }
925 909
926 pub fn render_above_top_layer(&self) -> bool {910 pub fn render_above_top_layer(&self) -> bool {
@@ -968,8 +952,8 @@ impl<W: LayoutElement> Monitor<W> {
968 )952 )
969 };953 };
970 954
971- self.workspaces_with_render_positions()955+ self.workspaces_with_render_geo()
972- .flat_map(move |(ws, offset)| {956+ .flat_map(move |(ws, geo)| {
973 ws.render_elements(renderer, target, focus_ring)957 ws.render_elements(renderer, target, focus_ring)
974 .filter_map(move |elem| {958 .filter_map(move |elem| {
975 CropRenderElement::from_element(elem, scale, crop_bounds)959 CropRenderElement::from_element(elem, scale, crop_bounds)
@@ -980,7 +964,7 @@ impl<W: LayoutElement> Monitor<W> {
980 // The offset we get from workspaces_with_render_positions() is already964 // The offset we get from workspaces_with_render_positions() is already
981 // rounded to physical pixels, but it's in the logical coordinate965 // rounded to physical pixels, but it's in the logical coordinate
982 // space, so we need to convert it to physical.966 // space, so we need to convert it to physical.
983- offset.to_physical_precise_round(scale),967+ geo.loc.to_physical_precise_round(scale),
984 Relocate::Relative,968 Relocate::Relative,
985 )969 )
986 })970 })