mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
focus-ring: Store config instead of individual fields
This commit is contained in:
+22
-29
@@ -1,7 +1,7 @@
|
|||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use niri_config::{self, Color};
|
use niri_config;
|
||||||
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
|
use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
|
||||||
use smithay::backend::renderer::element::Kind;
|
use smithay::backend::renderer::element::Kind;
|
||||||
use smithay::utils::{Logical, Point, Scale, Size};
|
use smithay::utils::{Logical, Point, Scale, Size};
|
||||||
@@ -10,11 +10,8 @@ use smithay::utils::{Logical, Point, Scale, Size};
|
|||||||
pub struct FocusRing {
|
pub struct FocusRing {
|
||||||
buffers: [SolidColorBuffer; 4],
|
buffers: [SolidColorBuffer; 4],
|
||||||
locations: [Point<i32, Logical>; 4],
|
locations: [Point<i32, Logical>; 4],
|
||||||
is_off: bool,
|
|
||||||
is_border: bool,
|
is_border: bool,
|
||||||
width: i32,
|
config: niri_config::FocusRing,
|
||||||
active_color: Color,
|
|
||||||
inactive_color: Color,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FocusRingRenderElement = SolidColorRenderElement;
|
pub type FocusRingRenderElement = SolidColorRenderElement;
|
||||||
@@ -24,36 +21,32 @@ impl FocusRing {
|
|||||||
Self {
|
Self {
|
||||||
buffers: Default::default(),
|
buffers: Default::default(),
|
||||||
locations: Default::default(),
|
locations: Default::default(),
|
||||||
is_off: config.off,
|
|
||||||
is_border: false,
|
is_border: false,
|
||||||
width: config.width.into(),
|
config,
|
||||||
active_color: config.active_color,
|
|
||||||
inactive_color: config.inactive_color,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_config(&mut self, config: niri_config::FocusRing) {
|
pub fn update_config(&mut self, config: niri_config::FocusRing) {
|
||||||
self.is_off = config.off;
|
self.config = config;
|
||||||
self.width = config.width.into();
|
|
||||||
self.active_color = config.active_color;
|
|
||||||
self.inactive_color = config.inactive_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) {
|
pub fn update(&mut self, win_size: Size<i32, Logical>, is_border: bool) {
|
||||||
if is_border {
|
let width = i32::from(self.config.width);
|
||||||
self.buffers[0].resize((win_size.w + self.width * 2, self.width));
|
|
||||||
self.buffers[1].resize((win_size.w + self.width * 2, self.width));
|
|
||||||
self.buffers[2].resize((self.width, win_size.h));
|
|
||||||
self.buffers[3].resize((self.width, win_size.h));
|
|
||||||
|
|
||||||
self.locations[0] = Point::from((-self.width, -self.width));
|
if is_border {
|
||||||
self.locations[1] = Point::from((-self.width, win_size.h));
|
self.buffers[0].resize((win_size.w + width * 2, width));
|
||||||
self.locations[2] = Point::from((-self.width, 0));
|
self.buffers[1].resize((win_size.w + width * 2, width));
|
||||||
|
self.buffers[2].resize((width, win_size.h));
|
||||||
|
self.buffers[3].resize((width, win_size.h));
|
||||||
|
|
||||||
|
self.locations[0] = Point::from((-width, -width));
|
||||||
|
self.locations[1] = Point::from((-width, win_size.h));
|
||||||
|
self.locations[2] = Point::from((-width, 0));
|
||||||
self.locations[3] = Point::from((win_size.w, 0));
|
self.locations[3] = Point::from((win_size.w, 0));
|
||||||
} else {
|
} else {
|
||||||
let size = win_size + Size::from((self.width * 2, self.width * 2));
|
let size = win_size + Size::from((width * 2, width * 2));
|
||||||
self.buffers[0].resize(size);
|
self.buffers[0].resize(size);
|
||||||
self.locations[0] = Point::from((-self.width, -self.width));
|
self.locations[0] = Point::from((-width, -width));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.is_border = is_border;
|
self.is_border = is_border;
|
||||||
@@ -61,9 +54,9 @@ impl FocusRing {
|
|||||||
|
|
||||||
pub fn set_active(&mut self, is_active: bool) {
|
pub fn set_active(&mut self, is_active: bool) {
|
||||||
let color = if is_active {
|
let color = if is_active {
|
||||||
self.active_color.into()
|
self.config.active_color.into()
|
||||||
} else {
|
} else {
|
||||||
self.inactive_color.into()
|
self.config.inactive_color.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
for buf in &mut self.buffers {
|
for buf in &mut self.buffers {
|
||||||
@@ -78,7 +71,7 @@ impl FocusRing {
|
|||||||
) -> impl Iterator<Item = FocusRingRenderElement> {
|
) -> impl Iterator<Item = FocusRingRenderElement> {
|
||||||
let mut rv = ArrayVec::<_, 4>::new();
|
let mut rv = ArrayVec::<_, 4>::new();
|
||||||
|
|
||||||
if self.is_off {
|
if self.config.off {
|
||||||
return rv.into_iter();
|
return rv.into_iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +83,7 @@ impl FocusRing {
|
|||||||
1.,
|
1.,
|
||||||
Kind::Unspecified,
|
Kind::Unspecified,
|
||||||
);
|
);
|
||||||
rv.push(elem);
|
rv.push(elem.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.is_border {
|
if self.is_border {
|
||||||
@@ -105,10 +98,10 @@ impl FocusRing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn width(&self) -> i32 {
|
pub fn width(&self) -> i32 {
|
||||||
self.width
|
self.config.width.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_off(&self) -> bool {
|
pub fn is_off(&self) -> bool {
|
||||||
self.is_off
|
self.config.off
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user