layout/monitor: Cache scale, view_size, working_area
Browse files at this commitef60dd81d7f72a7b452857be02bbed2a1ab6a60fParent: 7671a5d3 changed files +70 -25
- src/layout/mod.rs +16 -12
- src/layout/monitor.rs +49 -12
- src/layout/workspace.rs +5 -1
src/layout/mod.rsmodified+16 -12
| @@ -1432,19 +1432,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1432 | pub fn update_output_size(&mut self, output: &Output) { | 1432 | pub fn update_output_size(&mut self, output: &Output) { |
| 1433 | let _span = tracy_client::span!("Layout::update_output_size"); | 1433 | let _span = tracy_client::span!("Layout::update_output_size"); |
| 1434 | 1434 | ||
| 1435 | - let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else { | 1435 | + let Some(mon) = self.monitor_for_output_mut(output) else { |
| 1436 | - panic!() | 1436 | + error!("monitor missing in update_output_size()"); |
| 1437 | + return; | ||
| 1437 | }; | 1438 | }; |
| 1438 | 1439 | ||
| 1439 | - for mon in monitors { | 1440 | + mon.update_output_size(); |
| 1440 | - if &mon.output == output { | ||
| 1441 | - for ws in &mut mon.workspaces { | ||
| 1442 | - ws.update_output_size(); | ||
| 1443 | - } | ||
| 1444 | - | ||
| 1445 | - break; | ||
| 1446 | - } | ||
| 1447 | - } | ||
| 1448 | } | 1441 | } |
| 1449 | 1442 | ||
| 1450 | pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 { | 1443 | pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 { |
| @@ -2550,6 +2543,17 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2550 | for workspace in &monitor.workspaces { | 2543 | for workspace in &monitor.workspaces { |
| 2551 | assert_eq!(self.clock, workspace.clock); | 2544 | assert_eq!(self.clock, workspace.clock); |
| 2552 | 2545 | ||
| 2546 | + assert_eq!( | ||
| 2547 | + monitor.scale().integer_scale(), | ||
| 2548 | + workspace.scale().integer_scale() | ||
| 2549 | + ); | ||
| 2550 | + assert_eq!( | ||
| 2551 | + monitor.scale().fractional_scale(), | ||
| 2552 | + workspace.scale().fractional_scale() | ||
| 2553 | + ); | ||
| 2554 | + assert_eq!(monitor.view_size(), workspace.view_size()); | ||
| 2555 | + assert_eq!(monitor.working_area(), workspace.working_area()); | ||
| 2556 | + | ||
| 2553 | assert_eq!( | 2557 | assert_eq!( |
| 2554 | workspace.base_options, self.options, | 2558 | workspace.base_options, self.options, |
| 2555 | "workspace options must be synchronized with layout" | 2559 | "workspace options must be synchronized with layout" |
| @@ -2602,7 +2606,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2602 | saw_view_offset_gesture = has_view_offset_gesture; | 2606 | saw_view_offset_gesture = has_view_offset_gesture; |
| 2603 | } | 2607 | } |
| 2604 | 2608 | ||
| 2605 | - let scale = monitor.output.current_scale().fractional_scale(); | 2609 | + let scale = monitor.scale().fractional_scale(); |
| 2606 | let iter = monitor.workspaces_with_render_geo(); | 2610 | let iter = monitor.workspaces_with_render_geo(); |
| 2607 | for (_ws, ws_geo) in iter { | 2611 | for (_ws, ws_geo) in iter { |
| 2608 | let pos = ws_geo.loc; | 2612 | let pos = ws_geo.loc; |
src/layout/monitor.rsmodified+49 -12
| @@ -14,7 +14,8 @@ use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement}; | |||
| 14 | use super::scrolling::{Column, ColumnWidth}; | 14 | use super::scrolling::{Column, ColumnWidth}; |
| 15 | use super::tile::Tile; | 15 | use super::tile::Tile; |
| 16 | use super::workspace::{ | 16 | use super::workspace::{ |
| 17 | - OutputId, Workspace, WorkspaceAddWindowTarget, WorkspaceId, WorkspaceRenderElement, | 17 | + compute_working_area, OutputId, Workspace, WorkspaceAddWindowTarget, WorkspaceId, |
| 18 | + WorkspaceRenderElement, | ||
| 18 | }; | 19 | }; |
| 19 | use super::{ActivateWindow, HitType, LayoutElement, Options}; | 20 | use super::{ActivateWindow, HitType, LayoutElement, Options}; |
| 20 | use crate::animation::{Animation, Clock}; | 21 | use crate::animation::{Animation, Clock}; |
| @@ -40,6 +41,17 @@ pub struct Monitor<W: LayoutElement> { | |||
| 40 | pub(super) output: Output, | 41 | pub(super) output: Output, |
| 41 | /// Cached name of the output. | 42 | /// Cached name of the output. |
| 42 | output_name: String, | 43 | output_name: String, |
| 44 | + /// Latest known scale for this output. | ||
| 45 | + scale: smithay::output::Scale, | ||
| 46 | + /// Latest known size for this output. | ||
| 47 | + view_size: Size<f64, Logical>, | ||
| 48 | + /// Latest known working area for this output. | ||
| 49 | + /// | ||
| 50 | + /// Not rounded to physical pixels. | ||
| 51 | + // FIXME: since this is used for things like DnD scrolling edges in the overview, ideally this | ||
| 52 | + // should only consider overlay and top layer-shell surfaces. However, Smithay doesn't easily | ||
| 53 | + // let you do this at the moment. | ||
| 54 | + working_area: Rectangle<f64, Logical>, | ||
| 43 | // Must always contain at least one. | 55 | // Must always contain at least one. |
| 44 | pub(super) workspaces: Vec<Workspace<W>>, | 56 | pub(super) workspaces: Vec<Workspace<W>>, |
| 45 | /// Index of the currently active workspace. | 57 | /// Index of the currently active workspace. |
| @@ -182,9 +194,16 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 182 | clock: Clock, | 194 | clock: Clock, |
| 183 | options: Rc<Options>, | 195 | options: Rc<Options>, |
| 184 | ) -> Self { | 196 | ) -> Self { |
| 197 | + let scale = output.current_scale(); | ||
| 198 | + let view_size = output_size(&output); | ||
| 199 | + let working_area = compute_working_area(&output); | ||
| 200 | + | ||
| 185 | Self { | 201 | Self { |
| 186 | output_name: output.name(), | 202 | output_name: output.name(), |
| 187 | output, | 203 | output, |
| 204 | + scale, | ||
| 205 | + view_size, | ||
| 206 | + working_area, | ||
| 188 | workspaces, | 207 | workspaces, |
| 189 | active_workspace_idx: 0, | 208 | active_workspace_idx: 0, |
| 190 | previous_workspace_id: None, | 209 | previous_workspace_id: None, |
| @@ -795,6 +814,16 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 795 | self.insert_hint_element.update_shaders(); | 814 | self.insert_hint_element.update_shaders(); |
| 796 | } | 815 | } |
| 797 | 816 | ||
| 817 | + pub fn update_output_size(&mut self) { | ||
| 818 | + self.scale = self.output.current_scale(); | ||
| 819 | + self.view_size = output_size(&self.output); | ||
| 820 | + self.working_area = compute_working_area(&self.output); | ||
| 821 | + | ||
| 822 | + for ws in &mut self.workspaces { | ||
| 823 | + ws.update_output_size(); | ||
| 824 | + } | ||
| 825 | + } | ||
| 826 | + | ||
| 798 | pub fn move_workspace_down(&mut self) { | 827 | pub fn move_workspace_down(&mut self) { |
| 799 | let mut new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1); | 828 | let mut new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1); |
| 800 | if new_idx == self.active_workspace_idx { | 829 | if new_idx == self.active_workspace_idx { |
| @@ -914,8 +943,8 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 914 | } | 943 | } |
| 915 | 944 | ||
| 916 | pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> { | 945 | pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> { |
| 917 | - let scale = self.output.current_scale().fractional_scale(); | 946 | + let scale = self.scale.fractional_scale(); |
| 918 | - let size = output_size(&self.output); | 947 | + let size = self.view_size; |
| 919 | 948 | ||
| 920 | // Ceil the workspace size in physical pixels. | 949 | // Ceil the workspace size in physical pixels. |
| 921 | let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale); | 950 | let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale); |
| @@ -933,8 +962,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 933 | pub fn workspaces_with_render_geo( | 962 | pub fn workspaces_with_render_geo( |
| 934 | &self, | 963 | &self, |
| 935 | ) -> impl Iterator<Item = (&Workspace<W>, Rectangle<f64, Logical>)> { | 964 | ) -> impl Iterator<Item = (&Workspace<W>, Rectangle<f64, Logical>)> { |
| 936 | - let output_size = output_size(&self.output); | 965 | + let output_geo = Rectangle::from_size(self.view_size); |
| 937 | - let output_geo = Rectangle::new(Point::from((0., 0.)), output_size); | ||
| 938 | 966 | ||
| 939 | let geo = self.workspaces_render_geo(); | 967 | let geo = self.workspaces_render_geo(); |
| 940 | zip(self.workspaces.iter(), geo) | 968 | zip(self.workspaces.iter(), geo) |
| @@ -945,8 +973,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 945 | pub fn workspaces_with_render_geo_mut( | 973 | pub fn workspaces_with_render_geo_mut( |
| 946 | &mut self, | 974 | &mut self, |
| 947 | ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> { | 975 | ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> { |
| 948 | - let output_size = output_size(&self.output); | 976 | + let output_geo = Rectangle::from_size(self.view_size); |
| 949 | - let output_geo = Rectangle::new(Point::from((0., 0.)), output_size); | ||
| 950 | 977 | ||
| 951 | let geo = self.workspaces_render_geo(); | 978 | let geo = self.workspaces_render_geo(); |
| 952 | zip(self.workspaces.iter_mut(), geo) | 979 | zip(self.workspaces.iter_mut(), geo) |
| @@ -958,11 +985,10 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 958 | &self, | 985 | &self, |
| 959 | pos_within_output: Point<f64, Logical>, | 986 | pos_within_output: Point<f64, Logical>, |
| 960 | ) -> Option<(&Workspace<W>, Rectangle<f64, Logical>)> { | 987 | ) -> Option<(&Workspace<W>, Rectangle<f64, Logical>)> { |
| 961 | - let size = output_size(&self.output); | ||
| 962 | let (ws, geo) = self.workspaces_with_render_geo().find_map(|(ws, geo)| { | 988 | let (ws, geo) = self.workspaces_with_render_geo().find_map(|(ws, geo)| { |
| 963 | // Extend width to entire output. | 989 | // Extend width to entire output. |
| 964 | let loc = Point::from((0., geo.loc.y)); | 990 | let loc = Point::from((0., geo.loc.y)); |
| 965 | - let size = Size::from((size.w, geo.size.h)); | 991 | + let size = Size::from((self.view_size.w, geo.size.h)); |
| 966 | let bounds = Rectangle::new(loc, size); | 992 | let bounds = Rectangle::new(loc, size); |
| 967 | 993 | ||
| 968 | bounds.contains(pos_within_output).then_some((ws, geo)) | 994 | bounds.contains(pos_within_output).then_some((ws, geo)) |
| @@ -999,10 +1025,9 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 999 | ) -> impl Iterator<Item = MonitorRenderElement<R>> + 'a { | 1025 | ) -> impl Iterator<Item = MonitorRenderElement<R>> + 'a { |
| 1000 | let _span = tracy_client::span!("Monitor::render_elements"); | 1026 | let _span = tracy_client::span!("Monitor::render_elements"); |
| 1001 | 1027 | ||
| 1002 | - let scale = self.output.current_scale().fractional_scale(); | 1028 | + let scale = self.scale.fractional_scale(); |
| 1003 | - let size = output_size(&self.output); | ||
| 1004 | // Ceil the height in physical pixels. | 1029 | // Ceil the height in physical pixels. |
| 1005 | - let height = (size.h * scale).ceil() as i32; | 1030 | + let height = (self.view_size.h * scale).ceil() as i32; |
| 1006 | 1031 | ||
| 1007 | // Crop the elements to prevent them overflowing, currently visible during a workspace | 1032 | // Crop the elements to prevent them overflowing, currently visible during a workspace |
| 1008 | // switch. | 1033 | // switch. |
| @@ -1176,4 +1201,16 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1176 | 1201 | ||
| 1177 | true | 1202 | true |
| 1178 | } | 1203 | } |
| 1204 | + | ||
| 1205 | + pub fn scale(&self) -> smithay::output::Scale { | ||
| 1206 | + self.scale | ||
| 1207 | + } | ||
| 1208 | + | ||
| 1209 | + pub fn view_size(&self) -> Size<f64, Logical> { | ||
| 1210 | + self.view_size | ||
| 1211 | + } | ||
| 1212 | + | ||
| 1213 | + pub fn working_area(&self) -> Rectangle<f64, Logical> { | ||
| 1214 | + self.working_area | ||
| 1215 | + } | ||
| 1179 | } | 1216 | } |
src/layout/workspace.rsmodified+5 -1
| @@ -1708,6 +1708,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1708 | self.floating.logical_to_size_frac(logical_pos) | 1708 | self.floating.logical_to_size_frac(logical_pos) |
| 1709 | } | 1709 | } |
| 1710 | 1710 | ||
| 1711 | + pub fn working_area(&self) -> Rectangle<f64, Logical> { | ||
| 1712 | + self.working_area | ||
| 1713 | + } | ||
| 1714 | + | ||
| 1711 | #[cfg(test)] | 1715 | #[cfg(test)] |
| 1712 | pub fn scrolling(&self) -> &ScrollingSpace<W> { | 1716 | pub fn scrolling(&self) -> &ScrollingSpace<W> { |
| 1713 | &self.scrolling | 1717 | &self.scrolling |
| @@ -1777,6 +1781,6 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1777 | } | 1781 | } |
| 1778 | } | 1782 | } |
| 1779 | 1783 | ||
| 1780 | -fn compute_working_area(output: &Output) -> Rectangle<f64, Logical> { | 1784 | +pub(super) fn compute_working_area(output: &Output) -> Rectangle<f64, Logical> { |
| 1781 | layer_map_for_output(output).non_exclusive_zone().to_f64() | 1785 | layer_map_for_output(output).non_exclusive_zone().to_f64() |
| 1782 | } | 1786 | } |