forge
Explore
Log in

Don't you dare go Hollow

layout/monitor: Cache scale, view_size, working_area

Browse files at this commit

ef60dd81d7f72a7b452857be02bbed2a1ab6a60fIvan MolodetskikhParent: 7671a5d
src/layout/mod.rsmodified+16 -12
@@ -1432,19 +1432,12 @@ impl<W: LayoutElement> Layout<W> {
14321432 pub fn update_output_size(&mut self, output: &Output) {
14331433 let _span = tracy_client::span!("Layout::update_output_size");
14341434
1435- let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
1436- panic!()
1435+ let Some(mon) = self.monitor_for_output_mut(output) else {
1436+ error!("monitor missing in update_output_size()");
1437+ return;
14371438 };
14381439
1439- for mon in monitors {
1440- if &mon.output == output {
1441- for ws in &mut mon.workspaces {
1442- ws.update_output_size();
1443- }
1444-
1445- break;
1446- }
1447- }
1440+ mon.update_output_size();
14481441 }
14491442
14501443 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
@@ -2550,6 +2543,17 @@ impl<W: LayoutElement> Layout<W> {
25502543 for workspace in &monitor.workspaces {
25512544 assert_eq!(self.clock, workspace.clock);
25522545
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+
25532557 assert_eq!(
25542558 workspace.base_options, self.options,
25552559 "workspace options must be synchronized with layout"
@@ -2602,7 +2606,7 @@ impl<W: LayoutElement> Layout<W> {
26022606 saw_view_offset_gesture = has_view_offset_gesture;
26032607 }
26042608
2605- let scale = monitor.output.current_scale().fractional_scale();
2609+ let scale = monitor.scale().fractional_scale();
26062610 let iter = monitor.workspaces_with_render_geo();
26072611 for (_ws, ws_geo) in iter {
26082612 let pos = ws_geo.loc;
src/layout/monitor.rsmodified+49 -12
@@ -14,7 +14,8 @@ use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};
1414 use super::scrolling::{Column, ColumnWidth};
1515 use super::tile::Tile;
1616 use super::workspace::{
17- OutputId, Workspace, WorkspaceAddWindowTarget, WorkspaceId, WorkspaceRenderElement,
17+ compute_working_area, OutputId, Workspace, WorkspaceAddWindowTarget, WorkspaceId,
18+ WorkspaceRenderElement,
1819 };
1920 use super::{ActivateWindow, HitType, LayoutElement, Options};
2021 use crate::animation::{Animation, Clock};
@@ -40,6 +41,17 @@ pub struct Monitor<W: LayoutElement> {
4041 pub(super) output: Output,
4142 /// Cached name of the output.
4243 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>,
4355 // Must always contain at least one.
4456 pub(super) workspaces: Vec<Workspace<W>>,
4557 /// Index of the currently active workspace.
@@ -182,9 +194,16 @@ impl<W: LayoutElement> Monitor<W> {
182194 clock: Clock,
183195 options: Rc<Options>,
184196 ) -> Self {
197+ let scale = output.current_scale();
198+ let view_size = output_size(&output);
199+ let working_area = compute_working_area(&output);
200+
185201 Self {
186202 output_name: output.name(),
187203 output,
204+ scale,
205+ view_size,
206+ working_area,
188207 workspaces,
189208 active_workspace_idx: 0,
190209 previous_workspace_id: None,
@@ -795,6 +814,16 @@ impl<W: LayoutElement> Monitor<W> {
795814 self.insert_hint_element.update_shaders();
796815 }
797816
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+
798827 pub fn move_workspace_down(&mut self) {
799828 let mut new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);
800829 if new_idx == self.active_workspace_idx {
@@ -914,8 +943,8 @@ impl<W: LayoutElement> Monitor<W> {
914943 }
915944
916945 pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> {
917- let scale = self.output.current_scale().fractional_scale();
918- let size = output_size(&self.output);
946+ let scale = self.scale.fractional_scale();
947+ let size = self.view_size;
919948
920949 // Ceil the workspace size in physical pixels.
921950 let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale);
@@ -933,8 +962,7 @@ impl<W: LayoutElement> Monitor<W> {
933962 pub fn workspaces_with_render_geo(
934963 &self,
935964 ) -> impl Iterator<Item = (&Workspace<W>, Rectangle<f64, Logical>)> {
936- let output_size = output_size(&self.output);
937- let output_geo = Rectangle::new(Point::from((0., 0.)), output_size);
965+ let output_geo = Rectangle::from_size(self.view_size);
938966
939967 let geo = self.workspaces_render_geo();
940968 zip(self.workspaces.iter(), geo)
@@ -945,8 +973,7 @@ impl<W: LayoutElement> Monitor<W> {
945973 pub fn workspaces_with_render_geo_mut(
946974 &mut self,
947975 ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> {
948- let output_size = output_size(&self.output);
949- let output_geo = Rectangle::new(Point::from((0., 0.)), output_size);
976+ let output_geo = Rectangle::from_size(self.view_size);
950977
951978 let geo = self.workspaces_render_geo();
952979 zip(self.workspaces.iter_mut(), geo)
@@ -958,11 +985,10 @@ impl<W: LayoutElement> Monitor<W> {
958985 &self,
959986 pos_within_output: Point<f64, Logical>,
960987 ) -> Option<(&Workspace<W>, Rectangle<f64, Logical>)> {
961- let size = output_size(&self.output);
962988 let (ws, geo) = self.workspaces_with_render_geo().find_map(|(ws, geo)| {
963989 // Extend width to entire output.
964990 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));
966992 let bounds = Rectangle::new(loc, size);
967993
968994 bounds.contains(pos_within_output).then_some((ws, geo))
@@ -999,10 +1025,9 @@ impl<W: LayoutElement> Monitor<W> {
9991025 ) -> impl Iterator<Item = MonitorRenderElement<R>> + 'a {
10001026 let _span = tracy_client::span!("Monitor::render_elements");
10011027
1002- let scale = self.output.current_scale().fractional_scale();
1003- let size = output_size(&self.output);
1028+ let scale = self.scale.fractional_scale();
10041029 // 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;
10061031
10071032 // Crop the elements to prevent them overflowing, currently visible during a workspace
10081033 // switch.
@@ -1176,4 +1201,16 @@ impl<W: LayoutElement> Monitor<W> {
11761201
11771202 true
11781203 }
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+ }
11791216 }
src/layout/workspace.rsmodified+5 -1
@@ -1708,6 +1708,10 @@ impl<W: LayoutElement> Workspace<W> {
17081708 self.floating.logical_to_size_frac(logical_pos)
17091709 }
17101710
1711+ pub fn working_area(&self) -> Rectangle<f64, Logical> {
1712+ self.working_area
1713+ }
1714+
17111715 #[cfg(test)]
17121716 pub fn scrolling(&self) -> &ScrollingSpace<W> {
17131717 &self.scrolling
@@ -1777,6 +1781,6 @@ impl<W: LayoutElement> Workspace<W> {
17771781 }
17781782 }
17791783
1780-fn compute_working_area(output: &Output) -> Rectangle<f64, Logical> {
1784+pub(super) fn compute_working_area(output: &Output) -> Rectangle<f64, Logical> {
17811785 layer_map_for_output(output).non_exclusive_zone().to_f64()
17821786 }