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