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