diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-04 10:14:51 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-01-04 11:22:56 +0300 |
| commit | a2f9d132a088e399fb1f292d84d3d3862127f02e (patch) | |
| tree | 0e04941d8ae35be9362c53f8d41177cc71e24214 /src/layout | |
| parent | 1973b97cc2a51d697add3d9ad7210a4e6eba9183 (diff) | |
| download | niri-a2f9d132a088e399fb1f292d84d3d3862127f02e.tar.gz niri-a2f9d132a088e399fb1f292d84d3d3862127f02e.tar.bz2 niri-a2f9d132a088e399fb1f292d84d3d3862127f02e.zip | |
Migrate to new Rectangle functions
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/floating.rs | 4 | ||||
| -rw-r--r-- | src/layout/focus_ring.rs | 13 | ||||
| -rw-r--r-- | src/layout/mod.rs | 14 | ||||
| -rw-r--r-- | src/layout/monitor.rs | 16 | ||||
| -rw-r--r-- | src/layout/opening_window.rs | 2 | ||||
| -rw-r--r-- | src/layout/scrolling.rs | 22 | ||||
| -rw-r--r-- | src/layout/tile.rs | 12 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 8 |
8 files changed, 46 insertions, 45 deletions
diff --git a/src/layout/floating.rs b/src/layout/floating.rs index 1453415c..3705f9ef 100644 --- a/src/layout/floating.rs +++ b/src/layout/floating.rs @@ -330,7 +330,7 @@ impl<W: LayoutElement> FloatingSpace<W> { let (tile, offset) = self.tiles_with_offsets().next()?; let tile_size = tile.tile_size(); - let tile_rect = Rectangle::from_loc_and_size(offset, tile_size); + let tile_rect = Rectangle::new(offset, tile_size); self.working_area.intersection(tile_rect) } @@ -1105,7 +1105,7 @@ impl<W: LayoutElement> FloatingSpace<W> { pos: Point<f64, Logical>, size: Size<f64, Logical>, ) -> Point<f64, Logical> { - let mut rect = Rectangle::from_loc_and_size(pos, size); + let mut rect = Rectangle::new(pos, size); clamp_preferring_top_left_in_area(self.working_area, &mut rect); rect.loc } diff --git a/src/layout/focus_ring.rs b/src/layout/focus_ring.rs index 7cd73760..b6c65b3f 100644 --- a/src/layout/focus_ring.rs +++ b/src/layout/focus_ring.rs @@ -94,7 +94,7 @@ impl FocusRing { in_: GradientInterpolation::default(), }); - let full_rect = Rectangle::from_loc_and_size((-width, -width), self.full_size); + let full_rect = Rectangle::new(Point::from((-width, -width)), self.full_size); let gradient_area = match gradient.relative_to { GradientRelativeTo::Window => full_rect, GradientRelativeTo::WorkspaceView => view_rect, @@ -178,12 +178,12 @@ impl FocusRing { for (border, (loc, size)) in zip(&mut self.borders, zip(self.locations, self.sizes)) { border.update( size, - Rectangle::from_loc_and_size(gradient_area.loc - loc, gradient_area.size), + Rectangle::new(gradient_area.loc - loc, gradient_area.size), gradient.in_, gradient.from, gradient.to, ((gradient.angle as f32) - 90.).to_radians(), - Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size), + Rectangle::new(full_rect.loc - loc, full_rect.size), rounded_corner_border_width, radius, scale as f32, @@ -196,15 +196,12 @@ impl FocusRing { self.borders[0].update( self.sizes[0], - Rectangle::from_loc_and_size( - gradient_area.loc - self.locations[0], - gradient_area.size, - ), + Rectangle::new(gradient_area.loc - self.locations[0], gradient_area.size), gradient.in_, gradient.from, gradient.to, ((gradient.angle as f32) - 90.).to_radians(), - Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size), + Rectangle::new(full_rect.loc - self.locations[0], full_rect.size), rounded_corner_border_width, radius, scale as f32, diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 081a5f35..4923282b 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1289,7 +1289,7 @@ impl<W: LayoutElement> Layout<W> { // window geometry. let width = move_.tile.window_size().w; let height = output_size(&move_.output).h; - let mut target = Rectangle::from_loc_and_size((0., 0.), (width, height)); + let mut target = Rectangle::from_size(Size::from((width, height))); // FIXME: ideally this shouldn't include the tile render offset, but the code // duplication would be a bit annoying for this edge case. target.loc.y -= move_.tile_render_location().y; @@ -2405,10 +2405,8 @@ impl<W: LayoutElement> Layout<W> { if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { if output.map_or(true, |output| move_.output == *output) { let pos_within_output = move_.tile_render_location(); - let view_rect = Rectangle::from_loc_and_size( - pos_within_output.upscale(-1.), - output_size(&move_.output), - ); + let view_rect = + Rectangle::new(pos_within_output.upscale(-1.), output_size(&move_.output)); move_.tile.update(true, view_rect); } } @@ -4121,7 +4119,7 @@ mod tests { id, parent_id: None, is_floating: false, - bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), + bbox: Rectangle::from_size(Size::from((100, 200))), min_max_size: Default::default(), } } @@ -4295,7 +4293,7 @@ mod tests { any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| { let loc: Point<i32, _> = Point::from((x.into(), y.into())); let size: Size<i32, _> = Size::from((w.max(1).into(), h.max(1).into())); - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) }) } @@ -6078,7 +6076,7 @@ mod tests { Op::AddWindow { params: TestWindowParams { - bbox: Rectangle::from_loc_and_size((0, 0), (1280, 200)), + bbox: Rectangle::from_size(Size::from((1280, 200))), ..TestWindowParams::new(1) }, } diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 13079319..2de3c760 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -7,7 +7,7 @@ use smithay::backend::renderer::element::utils::{ CropRenderElement, Relocate, RelocateRenderElement, }; use smithay::output::Output; -use smithay::utils::{Logical, Point, Rectangle}; +use smithay::utils::{Logical, Point, Rectangle, Size}; use super::scrolling::{Column, ColumnWidth}; use super::tile::Tile; @@ -871,7 +871,7 @@ impl<W: LayoutElement> Monitor<W> { let offset = switch.target_idx() - self.active_workspace_idx as f64; let offset = offset * size.h; - let clip_rect = Rectangle::from_loc_and_size((0., -offset), size); + let clip_rect = Rectangle::new(Point::from((0., -offset)), size); rect = rect.intersection(clip_rect)?; } @@ -930,7 +930,7 @@ impl<W: LayoutElement> Monitor<W> { let size = output_size(&self.output); let (ws, bounds) = self .workspaces_with_render_positions() - .map(|(ws, offset)| (ws, Rectangle::from_loc_and_size(offset, size))) + .map(|(ws, offset)| (ws, Rectangle::new(offset, size))) .find(|(_, bounds)| bounds.contains(pos_within_output))?; Some((ws, bounds.loc)) } @@ -983,9 +983,15 @@ impl<W: LayoutElement> Monitor<W> { // // FIXME: use proper bounds after fixing the Crop element. let crop_bounds = if self.workspace_switch.is_some() { - Rectangle::from_loc_and_size((-i32::MAX / 2, 0), (i32::MAX, height)) + Rectangle::new( + Point::from((-i32::MAX / 2, 0)), + Size::from((i32::MAX, height)), + ) } else { - Rectangle::from_loc_and_size((-i32::MAX / 2, -i32::MAX / 2), (i32::MAX, i32::MAX)) + Rectangle::new( + Point::from((-i32::MAX / 2, -i32::MAX / 2)), + Size::from((i32::MAX, i32::MAX)), + ) }; self.workspaces_with_render_positions() diff --git a/src/layout/opening_window.rs b/src/layout/opening_window.rs index 0a3d4973..f64aef88 100644 --- a/src/layout/opening_window.rs +++ b/src/layout/opening_window.rs @@ -72,7 +72,7 @@ impl OpenAnimation { let texture_size = geo.size.to_f64().to_logical(scale); if Shaders::get(renderer).program(ProgramType::Open).is_some() { - let mut area = Rectangle::from_loc_and_size(location + offset, texture_size); + let mut area = Rectangle::new(location + offset, texture_size); // Expand the area a bit to allow for more varied effects. let mut target_size = area.size.upscale(1.5); diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index bdafdb71..89975736 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -335,13 +335,13 @@ impl<W: LayoutElement> ScrollingSpace<W> { let is_active = is_active && col_idx == active_idx; let col_off = Point::from((col_x, 0.)); let col_pos = view_pos - col_off - col.render_offset(); - let view_rect = Rectangle::from_loc_and_size(col_pos, view_size); + let view_rect = Rectangle::new(col_pos, view_size); col.update_render_elements(is_active, view_rect); } if let Some(insert_hint) = &self.insert_hint { if let Some(area) = self.insert_hint_area(insert_hint) { - let view_rect = Rectangle::from_loc_and_size(area.loc.upscale(-1.), view_size); + let view_rect = Rectangle::new(area.loc.upscale(-1.), view_size); self.insert_hint_element.update_render_elements( area.size, view_rect, @@ -1919,7 +1919,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { if column_index == 0 && !self.columns.is_empty() { loc.x -= size.w + self.options.gaps; } - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) } else if column_index > self.columns.len() { error!("insert hint column index is out of range"); return None; @@ -1930,7 +1930,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { self.column_x(column_index) - size.w / 2. - self.options.gaps / 2., self.working_area.loc.y + self.options.gaps, )); - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) } } InsertPosition::InColumn(column_index, tile_index) => { @@ -1963,7 +1963,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { let size = Size::from((self.data[column_index].width, height)); let loc = Point::from((self.column_x(column_index), y)); - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) } InsertPosition::Floating => return None, }; @@ -2010,9 +2010,9 @@ impl<W: LayoutElement> ScrollingSpace<W> { let tile_pos = view_off + tile_off; let tile_size = tile.tile_size(); - let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size); + let tile_rect = Rectangle::new(tile_pos, tile_size); - let view = Rectangle::from_loc_and_size((0., 0.), self.view_size); + let view = Rectangle::from_size(self.view_size); view.intersection(tile_rect) } @@ -2256,7 +2256,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { } // Draw the closing windows on top of the other windows. - let view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0.), self.view_size); + let view_rect = Rectangle::new(Point::from((self.view_pos(), 0.)), self.view_size); for closing in self.closing_windows.iter().rev() { let elem = closing.render(renderer.as_gles_renderer(), view_rect, scale, target); rv.push(elem.into()); @@ -3731,7 +3731,7 @@ impl<W: LayoutElement> Column<W> { let width = tile.window_size().w; let height = self.view_size.h; - let mut target = Rectangle::from_loc_and_size((0., 0.), (width, height)); + let mut target = Rectangle::from_size(Size::from((width, height))); target.loc.y -= pos.y; target.loc.y -= tile.window_loc().y; @@ -4028,7 +4028,7 @@ mod tests { bottom: FloatOrInt(1.), }; - let parent_area = Rectangle::from_loc_and_size((0., 0.), (1280., 720.)); + let parent_area = Rectangle::from_size(Size::from((1280., 720.))); let area = compute_working_area(parent_area, 1., struts); assert_eq!(round_logical_in_physical(1., area.loc.x), area.loc.x); @@ -4044,7 +4044,7 @@ mod tests { bottom: FloatOrInt(0.), }; - let parent_area = Rectangle::from_loc_and_size((0., 0.), (1280., 720.)); + let parent_area = Rectangle::from_size(Size::from((1280., 720.))); compute_working_area(parent_area, 1., struts); } } diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 96936d26..163dd673 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -318,7 +318,7 @@ impl<W: LayoutElement> Tile<W> { self.animated_window_size(), is_active, !draw_border_with_background, - Rectangle::from_loc_and_size( + Rectangle::new( view_rect.loc - Point::from((border_width, border_width)), view_rect.size, ), @@ -590,7 +590,7 @@ impl<W: LayoutElement> Tile<W> { } pub fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool { - let activation_region = Rectangle::from_loc_and_size((0., 0.), self.tile_size()); + let activation_region = Rectangle::from_size(self.tile_size()); activation_region.contains(point) } @@ -711,7 +711,7 @@ impl<W: LayoutElement> Tile<W> { let window_size = self.window_size().to_f64(); let animated_window_size = self.animated_window_size(); let window_render_loc = location + window_loc; - let area = Rectangle::from_loc_and_size(window_render_loc, animated_window_size); + let area = Rectangle::new(window_render_loc, animated_window_size); let rules = self.window.rules(); let clip_to_geometry = !self.is_fullscreen && rules.clip_to_geometry == Some(true); @@ -810,7 +810,7 @@ impl<W: LayoutElement> Tile<W> { .window .render(renderer, window_render_loc, scale, alpha, target); - let geo = Rectangle::from_loc_and_size(window_render_loc, window_size); + let geo = Rectangle::new(window_render_loc, window_size); let radius = radius.fit_to(window_size.w as f32, window_size.h as f32); let clip_shader = ClippedSurfaceRenderElement::shader(renderer).cloned(); @@ -852,12 +852,12 @@ impl<W: LayoutElement> Tile<W> { if radius != CornerRadius::default() && has_border_shader { return BorderRenderElement::new( geo.size, - Rectangle::from_loc_and_size((0., 0.), geo.size), + Rectangle::from_size(geo.size), GradientInterpolation::default(), Color::from_color32f(elem.color()), Color::from_color32f(elem.color()), 0., - Rectangle::from_loc_and_size((0., 0.), geo.size), + Rectangle::from_size(geo.size), 0., radius, scale.x as f32, diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 25a03987..b11b46ac 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -260,7 +260,7 @@ impl<W: LayoutElement> Workspace<W> { Rc::new(Options::clone(&base_options).adjusted_for_scale(scale.fractional_scale())); let view_size = Size::from((1280., 720.)); - let working_area = Rectangle::from_loc_and_size((0., 0.), (1280., 720.)); + let working_area = Rectangle::from_size(Size::from((1280., 720.))); let scrolling = ScrollingSpace::new( view_size, @@ -337,7 +337,7 @@ impl<W: LayoutElement> Workspace<W> { self.scrolling .update_render_elements(is_active && !self.floating_is_active.get()); - let view_rect = Rectangle::from_loc_and_size((0., 0.), self.view_size); + let view_rect = Rectangle::from_size(self.view_size); self.floating .update_render_elements(is_active && self.floating_is_active.get(), view_rect); } @@ -1332,7 +1332,7 @@ impl<W: LayoutElement> Workspace<W> { let floating_focus_ring = focus_ring && self.floating_is_active(); let floating = self.is_floating_visible().then(|| { - let view_rect = Rectangle::from_loc_and_size((0., 0.), self.view_size); + let view_rect = Rectangle::from_size(self.view_size); let floating = self.floating.render_elements( renderer, view_rect, @@ -1364,7 +1364,7 @@ impl<W: LayoutElement> Workspace<W> { for (tile, tile_pos) in self.tiles_with_render_positions_mut(false) { if tile.window().id() == window { let view_pos = Point::from((-tile_pos.x, -tile_pos.y)); - let view_rect = Rectangle::from_loc_and_size(view_pos, view_size); + let view_rect = Rectangle::new(view_pos, view_size); tile.update(false, view_rect); tile.store_unmap_snapshot_if_empty(renderer, output_scale); return; |
