diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-21 11:08:48 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-21 11:08:48 +0400 |
| commit | 646e3d89951e576a2e89ac121c521b4a7c3fced8 (patch) | |
| tree | ce711d7453cd74b67431a38cdfc023bd61962495 /src/layout | |
| parent | d1fe6930a7bc5b78b0f005c2105c92094fc4ec52 (diff) | |
| download | niri-646e3d89951e576a2e89ac121c521b4a7c3fced8.tar.gz niri-646e3d89951e576a2e89ac121c521b4a7c3fced8.tar.bz2 niri-646e3d89951e576a2e89ac121c521b4a7c3fced8.zip | |
Accept location in FocusRing
Makes it work more like other elements.
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/focus_ring.rs | 27 | ||||
| -rw-r--r-- | src/layout/tile.rs | 47 |
2 files changed, 26 insertions, 48 deletions
diff --git a/src/layout/focus_ring.rs b/src/layout/focus_ring.rs index 6e2730b8..4f55fe0c 100644 --- a/src/layout/focus_ring.rs +++ b/src/layout/focus_ring.rs @@ -39,26 +39,21 @@ impl FocusRing { self.inactive_color = config.inactive_color; } - pub fn update( - &mut self, - win_pos: Point<i32, Logical>, - win_size: Size<i32, Logical>, - is_border: bool, - ) { + pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) { if is_border { self.buffers[0].resize((win_size.w + self.width * 2, self.width)); self.buffers[1].resize((win_size.w + self.width * 2, self.width)); self.buffers[2].resize((self.width, win_size.h)); self.buffers[3].resize((self.width, win_size.h)); - self.locations[0] = win_pos + Point::from((-self.width, -self.width)); - self.locations[1] = win_pos + Point::from((-self.width, win_size.h)); - self.locations[2] = win_pos + Point::from((-self.width, 0)); - self.locations[3] = win_pos + Point::from((win_size.w, 0)); + self.locations[0] = Point::from((-self.width, -self.width)); + self.locations[1] = Point::from((-self.width, win_size.h)); + self.locations[2] = Point::from((-self.width, 0)); + self.locations[3] = Point::from((win_size.w, 0)); } else { let size = win_size + Size::from((self.width * 2, self.width * 2)); self.buffers[0].resize(size); - self.locations[0] = win_pos - Point::from((self.width, self.width)); + self.locations[0] = Point::from((-self.width, -self.width)); } self.is_border = is_border; @@ -76,7 +71,11 @@ impl FocusRing { } } - pub fn render(&self, scale: Scale<f64>) -> impl Iterator<Item = FocusRingRenderElement> { + pub fn render( + &self, + location: Point<i32, Logical>, + scale: Scale<f64>, + ) -> impl Iterator<Item = FocusRingRenderElement> { let mut rv = ArrayVec::<_, 4>::new(); if self.is_off { @@ -96,10 +95,10 @@ impl FocusRing { if self.is_border { for (buf, loc) in zip(&self.buffers, self.locations) { - push(buf, loc); + push(buf, location + loc); } } else { - push(&self.buffers[0], self.locations[0]); + push(&self.buffers[0], location + self.locations[0]); } rv.into_iter() diff --git a/src/layout/tile.rs b/src/layout/tile.rs index fa1d1e5d..28bcfb47 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -3,9 +3,7 @@ use std::rc::Rc; use std::time::Duration; use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; -use smithay::backend::renderer::element::utils::{ - Relocate, RelocateRenderElement, RescaleRenderElement, -}; +use smithay::backend::renderer::element::utils::RescaleRenderElement; use smithay::backend::renderer::element::{Element, Kind}; use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; @@ -53,7 +51,7 @@ pub struct Tile<W: LayoutElement> { niri_render_elements! { TileRenderElement<R> => { LayoutElement = LayoutElementRenderElement<R>, - SolidColor = RelocateRenderElement<SolidColorRenderElement>, + SolidColor = SolidColorRenderElement, Offscreen = RescaleRenderElement<OffscreenRenderElement>, } } @@ -86,16 +84,11 @@ impl<W: LayoutElement> Tile<W> { } pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) { - let width = self.border.width(); - self.border.update( - (width, width).into(), - self.window.size(), - self.window.has_ssd(), - ); + self.border + .update(self.window.size(), self.window.has_ssd()); self.border.set_active(is_active); - self.focus_ring - .update((0, 0).into(), self.tile_size(), self.has_ssd()); + self.focus_ring.update(self.tile_size(), self.has_ssd()); self.focus_ring.set_active(is_active); match &mut self.open_animation { @@ -312,39 +305,25 @@ impl<W: LayoutElement> Tile<W> { .into_iter() .map(Into::into); - let elem = self.effective_border_width().map(|_| { - self.border.render(scale).map(move |elem| { - RelocateRenderElement::from_element( - elem, - location.to_physical_precise_round(scale), - Relocate::Relative, - ) - .into() - }) + let elem = self.effective_border_width().map(|width| { + self.border + .render(location + Point::from((width, width)), scale) + .map(Into::into) }); let rv = rv.chain(elem.into_iter().flatten()); - let elem = focus_ring.then(|| { - self.focus_ring.render(scale).map(move |elem| { - RelocateRenderElement::from_element( - elem, - location.to_physical_precise_round(scale), - Relocate::Relative, - ) - .into() - }) - }); + let elem = focus_ring.then(|| self.focus_ring.render(location, scale).map(Into::into)); let rv = rv.chain(elem.into_iter().flatten()); let elem = self.is_fullscreen.then(|| { - let elem = SolidColorRenderElement::from_buffer( + SolidColorRenderElement::from_buffer( &self.fullscreen_backdrop, location.to_physical_precise_round(scale), scale, 1., Kind::Unspecified, - ); - RelocateRenderElement::from_element(elem, (0, 0), Relocate::Relative).into() + ) + .into() }); rv.chain(elem) } |
