forge
Explore
Log in

Don't you dare go Hollow

focus-ring: Store config instead of individual fields

Browse files at this commit

d1b8134337effeb146d5111e477c3ca5ca917d66Ivan MolodetskikhParent: 646e3d8
src/layout/focus_ring.rsmodified+22 -29
@@ -1,7 +1,7 @@
11 use std::iter::zip;
22
33 use arrayvec::ArrayVec;
4-use niri_config::{self, Color};
4+use niri_config;
55 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
66 use smithay::backend::renderer::element::Kind;
77 use smithay::utils::{Logical, Point, Scale, Size};
@@ -10,11 +10,8 @@ use smithay::utils::{Logical, Point, Scale, Size};
1010 pub struct FocusRing {
1111 buffers: [SolidColorBuffer; 4],
1212 locations: [Point<i32, Logical>; 4],
13- is_off: bool,
1413 is_border: bool,
15- width: i32,
16- active_color: Color,
17- inactive_color: Color,
14+ config: niri_config::FocusRing,
1815 }
1916
2017 pub type FocusRingRenderElement = SolidColorRenderElement;
@@ -24,36 +21,32 @@ impl FocusRing {
2421 Self {
2522 buffers: Default::default(),
2623 locations: Default::default(),
27- is_off: config.off,
2824 is_border: false,
29- width: config.width.into(),
30- active_color: config.active_color,
31- inactive_color: config.inactive_color,
25+ config,
3226 }
3327 }
3428
3529 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;
4031 }
4132
4233 pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) {
34+ let width = i32::from(self.config.width);
35+
4336 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));
5245 self.locations[3] = Point::from((win_size.w, 0));
5346 } 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));
5548 self.buffers[0].resize(size);
56- self.locations[0] = Point::from((-self.width, -self.width));
49+ self.locations[0] = Point::from((-width, -width));
5750 }
5851
5952 self.is_border = is_border;
@@ -61,9 +54,9 @@ impl FocusRing {
6154
6255 pub fn set_active(&mut self, is_active: bool) {
6356 let color = if is_active {
64- self.active_color.into()
57+ self.config.active_color.into()
6558 } else {
66- self.inactive_color.into()
59+ self.config.inactive_color.into()
6760 };
6861
6962 for buf in &mut self.buffers {
@@ -78,7 +71,7 @@ impl FocusRing {
7871 ) -> impl Iterator<Item = FocusRingRenderElement> {
7972 let mut rv = ArrayVec::<_, 4>::new();
8073
81- if self.is_off {
74+ if self.config.off {
8275 return rv.into_iter();
8376 }
8477
@@ -90,7 +83,7 @@ impl FocusRing {
9083 1.,
9184 Kind::Unspecified,
9285 );
93- rv.push(elem);
86+ rv.push(elem.into());
9487 };
9588
9689 if self.is_border {
@@ -105,10 +98,10 @@ impl FocusRing {
10598 }
10699
107100 pub fn width(&self) -> i32 {
108- self.width
101+ self.config.width.into()
109102 }
110103
111104 pub fn is_off(&self) -> bool {
112- self.is_off
105+ self.config.off
113106 }
114107 }