focus-ring: Store config instead of individual fields
Browse files at this commitd1b8134337effeb146d5111e477c3ca5ca917d66Parent: 646e3d81 changed file +22 -29
- src/layout/focus_ring.rs +22 -29
src/layout/focus_ring.rsmodified+22 -29
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::iter::zip; |
| 2 | 2 | |
| 3 | 3 | use arrayvec::ArrayVec; |
| 4 | -use niri_config::{self, Color}; | |
| 4 | +use niri_config; | |
| 5 | 5 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; |
| 6 | 6 | use smithay::backend::renderer::element::Kind; |
| 7 | 7 | use smithay::utils::{Logical, Point, Scale, Size}; |
| @@ -10,11 +10,8 @@ use smithay::utils::{Logical, Point, Scale, Size}; | ||
| 10 | 10 | pub struct FocusRing { |
| 11 | 11 | buffers: [SolidColorBuffer; 4], |
| 12 | 12 | locations: [Point<i32, Logical>; 4], |
| 13 | - is_off: bool, | |
| 14 | 13 | is_border: bool, |
| 15 | - width: i32, | |
| 16 | - active_color: Color, | |
| 17 | - inactive_color: Color, | |
| 14 | + config: niri_config::FocusRing, | |
| 18 | 15 | } |
| 19 | 16 | |
| 20 | 17 | pub type FocusRingRenderElement = SolidColorRenderElement; |
| @@ -24,36 +21,32 @@ impl FocusRing { | ||
| 24 | 21 | Self { |
| 25 | 22 | buffers: Default::default(), |
| 26 | 23 | locations: Default::default(), |
| 27 | - is_off: config.off, | |
| 28 | 24 | is_border: false, |
| 29 | - width: config.width.into(), | |
| 30 | - active_color: config.active_color, | |
| 31 | - inactive_color: config.inactive_color, | |
| 25 | + config, | |
| 32 | 26 | } |
| 33 | 27 | } |
| 34 | 28 | |
| 35 | 29 | pub fn update_config(&mut self, config: niri_config::FocusRing) { |
| 36 | - self.is_off = config.off; | |
| 37 | - self.width = config.width.into(); | |
| 38 | - self.active_color = config.active_color; | |
| 39 | - self.inactive_color = config.inactive_color; | |
| 30 | + self.config = config; | |
| 40 | 31 | } |
| 41 | 32 | |
| 42 | 33 | pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) { |
| 34 | + let width = i32::from(self.config.width); | |
| 35 | + | |
| 43 | 36 | if is_border { |
| 44 | - self.buffers[0].resize((win_size.w + self.width * 2, self.width)); | |
| 45 | - self.buffers[1].resize((win_size.w + self.width * 2, self.width)); | |
| 46 | - self.buffers[2].resize((self.width, win_size.h)); | |
| 47 | - self.buffers[3].resize((self.width, win_size.h)); | |
| 48 | - | |
| 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)); | |
| 37 | + self.buffers[0].resize((win_size.w + width * 2, width)); | |
| 38 | + self.buffers[1].resize((win_size.w + width * 2, width)); | |
| 39 | + self.buffers[2].resize((width, win_size.h)); | |
| 40 | + self.buffers[3].resize((width, win_size.h)); | |
| 41 | + | |
| 42 | + self.locations[0] = Point::from((-width, -width)); | |
| 43 | + self.locations[1] = Point::from((-width, win_size.h)); | |
| 44 | + self.locations[2] = Point::from((-width, 0)); | |
| 52 | 45 | self.locations[3] = Point::from((win_size.w, 0)); |
| 53 | 46 | } else { |
| 54 | - let size = win_size + Size::from((self.width * 2, self.width * 2)); | |
| 47 | + let size = win_size + Size::from((width * 2, width * 2)); | |
| 55 | 48 | self.buffers[0].resize(size); |
| 56 | - self.locations[0] = Point::from((-self.width, -self.width)); | |
| 49 | + self.locations[0] = Point::from((-width, -width)); | |
| 57 | 50 | } |
| 58 | 51 | |
| 59 | 52 | self.is_border = is_border; |
| @@ -61,9 +54,9 @@ impl FocusRing { | ||
| 61 | 54 | |
| 62 | 55 | pub fn set_active(&mut self, is_active: bool) { |
| 63 | 56 | let color = if is_active { |
| 64 | - self.active_color.into() | |
| 57 | + self.config.active_color.into() | |
| 65 | 58 | } else { |
| 66 | - self.inactive_color.into() | |
| 59 | + self.config.inactive_color.into() | |
| 67 | 60 | }; |
| 68 | 61 | |
| 69 | 62 | for buf in &mut self.buffers { |
| @@ -78,7 +71,7 @@ impl FocusRing { | ||
| 78 | 71 | ) -> impl Iterator<Item = FocusRingRenderElement> { |
| 79 | 72 | let mut rv = ArrayVec::<_, 4>::new(); |
| 80 | 73 | |
| 81 | - if self.is_off { | |
| 74 | + if self.config.off { | |
| 82 | 75 | return rv.into_iter(); |
| 83 | 76 | } |
| 84 | 77 | |
| @@ -90,7 +83,7 @@ impl FocusRing { | ||
| 90 | 83 | 1., |
| 91 | 84 | Kind::Unspecified, |
| 92 | 85 | ); |
| 93 | - rv.push(elem); | |
| 86 | + rv.push(elem.into()); | |
| 94 | 87 | }; |
| 95 | 88 | |
| 96 | 89 | if self.is_border { |
| @@ -105,10 +98,10 @@ impl FocusRing { | ||
| 105 | 98 | } |
| 106 | 99 | |
| 107 | 100 | pub fn width(&self) -> i32 { |
| 108 | - self.width | |
| 101 | + self.config.width.into() | |
| 109 | 102 | } |
| 110 | 103 | |
| 111 | 104 | pub fn is_off(&self) -> bool { |
| 112 | - self.is_off | |
| 105 | + self.config.off | |
| 113 | 106 | } |
| 114 | 107 | } |