Accept location in FocusRing
Browse files at this commit646e3d89951e576a2e89ac121c521b4a7c3fced8Parent: d1fe6932 changed files +26 -48
- src/layout/focus_ring.rs +13 -14
- src/layout/tile.rs +13 -34
src/layout/focus_ring.rsmodified+13 -14
| @@ -39,26 +39,21 @@ impl FocusRing { | ||
| 39 | 39 | self.inactive_color = config.inactive_color; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - pub fn update( | |
| 43 | - &mut self, | |
| 44 | - win_pos: Point<i32, Logical>, | |
| 45 | - win_size: Size<i32, Logical>, | |
| 46 | - is_border: bool, | |
| 47 | - ) { | |
| 42 | + pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) { | |
| 48 | 43 | if is_border { |
| 49 | 44 | self.buffers[0].resize((win_size.w + self.width * 2, self.width)); |
| 50 | 45 | self.buffers[1].resize((win_size.w + self.width * 2, self.width)); |
| 51 | 46 | self.buffers[2].resize((self.width, win_size.h)); |
| 52 | 47 | self.buffers[3].resize((self.width, win_size.h)); |
| 53 | 48 | |
| 54 | - self.locations[0] = win_pos + Point::from((-self.width, -self.width)); | |
| 55 | - self.locations[1] = win_pos + Point::from((-self.width, win_size.h)); | |
| 56 | - self.locations[2] = win_pos + Point::from((-self.width, 0)); | |
| 57 | - self.locations[3] = win_pos + Point::from((win_size.w, 0)); | |
| 49 | + self.locations[0] = Point::from((-self.width, -self.width)); | |
| 50 | + self.locations[1] = Point::from((-self.width, win_size.h)); | |
| 51 | + self.locations[2] = Point::from((-self.width, 0)); | |
| 52 | + self.locations[3] = Point::from((win_size.w, 0)); | |
| 58 | 53 | } else { |
| 59 | 54 | let size = win_size + Size::from((self.width * 2, self.width * 2)); |
| 60 | 55 | self.buffers[0].resize(size); |
| 61 | - self.locations[0] = win_pos - Point::from((self.width, self.width)); | |
| 56 | + self.locations[0] = Point::from((-self.width, -self.width)); | |
| 62 | 57 | } |
| 63 | 58 | |
| 64 | 59 | self.is_border = is_border; |
| @@ -76,7 +71,11 @@ impl FocusRing { | ||
| 76 | 71 | } |
| 77 | 72 | } |
| 78 | 73 | |
| 79 | - pub fn render(&self, scale: Scale<f64>) -> impl Iterator<Item = FocusRingRenderElement> { | |
| 74 | + pub fn render( | |
| 75 | + &self, | |
| 76 | + location: Point<i32, Logical>, | |
| 77 | + scale: Scale<f64>, | |
| 78 | + ) -> impl Iterator<Item = FocusRingRenderElement> { | |
| 80 | 79 | let mut rv = ArrayVec::<_, 4>::new(); |
| 81 | 80 | |
| 82 | 81 | if self.is_off { |
| @@ -96,10 +95,10 @@ impl FocusRing { | ||
| 96 | 95 | |
| 97 | 96 | if self.is_border { |
| 98 | 97 | for (buf, loc) in zip(&self.buffers, self.locations) { |
| 99 | - push(buf, loc); | |
| 98 | + push(buf, location + loc); | |
| 100 | 99 | } |
| 101 | 100 | } else { |
| 102 | - push(&self.buffers[0], self.locations[0]); | |
| 101 | + push(&self.buffers[0], location + self.locations[0]); | |
| 103 | 102 | } |
| 104 | 103 | |
| 105 | 104 | rv.into_iter() |
src/layout/tile.rsmodified+13 -34
| @@ -3,9 +3,7 @@ use std::rc::Rc; | ||
| 3 | 3 | use std::time::Duration; |
| 4 | 4 | |
| 5 | 5 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; |
| 6 | -use smithay::backend::renderer::element::utils::{ | |
| 7 | - Relocate, RelocateRenderElement, RescaleRenderElement, | |
| 8 | -}; | |
| 6 | +use smithay::backend::renderer::element::utils::RescaleRenderElement; | |
| 9 | 7 | use smithay::backend::renderer::element::{Element, Kind}; |
| 10 | 8 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; |
| 11 | 9 | |
| @@ -53,7 +51,7 @@ pub struct Tile<W: LayoutElement> { | ||
| 53 | 51 | niri_render_elements! { |
| 54 | 52 | TileRenderElement<R> => { |
| 55 | 53 | LayoutElement = LayoutElementRenderElement<R>, |
| 56 | - SolidColor = RelocateRenderElement<SolidColorRenderElement>, | |
| 54 | + SolidColor = SolidColorRenderElement, | |
| 57 | 55 | Offscreen = RescaleRenderElement<OffscreenRenderElement>, |
| 58 | 56 | } |
| 59 | 57 | } |
| @@ -86,16 +84,11 @@ impl<W: LayoutElement> Tile<W> { | ||
| 86 | 84 | } |
| 87 | 85 | |
| 88 | 86 | pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) { |
| 89 | - let width = self.border.width(); | |
| 90 | - self.border.update( | |
| 91 | - (width, width).into(), | |
| 92 | - self.window.size(), | |
| 93 | - self.window.has_ssd(), | |
| 94 | - ); | |
| 87 | + self.border | |
| 88 | + .update(self.window.size(), self.window.has_ssd()); | |
| 95 | 89 | self.border.set_active(is_active); |
| 96 | 90 | |
| 97 | - self.focus_ring | |
| 98 | - .update((0, 0).into(), self.tile_size(), self.has_ssd()); | |
| 91 | + self.focus_ring.update(self.tile_size(), self.has_ssd()); | |
| 99 | 92 | self.focus_ring.set_active(is_active); |
| 100 | 93 | |
| 101 | 94 | match &mut self.open_animation { |
| @@ -312,39 +305,25 @@ impl<W: LayoutElement> Tile<W> { | ||
| 312 | 305 | .into_iter() |
| 313 | 306 | .map(Into::into); |
| 314 | 307 | |
| 315 | - let elem = self.effective_border_width().map(|_| { | |
| 316 | - self.border.render(scale).map(move |elem| { | |
| 317 | - RelocateRenderElement::from_element( | |
| 318 | - elem, | |
| 319 | - location.to_physical_precise_round(scale), | |
| 320 | - Relocate::Relative, | |
| 321 | - ) | |
| 322 | - .into() | |
| 323 | - }) | |
| 308 | + let elem = self.effective_border_width().map(|width| { | |
| 309 | + self.border | |
| 310 | + .render(location + Point::from((width, width)), scale) | |
| 311 | + .map(Into::into) | |
| 324 | 312 | }); |
| 325 | 313 | let rv = rv.chain(elem.into_iter().flatten()); |
| 326 | 314 | |
| 327 | - let elem = focus_ring.then(|| { | |
| 328 | - self.focus_ring.render(scale).map(move |elem| { | |
| 329 | - RelocateRenderElement::from_element( | |
| 330 | - elem, | |
| 331 | - location.to_physical_precise_round(scale), | |
| 332 | - Relocate::Relative, | |
| 333 | - ) | |
| 334 | - .into() | |
| 335 | - }) | |
| 336 | - }); | |
| 315 | + let elem = focus_ring.then(|| self.focus_ring.render(location, scale).map(Into::into)); | |
| 337 | 316 | let rv = rv.chain(elem.into_iter().flatten()); |
| 338 | 317 | |
| 339 | 318 | let elem = self.is_fullscreen.then(|| { |
| 340 | - let elem = SolidColorRenderElement::from_buffer( | |
| 319 | + SolidColorRenderElement::from_buffer( | |
| 341 | 320 | &self.fullscreen_backdrop, |
| 342 | 321 | location.to_physical_precise_round(scale), |
| 343 | 322 | scale, |
| 344 | 323 | 1., |
| 345 | 324 | Kind::Unspecified, |
| 346 | - ); | |
| 347 | - RelocateRenderElement::from_element(elem, (0, 0), Relocate::Relative).into() | |
| 325 | + ) | |
| 326 | + .into() | |
| 348 | 327 | }); |
| 349 | 328 | rv.chain(elem) |
| 350 | 329 | } |