aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-02-02 08:41:42 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-02-02 09:55:40 +0300
commitd5592743cb04cef3fe50c987b7ba9349c5090dbd (patch)
tree3145eb367a5e7b7acb4eafc30be6caf99350d9d3
parent019e75955d2693b1625ee06a24534b9eb605d829 (diff)
downloadniri-d5592743cb04cef3fe50c987b7ba9349c5090dbd.tar.gz
niri-d5592743cb04cef3fe50c987b7ba9349c5090dbd.tar.bz2
niri-d5592743cb04cef3fe50c987b7ba9349c5090dbd.zip
Add impl From<Color> for Gradient
-rw-r--r--niri-config/src/lib.rs12
-rw-r--r--src/layout/focus_ring.rs10
2 files changed, 14 insertions, 8 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index cfa87a24..ddd3003d 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -530,6 +530,18 @@ pub struct Gradient {
pub in_: GradientInterpolation,
}
+impl From<Color> for Gradient {
+ fn from(value: Color) -> Self {
+ Self {
+ from: value,
+ to: value,
+ angle: 0,
+ relative_to: GradientRelativeTo::Window,
+ in_: GradientInterpolation::default(),
+ }
+ }
+}
+
#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum GradientRelativeTo {
#[default]
diff --git a/src/layout/focus_ring.rs b/src/layout/focus_ring.rs
index b6c65b3f..3d97cb02 100644
--- a/src/layout/focus_ring.rs
+++ b/src/layout/focus_ring.rs
@@ -1,7 +1,7 @@
use std::iter::zip;
use arrayvec::ArrayVec;
-use niri_config::{CornerRadius, Gradient, GradientInterpolation, GradientRelativeTo};
+use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
use smithay::backend::renderer::element::Kind;
use smithay::utils::{Logical, Point, Rectangle, Size};
@@ -86,13 +86,7 @@ impl FocusRing {
self.use_border_shader = radius != CornerRadius::default() || gradient.is_some();
// Set the defaults for solid color + rounded corners.
- let gradient = gradient.unwrap_or(Gradient {
- from: color,
- to: color,
- angle: 0,
- relative_to: GradientRelativeTo::Window,
- in_: GradientInterpolation::default(),
- });
+ let gradient = gradient.unwrap_or_else(|| Gradient::from(color));
let full_rect = Rectangle::new(Point::from((-width, -width)), self.full_size);
let gradient_area = match gradient.relative_to {