Implement gradient color interpolation option (#548)
Browse files at this commit27 changed files +1092 -79
- niri-config/src/lib.rs +215 -43
- niri-visual-tests/src/cases/gradient_angle.rs +4 -3
- niri-visual-tests/src/cases/gradient_area.rs +5 -4
- niri-visual-tests/src/cases/gradient_oklab.rs +53 -0
- niri-visual-tests/src/cases/gradient_oklab_alpha.rs +51 -0
- niri-visual-tests/src/cases/gradient_oklch_alpha.rs +53 -0
- niri-visual-tests/src/cases/gradient_oklch_decreasing.rs +53 -0
- niri-visual-tests/src/cases/gradient_oklch_increasing.rs +53 -0
- niri-visual-tests/src/cases/gradient_oklch_longer.rs +53 -0
- niri-visual-tests/src/cases/gradient_oklch_shorter.rs +53 -0
- niri-visual-tests/src/cases/gradient_srgb.rs +53 -0
- niri-visual-tests/src/cases/gradient_srgb_alpha.rs +51 -0
- niri-visual-tests/src/cases/gradient_srgblinear.rs +53 -0
- niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs +51 -0
- niri-visual-tests/src/cases/layout.rs +2 -2
- niri-visual-tests/src/cases/mod.rs +11 -0
- niri-visual-tests/src/cases/tile.rs +1 -1
- niri-visual-tests/src/main.rs +24 -2
- resources/default-config.kdl +1 -0
- src/layout/focus_ring.rs +9 -6
- src/layout/tile.rs +4 -3
- src/render_helpers/border.rs +34 -9
- src/render_helpers/shaders/border.frag +173 -1
- src/render_helpers/shaders/mod.rs +2 -0
- src/window/mapped.rs +4 -3
- wiki/Configuration:-Layout.md +23 -2
- wiki/img/gradients-oklch.png +3 -0
niri-config/src/lib.rsmodified+215 -43
| @@ -410,8 +410,8 @@ impl Default for FocusRing { | ||
| 410 | 410 | Self { |
| 411 | 411 | off: false, |
| 412 | 412 | width: FloatOrInt(4.), |
| 413 | - active_color: Color::new(127, 200, 255, 255), | |
| 414 | - inactive_color: Color::new(80, 80, 80, 255), | |
| 413 | + active_color: Color::from_rgba8_unpremul(127, 200, 255, 255), | |
| 414 | + inactive_color: Color::from_rgba8_unpremul(80, 80, 80, 255), | |
| 415 | 415 | active_gradient: None, |
| 416 | 416 | inactive_gradient: None, |
| 417 | 417 | } |
| @@ -428,6 +428,8 @@ pub struct Gradient { | ||
| 428 | 428 | pub angle: i16, |
| 429 | 429 | #[knuffel(property, default)] |
| 430 | 430 | pub relative_to: GradientRelativeTo, |
| 431 | + #[knuffel(property(name = "in"), str, default)] | |
| 432 | + pub in_: GradientInterpolation, | |
| 431 | 433 | } |
| 432 | 434 | |
| 433 | 435 | #[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)] |
| @@ -437,6 +439,30 @@ pub enum GradientRelativeTo { | ||
| 437 | 439 | WorkspaceView, |
| 438 | 440 | } |
| 439 | 441 | |
| 442 | +#[derive(Default, Debug, Clone, Copy, PartialEq)] | |
| 443 | +pub struct GradientInterpolation { | |
| 444 | + pub color_space: GradientColorSpace, | |
| 445 | + pub hue_interpolation: HueInterpolation, | |
| 446 | +} | |
| 447 | + | |
| 448 | +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | |
| 449 | +pub enum GradientColorSpace { | |
| 450 | + #[default] | |
| 451 | + Srgb, | |
| 452 | + SrgbLinear, | |
| 453 | + Oklab, | |
| 454 | + Oklch, | |
| 455 | +} | |
| 456 | + | |
| 457 | +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | |
| 458 | +pub enum HueInterpolation { | |
| 459 | + #[default] | |
| 460 | + Shorter, | |
| 461 | + Longer, | |
| 462 | + Increasing, | |
| 463 | + Decreasing, | |
| 464 | +} | |
| 465 | + | |
| 440 | 466 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 441 | 467 | pub struct Border { |
| 442 | 468 | #[knuffel(child)] |
| @@ -458,8 +484,8 @@ impl Default for Border { | ||
| 458 | 484 | Self { |
| 459 | 485 | off: true, |
| 460 | 486 | width: FloatOrInt(4.), |
| 461 | - active_color: Color::new(255, 200, 127, 255), | |
| 462 | - inactive_color: Color::new(80, 80, 80, 255), | |
| 487 | + active_color: Color::from_rgba8_unpremul(255, 200, 127, 255), | |
| 488 | + inactive_color: Color::from_rgba8_unpremul(80, 80, 80, 255), | |
| 463 | 489 | active_gradient: None, |
| 464 | 490 | inactive_gradient: None, |
| 465 | 491 | } |
| @@ -492,23 +518,49 @@ impl From<FocusRing> for Border { | ||
| 492 | 518 | } |
| 493 | 519 | } |
| 494 | 520 | |
| 495 | -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | |
| 521 | +/// RGB color in [0, 1] with unpremultiplied alpha. | |
| 522 | +#[derive(Debug, Default, Clone, Copy, PartialEq)] | |
| 496 | 523 | pub struct Color { |
| 497 | - pub r: u8, | |
| 498 | - pub g: u8, | |
| 499 | - pub b: u8, | |
| 500 | - pub a: u8, | |
| 524 | + pub r: f32, | |
| 525 | + pub g: f32, | |
| 526 | + pub b: f32, | |
| 527 | + pub a: f32, | |
| 501 | 528 | } |
| 502 | 529 | |
| 503 | 530 | impl Color { |
| 504 | - pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self { | |
| 531 | + pub const fn new_unpremul(r: f32, g: f32, b: f32, a: f32) -> Self { | |
| 505 | 532 | Self { r, g, b, a } |
| 506 | 533 | } |
| 507 | -} | |
| 508 | 534 | |
| 509 | -impl From<Color> for [f32; 4] { | |
| 510 | - fn from(c: Color) -> Self { | |
| 511 | - let [r, g, b, a] = [c.r, c.g, c.b, c.a].map(|x| x as f32 / 255.); | |
| 535 | + pub fn from_rgba8_unpremul(r: u8, g: u8, b: u8, a: u8) -> Self { | |
| 536 | + Self::from_array_unpremul([r, g, b, a].map(|x| x as f32 / 255.)) | |
| 537 | + } | |
| 538 | + | |
| 539 | + pub fn from_array_premul([r, g, b, a]: [f32; 4]) -> Self { | |
| 540 | + let a = a.clamp(0., 1.); | |
| 541 | + | |
| 542 | + if a == 0. { | |
| 543 | + Self::new_unpremul(0., 0., 0., 0.) | |
| 544 | + } else { | |
| 545 | + Self { | |
| 546 | + r: (r / a).clamp(0., 1.), | |
| 547 | + g: (g / a).clamp(0., 1.), | |
| 548 | + b: (b / a).clamp(0., 1.), | |
| 549 | + a, | |
| 550 | + } | |
| 551 | + } | |
| 552 | + } | |
| 553 | + | |
| 554 | + pub fn from_array_unpremul([r, g, b, a]: [f32; 4]) -> Self { | |
| 555 | + Self { r, g, b, a } | |
| 556 | + } | |
| 557 | + | |
| 558 | + pub fn to_array_unpremul(self) -> [f32; 4] { | |
| 559 | + [self.r, self.g, self.b, self.a] | |
| 560 | + } | |
| 561 | + | |
| 562 | + pub fn to_array_premul(self) -> [f32; 4] { | |
| 563 | + let [r, g, b, a] = [self.r, self.g, self.b, self.a]; | |
| 512 | 564 | [r * a, g * a, b * a, a] |
| 513 | 565 | } |
| 514 | 566 | } |
| @@ -1429,12 +1481,73 @@ impl CornerRadius { | ||
| 1429 | 1481 | } |
| 1430 | 1482 | } |
| 1431 | 1483 | |
| 1484 | +impl FromStr for GradientInterpolation { | |
| 1485 | + type Err = miette::Error; | |
| 1486 | + | |
| 1487 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | |
| 1488 | + let mut iter = s.split_whitespace(); | |
| 1489 | + let in_part1 = iter.next(); | |
| 1490 | + let in_part2 = iter.next(); | |
| 1491 | + let in_part3 = iter.next(); | |
| 1492 | + | |
| 1493 | + let Some(in_part1) = in_part1 else { | |
| 1494 | + return Err(miette!("missing color space")); | |
| 1495 | + }; | |
| 1496 | + | |
| 1497 | + let color = match in_part1 { | |
| 1498 | + "srgb" => GradientColorSpace::Srgb, | |
| 1499 | + "srgb-linear" => GradientColorSpace::SrgbLinear, | |
| 1500 | + "oklab" => GradientColorSpace::Oklab, | |
| 1501 | + "oklch" => GradientColorSpace::Oklch, | |
| 1502 | + x => { | |
| 1503 | + return Err(miette!( | |
| 1504 | + "invalid color space {x}; can be srgb, srgb-linear, oklab or oklch" | |
| 1505 | + )) | |
| 1506 | + } | |
| 1507 | + }; | |
| 1508 | + | |
| 1509 | + let interpolation = if let Some(in_part2) = in_part2 { | |
| 1510 | + if color != GradientColorSpace::Oklch { | |
| 1511 | + return Err(miette!("only oklch color space can have hue interpolation")); | |
| 1512 | + } | |
| 1513 | + | |
| 1514 | + if in_part3 != Some("hue") { | |
| 1515 | + return Err(miette!( | |
| 1516 | + "interpolation must end with \"hue\", like \"oklch shorter hue\"" | |
| 1517 | + )); | |
| 1518 | + } else if iter.next().is_some() { | |
| 1519 | + return Err(miette!("unexpected text after hue interpolation")); | |
| 1520 | + } else { | |
| 1521 | + match in_part2 { | |
| 1522 | + "shorter" => HueInterpolation::Shorter, | |
| 1523 | + "longer" => HueInterpolation::Longer, | |
| 1524 | + "increasing" => HueInterpolation::Increasing, | |
| 1525 | + "decreasing" => HueInterpolation::Decreasing, | |
| 1526 | + x => { | |
| 1527 | + return Err(miette!( | |
| 1528 | + "invalid hue interpolation {x}; \ | |
| 1529 | + can be shorter, longer, increasing, decreasing" | |
| 1530 | + )) | |
| 1531 | + } | |
| 1532 | + } | |
| 1533 | + } | |
| 1534 | + } else { | |
| 1535 | + HueInterpolation::default() | |
| 1536 | + }; | |
| 1537 | + | |
| 1538 | + Ok(Self { | |
| 1539 | + color_space: color, | |
| 1540 | + hue_interpolation: interpolation, | |
| 1541 | + }) | |
| 1542 | + } | |
| 1543 | +} | |
| 1544 | + | |
| 1432 | 1545 | impl FromStr for Color { |
| 1433 | 1546 | type Err = miette::Error; |
| 1434 | 1547 | |
| 1435 | 1548 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1436 | - let [r, g, b, a] = csscolorparser::parse(s).into_diagnostic()?.to_rgba8(); | |
| 1437 | - Ok(Self { r, g, b, a }) | |
| 1549 | + let color = csscolorparser::parse(s).into_diagnostic()?.to_array(); | |
| 1550 | + Ok(Self::from_array_unpremul(color.map(|x| x as f32))) | |
| 1438 | 1551 | } |
| 1439 | 1552 | } |
| 1440 | 1553 | |
| @@ -1453,7 +1566,7 @@ struct ColorRgba { | ||
| 1453 | 1566 | impl From<ColorRgba> for Color { |
| 1454 | 1567 | fn from(value: ColorRgba) -> Self { |
| 1455 | 1568 | let ColorRgba { r, g, b, a } = value; |
| 1456 | - Self { r, g, b, a } | |
| 1569 | + Self::from_array_unpremul([r, g, b, a].map(|x| x as f32 / 255.)) | |
| 1457 | 1570 | } |
| 1458 | 1571 | } |
| 1459 | 1572 | |
| @@ -2771,41 +2884,25 @@ mod tests { | ||
| 2771 | 2884 | focus_ring: FocusRing { |
| 2772 | 2885 | off: false, |
| 2773 | 2886 | width: FloatOrInt(5.), |
| 2774 | - active_color: Color { | |
| 2775 | - r: 0, | |
| 2776 | - g: 100, | |
| 2777 | - b: 200, | |
| 2778 | - a: 255, | |
| 2779 | - }, | |
| 2780 | - inactive_color: Color { | |
| 2781 | - r: 255, | |
| 2782 | - g: 200, | |
| 2783 | - b: 100, | |
| 2784 | - a: 0, | |
| 2785 | - }, | |
| 2887 | + active_color: Color::from_rgba8_unpremul(0, 100, 200, 255), | |
| 2888 | + inactive_color: Color::from_rgba8_unpremul(255, 200, 100, 0), | |
| 2786 | 2889 | active_gradient: Some(Gradient { |
| 2787 | - from: Color::new(10, 20, 30, 255), | |
| 2788 | - to: Color::new(0, 128, 255, 255), | |
| 2890 | + from: Color::from_rgba8_unpremul(10, 20, 30, 255), | |
| 2891 | + to: Color::from_rgba8_unpremul(0, 128, 255, 255), | |
| 2789 | 2892 | angle: 180, |
| 2790 | 2893 | relative_to: GradientRelativeTo::WorkspaceView, |
| 2894 | + in_: GradientInterpolation { | |
| 2895 | + color_space: GradientColorSpace::Srgb, | |
| 2896 | + hue_interpolation: HueInterpolation::Shorter, | |
| 2897 | + }, | |
| 2791 | 2898 | }), |
| 2792 | 2899 | inactive_gradient: None, |
| 2793 | 2900 | }, |
| 2794 | 2901 | border: Border { |
| 2795 | 2902 | off: false, |
| 2796 | 2903 | width: FloatOrInt(3.), |
| 2797 | - active_color: Color { | |
| 2798 | - r: 255, | |
| 2799 | - g: 200, | |
| 2800 | - b: 127, | |
| 2801 | - a: 255, | |
| 2802 | - }, | |
| 2803 | - inactive_color: Color { | |
| 2804 | - r: 255, | |
| 2805 | - g: 200, | |
| 2806 | - b: 100, | |
| 2807 | - a: 0, | |
| 2808 | - }, | |
| 2904 | + active_color: Color::from_rgba8_unpremul(255, 200, 127, 255), | |
| 2905 | + inactive_color: Color::from_rgba8_unpremul(255, 200, 100, 0), | |
| 2809 | 2906 | active_gradient: None, |
| 2810 | 2907 | inactive_gradient: None, |
| 2811 | 2908 | }, |
| @@ -3095,6 +3192,81 @@ mod tests { | ||
| 3095 | 3192 | assert!("10% ".parse::<SizeChange>().is_err()); |
| 3096 | 3193 | } |
| 3097 | 3194 | |
| 3195 | + #[test] | |
| 3196 | + fn parse_gradient_interpolation() { | |
| 3197 | + assert_eq!( | |
| 3198 | + "srgb".parse::<GradientInterpolation>().unwrap(), | |
| 3199 | + GradientInterpolation { | |
| 3200 | + color_space: GradientColorSpace::Srgb, | |
| 3201 | + ..Default::default() | |
| 3202 | + } | |
| 3203 | + ); | |
| 3204 | + assert_eq!( | |
| 3205 | + "srgb-linear".parse::<GradientInterpolation>().unwrap(), | |
| 3206 | + GradientInterpolation { | |
| 3207 | + color_space: GradientColorSpace::SrgbLinear, | |
| 3208 | + ..Default::default() | |
| 3209 | + } | |
| 3210 | + ); | |
| 3211 | + assert_eq!( | |
| 3212 | + "oklab".parse::<GradientInterpolation>().unwrap(), | |
| 3213 | + GradientInterpolation { | |
| 3214 | + color_space: GradientColorSpace::Oklab, | |
| 3215 | + ..Default::default() | |
| 3216 | + } | |
| 3217 | + ); | |
| 3218 | + assert_eq!( | |
| 3219 | + "oklch".parse::<GradientInterpolation>().unwrap(), | |
| 3220 | + GradientInterpolation { | |
| 3221 | + color_space: GradientColorSpace::Oklch, | |
| 3222 | + ..Default::default() | |
| 3223 | + } | |
| 3224 | + ); | |
| 3225 | + assert_eq!( | |
| 3226 | + "oklch shorter hue" | |
| 3227 | + .parse::<GradientInterpolation>() | |
| 3228 | + .unwrap(), | |
| 3229 | + GradientInterpolation { | |
| 3230 | + color_space: GradientColorSpace::Oklch, | |
| 3231 | + hue_interpolation: HueInterpolation::Shorter, | |
| 3232 | + } | |
| 3233 | + ); | |
| 3234 | + assert_eq!( | |
| 3235 | + "oklch longer hue".parse::<GradientInterpolation>().unwrap(), | |
| 3236 | + GradientInterpolation { | |
| 3237 | + color_space: GradientColorSpace::Oklch, | |
| 3238 | + hue_interpolation: HueInterpolation::Longer, | |
| 3239 | + } | |
| 3240 | + ); | |
| 3241 | + assert_eq!( | |
| 3242 | + "oklch decreasing hue" | |
| 3243 | + .parse::<GradientInterpolation>() | |
| 3244 | + .unwrap(), | |
| 3245 | + GradientInterpolation { | |
| 3246 | + color_space: GradientColorSpace::Oklch, | |
| 3247 | + hue_interpolation: HueInterpolation::Decreasing, | |
| 3248 | + } | |
| 3249 | + ); | |
| 3250 | + assert_eq!( | |
| 3251 | + "oklch increasing hue" | |
| 3252 | + .parse::<GradientInterpolation>() | |
| 3253 | + .unwrap(), | |
| 3254 | + GradientInterpolation { | |
| 3255 | + color_space: GradientColorSpace::Oklch, | |
| 3256 | + hue_interpolation: HueInterpolation::Increasing, | |
| 3257 | + } | |
| 3258 | + ); | |
| 3259 | + | |
| 3260 | + assert!("".parse::<GradientInterpolation>().is_err()); | |
| 3261 | + assert!("srgb shorter hue".parse::<GradientInterpolation>().is_err()); | |
| 3262 | + assert!("oklch shorter".parse::<GradientInterpolation>().is_err()); | |
| 3263 | + assert!("oklch shorter h".parse::<GradientInterpolation>().is_err()); | |
| 3264 | + assert!("oklch a hue".parse::<GradientInterpolation>().is_err()); | |
| 3265 | + assert!("oklch shorter hue a" | |
| 3266 | + .parse::<GradientInterpolation>() | |
| 3267 | + .is_err()); | |
| 3268 | + } | |
| 3269 | + | |
| 3098 | 3270 | #[test] |
| 3099 | 3271 | fn parse_iso_level3_shift() { |
| 3100 | 3272 | assert_eq!( |
niri-visual-tests/src/cases/gradient_angle.rsmodified+4 -3
| @@ -4,7 +4,7 @@ use std::time::Duration; | ||
| 4 | 4 | |
| 5 | 5 | use niri::animation::ANIMATION_SLOWDOWN; |
| 6 | 6 | use niri::render_helpers::border::BorderRenderElement; |
| 7 | -use niri_config::CornerRadius; | |
| 7 | +use niri_config::{Color, CornerRadius, GradientInterpolation}; | |
| 8 | 8 | use smithay::backend::renderer::element::RenderElement; |
| 9 | 9 | use smithay::backend::renderer::gles::GlesRenderer; |
| 10 | 10 | use smithay::utils::{Logical, Physical, Rectangle, Size}; |
| @@ -64,8 +64,9 @@ impl TestCase for GradientAngle { | ||
| 64 | 64 | [BorderRenderElement::new( |
| 65 | 65 | area.size, |
| 66 | 66 | Rectangle::from_loc_and_size((0., 0.), area.size), |
| 67 | - [1., 0., 0., 1.], | |
| 68 | - [0., 1., 0., 1.], | |
| 67 | + GradientInterpolation::default(), | |
| 68 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 69 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 69 | 70 | self.angle - FRAC_PI_2, |
| 70 | 71 | Rectangle::from_loc_and_size((0., 0.), area.size), |
| 71 | 72 | 0., |
niri-visual-tests/src/cases/gradient_area.rsmodified+5 -4
| @@ -5,7 +5,7 @@ use std::time::Duration; | ||
| 5 | 5 | use niri::animation::ANIMATION_SLOWDOWN; |
| 6 | 6 | use niri::layout::focus_ring::FocusRing; |
| 7 | 7 | use niri::render_helpers::border::BorderRenderElement; |
| 8 | -use niri_config::{Color, CornerRadius, FloatOrInt}; | |
| 8 | +use niri_config::{Color, CornerRadius, FloatOrInt, GradientInterpolation}; | |
| 9 | 9 | use smithay::backend::renderer::element::RenderElement; |
| 10 | 10 | use smithay::backend::renderer::gles::GlesRenderer; |
| 11 | 11 | use smithay::utils::{Logical, Physical, Point, Rectangle, Size}; |
| @@ -23,7 +23,7 @@ impl GradientArea { | ||
| 23 | 23 | let border = FocusRing::new(niri_config::FocusRing { |
| 24 | 24 | off: false, |
| 25 | 25 | width: FloatOrInt(1.), |
| 26 | - active_color: Color::new(255, 255, 255, 128), | |
| 26 | + active_color: Color::from_rgba8_unpremul(255, 255, 255, 128), | |
| 27 | 27 | inactive_color: Color::default(), |
| 28 | 28 | active_gradient: None, |
| 29 | 29 | inactive_gradient: None, |
| @@ -104,8 +104,9 @@ impl TestCase for GradientArea { | ||
| 104 | 104 | [BorderRenderElement::new( |
| 105 | 105 | area.size, |
| 106 | 106 | g_area, |
| 107 | - [1., 0., 0., 1.], | |
| 108 | - [0., 1., 0., 1.], | |
| 107 | + GradientInterpolation::default(), | |
| 108 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 109 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 109 | 110 | FRAC_PI_4, |
| 110 | 111 | Rectangle::from_loc_and_size((0, 0), rect_size).to_f64(), |
| 111 | 112 | 0., |
niri-visual-tests/src/cases/gradient_oklab.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklab { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklab { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklab, | |
| 20 | + hue_interpolation: HueInterpolation::Shorter, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklab { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_oklab_alpha.rsadded+51 -0
| @@ -0,0 +1,51 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation}; | |
| 3 | +use smithay::backend::renderer::element::RenderElement; | |
| 4 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 5 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 6 | + | |
| 7 | +use super::TestCase; | |
| 8 | + | |
| 9 | +pub struct GradientOklabAlpha { | |
| 10 | + gradient_format: GradientInterpolation, | |
| 11 | +} | |
| 12 | + | |
| 13 | +impl GradientOklabAlpha { | |
| 14 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 15 | + Self { | |
| 16 | + gradient_format: GradientInterpolation { | |
| 17 | + color_space: GradientColorSpace::Oklab, | |
| 18 | + hue_interpolation: Default::default(), | |
| 19 | + }, | |
| 20 | + } | |
| 21 | + } | |
| 22 | +} | |
| 23 | + | |
| 24 | +impl TestCase for GradientOklabAlpha { | |
| 25 | + fn render( | |
| 26 | + &mut self, | |
| 27 | + _renderer: &mut GlesRenderer, | |
| 28 | + size: Size<i32, Physical>, | |
| 29 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 30 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 31 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 32 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 33 | + | |
| 34 | + [BorderRenderElement::new( | |
| 35 | + area.size, | |
| 36 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 37 | + self.gradient_format, | |
| 38 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 39 | + Color::new_unpremul(0., 1., 0., 0.), | |
| 40 | + 0., | |
| 41 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 42 | + 0., | |
| 43 | + CornerRadius::default(), | |
| 44 | + 1., | |
| 45 | + ) | |
| 46 | + .with_location(area.loc)] | |
| 47 | + .into_iter() | |
| 48 | + .map(|elem| Box::new(elem) as _) | |
| 49 | + .collect() | |
| 50 | + } | |
| 51 | +} |
niri-visual-tests/src/cases/gradient_oklch_alpha.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklchAlpha { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklchAlpha { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklch, | |
| 20 | + hue_interpolation: HueInterpolation::Longer, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklchAlpha { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 0.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_oklch_decreasing.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklchDecreasing { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklchDecreasing { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklch, | |
| 20 | + hue_interpolation: HueInterpolation::Decreasing, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklchDecreasing { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_oklch_increasing.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklchIncreasing { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklchIncreasing { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklch, | |
| 20 | + hue_interpolation: HueInterpolation::Increasing, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklchIncreasing { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_oklch_longer.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklchLonger { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklchLonger { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklch, | |
| 20 | + hue_interpolation: HueInterpolation::Longer, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklchLonger { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_oklch_shorter.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientOklchShorter { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientOklchShorter { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Oklch, | |
| 20 | + hue_interpolation: HueInterpolation::Shorter, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientOklchShorter { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_srgb.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientSrgb { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientSrgb { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::Srgb, | |
| 20 | + hue_interpolation: HueInterpolation::Shorter, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientSrgb { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_srgb_alpha.rsadded+51 -0
| @@ -0,0 +1,51 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation}; | |
| 3 | +use smithay::backend::renderer::element::RenderElement; | |
| 4 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 5 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 6 | + | |
| 7 | +use super::TestCase; | |
| 8 | + | |
| 9 | +pub struct GradientSrgbAlpha { | |
| 10 | + gradient_format: GradientInterpolation, | |
| 11 | +} | |
| 12 | + | |
| 13 | +impl GradientSrgbAlpha { | |
| 14 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 15 | + Self { | |
| 16 | + gradient_format: GradientInterpolation { | |
| 17 | + color_space: GradientColorSpace::Srgb, | |
| 18 | + hue_interpolation: Default::default(), | |
| 19 | + }, | |
| 20 | + } | |
| 21 | + } | |
| 22 | +} | |
| 23 | + | |
| 24 | +impl TestCase for GradientSrgbAlpha { | |
| 25 | + fn render( | |
| 26 | + &mut self, | |
| 27 | + _renderer: &mut GlesRenderer, | |
| 28 | + size: Size<i32, Physical>, | |
| 29 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 30 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 31 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 32 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 33 | + | |
| 34 | + [BorderRenderElement::new( | |
| 35 | + area.size, | |
| 36 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 37 | + self.gradient_format, | |
| 38 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 39 | + Color::new_unpremul(0., 1., 0., 0.), | |
| 40 | + 0., | |
| 41 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 42 | + 0., | |
| 43 | + CornerRadius::default(), | |
| 44 | + 1., | |
| 45 | + ) | |
| 46 | + .with_location(area.loc)] | |
| 47 | + .into_iter() | |
| 48 | + .map(|elem| Box::new(elem) as _) | |
| 49 | + .collect() | |
| 50 | + } | |
| 51 | +} |
niri-visual-tests/src/cases/gradient_srgblinear.rsadded+53 -0
| @@ -0,0 +1,53 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{ | |
| 3 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 4 | +}; | |
| 5 | +use smithay::backend::renderer::element::RenderElement; | |
| 6 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 7 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 8 | + | |
| 9 | +use super::TestCase; | |
| 10 | + | |
| 11 | +pub struct GradientSrgbLinear { | |
| 12 | + gradient_format: GradientInterpolation, | |
| 13 | +} | |
| 14 | + | |
| 15 | +impl GradientSrgbLinear { | |
| 16 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 17 | + Self { | |
| 18 | + gradient_format: GradientInterpolation { | |
| 19 | + color_space: GradientColorSpace::SrgbLinear, | |
| 20 | + hue_interpolation: HueInterpolation::Shorter, | |
| 21 | + }, | |
| 22 | + } | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl TestCase for GradientSrgbLinear { | |
| 27 | + fn render( | |
| 28 | + &mut self, | |
| 29 | + _renderer: &mut GlesRenderer, | |
| 30 | + size: Size<i32, Physical>, | |
| 31 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 32 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 33 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 34 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 35 | + | |
| 36 | + [BorderRenderElement::new( | |
| 37 | + area.size, | |
| 38 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 39 | + self.gradient_format, | |
| 40 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 41 | + Color::new_unpremul(0., 1., 0., 1.), | |
| 42 | + 0., | |
| 43 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 44 | + 0., | |
| 45 | + CornerRadius::default(), | |
| 46 | + 1., | |
| 47 | + ) | |
| 48 | + .with_location(area.loc)] | |
| 49 | + .into_iter() | |
| 50 | + .map(|elem| Box::new(elem) as _) | |
| 51 | + .collect() | |
| 52 | + } | |
| 53 | +} |
niri-visual-tests/src/cases/gradient_srgblinear_alpha.rsadded+51 -0
| @@ -0,0 +1,51 @@ | ||
| 1 | +use niri::render_helpers::border::BorderRenderElement; | |
| 2 | +use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation}; | |
| 3 | +use smithay::backend::renderer::element::RenderElement; | |
| 4 | +use smithay::backend::renderer::gles::GlesRenderer; | |
| 5 | +use smithay::utils::{Logical, Physical, Rectangle, Size}; | |
| 6 | + | |
| 7 | +use super::TestCase; | |
| 8 | + | |
| 9 | +pub struct GradientSrgbLinearAlpha { | |
| 10 | + gradient_format: GradientInterpolation, | |
| 11 | +} | |
| 12 | + | |
| 13 | +impl GradientSrgbLinearAlpha { | |
| 14 | + pub fn new(_size: Size<i32, Logical>) -> Self { | |
| 15 | + Self { | |
| 16 | + gradient_format: GradientInterpolation { | |
| 17 | + color_space: GradientColorSpace::SrgbLinear, | |
| 18 | + hue_interpolation: Default::default(), | |
| 19 | + }, | |
| 20 | + } | |
| 21 | + } | |
| 22 | +} | |
| 23 | + | |
| 24 | +impl TestCase for GradientSrgbLinearAlpha { | |
| 25 | + fn render( | |
| 26 | + &mut self, | |
| 27 | + _renderer: &mut GlesRenderer, | |
| 28 | + size: Size<i32, Physical>, | |
| 29 | + ) -> Vec<Box<dyn RenderElement<GlesRenderer>>> { | |
| 30 | + let (a, b) = (size.w / 6, size.h / 3); | |
| 31 | + let size = (size.w - a * 2, size.h - b * 2); | |
| 32 | + let area = Rectangle::from_loc_and_size((a, b), size).to_f64(); | |
| 33 | + | |
| 34 | + [BorderRenderElement::new( | |
| 35 | + area.size, | |
| 36 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 37 | + self.gradient_format, | |
| 38 | + Color::new_unpremul(1., 0., 0., 1.), | |
| 39 | + Color::new_unpremul(0., 1., 0., 0.), | |
| 40 | + 0., | |
| 41 | + Rectangle::from_loc_and_size((0., 0.), area.size), | |
| 42 | + 0., | |
| 43 | + CornerRadius::default(), | |
| 44 | + 1., | |
| 45 | + ) | |
| 46 | + .with_location(area.loc)] | |
| 47 | + .into_iter() | |
| 48 | + .map(|elem| Box::new(elem) as _) | |
| 49 | + .collect() | |
| 50 | + } | |
| 51 | +} |
niri-visual-tests/src/cases/layout.rsmodified+2 -2
| @@ -50,8 +50,8 @@ impl Layout { | ||
| 50 | 50 | border: niri_config::Border { |
| 51 | 51 | off: false, |
| 52 | 52 | width: FloatOrInt(4.), |
| 53 | - active_color: Color::new(255, 163, 72, 255), | |
| 54 | - inactive_color: Color::new(50, 50, 50, 255), | |
| 53 | + active_color: Color::from_rgba8_unpremul(255, 163, 72, 255), | |
| 54 | + inactive_color: Color::from_rgba8_unpremul(50, 50, 50, 255), | |
| 55 | 55 | active_gradient: None, |
| 56 | 56 | inactive_gradient: None, |
| 57 | 57 | }, |
niri-visual-tests/src/cases/mod.rsmodified+11 -0
| @@ -6,6 +6,17 @@ use smithay::utils::{Physical, Size}; | ||
| 6 | 6 | |
| 7 | 7 | pub mod gradient_angle; |
| 8 | 8 | pub mod gradient_area; |
| 9 | +pub mod gradient_oklab; | |
| 10 | +pub mod gradient_oklab_alpha; | |
| 11 | +pub mod gradient_oklch_alpha; | |
| 12 | +pub mod gradient_oklch_decreasing; | |
| 13 | +pub mod gradient_oklch_increasing; | |
| 14 | +pub mod gradient_oklch_longer; | |
| 15 | +pub mod gradient_oklch_shorter; | |
| 16 | +pub mod gradient_srgb; | |
| 17 | +pub mod gradient_srgb_alpha; | |
| 18 | +pub mod gradient_srgblinear; | |
| 19 | +pub mod gradient_srgblinear_alpha; | |
| 9 | 20 | pub mod layout; |
| 10 | 21 | pub mod tile; |
| 11 | 22 | pub mod window; |
niri-visual-tests/src/cases/tile.rsmodified+1 -1
| @@ -72,7 +72,7 @@ impl Tile { | ||
| 72 | 72 | border: niri_config::Border { |
| 73 | 73 | off: false, |
| 74 | 74 | width: FloatOrInt(32.), |
| 75 | - active_color: Color::new(255, 163, 72, 255), | |
| 75 | + active_color: Color::from_rgba8_unpremul(255, 163, 72, 255), | |
| 76 | 76 | ..Default::default() |
| 77 | 77 | }, |
| 78 | 78 | ..Default::default() |
niri-visual-tests/src/main.rsmodified+24 -2
| @@ -5,8 +5,6 @@ use std::env; | ||
| 5 | 5 | use std::sync::atomic::Ordering; |
| 6 | 6 | |
| 7 | 7 | use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt}; |
| 8 | -use cases::tile::Tile; | |
| 9 | -use cases::window::Window; | |
| 10 | 8 | use gtk::prelude::{ |
| 11 | 9 | AdjustmentExt, ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt, WidgetExt, |
| 12 | 10 | }; |
| @@ -18,7 +16,20 @@ use tracing_subscriber::EnvFilter; | ||
| 18 | 16 | |
| 19 | 17 | use crate::cases::gradient_angle::GradientAngle; |
| 20 | 18 | use crate::cases::gradient_area::GradientArea; |
| 19 | +use crate::cases::gradient_oklab::GradientOklab; | |
| 20 | +use crate::cases::gradient_oklab_alpha::GradientOklabAlpha; | |
| 21 | +use crate::cases::gradient_oklch_alpha::GradientOklchAlpha; | |
| 22 | +use crate::cases::gradient_oklch_decreasing::GradientOklchDecreasing; | |
| 23 | +use crate::cases::gradient_oklch_increasing::GradientOklchIncreasing; | |
| 24 | +use crate::cases::gradient_oklch_longer::GradientOklchLonger; | |
| 25 | +use crate::cases::gradient_oklch_shorter::GradientOklchShorter; | |
| 26 | +use crate::cases::gradient_srgb::GradientSrgb; | |
| 27 | +use crate::cases::gradient_srgb_alpha::GradientSrgbAlpha; | |
| 28 | +use crate::cases::gradient_srgblinear::GradientSrgbLinear; | |
| 29 | +use crate::cases::gradient_srgblinear_alpha::GradientSrgbLinearAlpha; | |
| 21 | 30 | use crate::cases::layout::Layout; |
| 31 | +use crate::cases::tile::Tile; | |
| 32 | +use crate::cases::window::Window; | |
| 22 | 33 | use crate::cases::TestCase; |
| 23 | 34 | |
| 24 | 35 | mod cases; |
| @@ -112,6 +123,17 @@ fn build_ui(app: &adw::Application) { | ||
| 112 | 123 | |
| 113 | 124 | s.add(GradientAngle::new, "Gradient - Angle"); |
| 114 | 125 | s.add(GradientArea::new, "Gradient - Area"); |
| 126 | + s.add(GradientSrgb::new, "Gradient - Srgb"); | |
| 127 | + s.add(GradientSrgbLinear::new, "Gradient - SrgbLinear"); | |
| 128 | + s.add(GradientOklab::new, "Gradient - Oklab"); | |
| 129 | + s.add(GradientOklchShorter::new, "Gradient - Oklch Shorter"); | |
| 130 | + s.add(GradientOklchLonger::new, "Gradient - Oklch Longer"); | |
| 131 | + s.add(GradientOklchIncreasing::new, "Gradient - Oklch Increasing"); | |
| 132 | + s.add(GradientOklchDecreasing::new, "Gradient - Oklch Decreasing"); | |
| 133 | + s.add(GradientSrgbAlpha::new, "Gradient - Srgb Alpha"); | |
| 134 | + s.add(GradientSrgbLinearAlpha::new, "Gradient - SrgbLinear Alpha"); | |
| 135 | + s.add(GradientOklabAlpha::new, "Gradient - Oklab Alpha"); | |
| 136 | + s.add(GradientOklchAlpha::new, "Gradient - Oklch Alpha"); | |
| 115 | 137 | |
| 116 | 138 | let content_headerbar = adw::HeaderBar::new(); |
| 117 | 139 |
resources/default-config.kdlmodified+1 -0
| @@ -153,6 +153,7 @@ layout { | ||
| 153 | 153 | // The angle is the same as in linear-gradient, and is optional, |
| 154 | 154 | // defaulting to 180 (top-to-bottom gradient). |
| 155 | 155 | // You can use any CSS linear-gradient tool on the web to set these up. |
| 156 | + // Changing the color space is also supported, check the wiki for more info. | |
| 156 | 157 | // |
| 157 | 158 | // active-gradient from="#80c8ff" to="#bbddff" angle=45 |
| 158 | 159 |
src/layout/focus_ring.rsmodified+9 -6
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::iter::zip; |
| 2 | 2 | |
| 3 | 3 | use arrayvec::ArrayVec; |
| 4 | -use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; | |
| 4 | +use niri_config::{CornerRadius, Gradient, GradientInterpolation, GradientRelativeTo}; | |
| 5 | 5 | use smithay::backend::renderer::element::Kind; |
| 6 | 6 | use smithay::utils::{Logical, Point, Rectangle, Size}; |
| 7 | 7 | |
| @@ -72,7 +72,7 @@ impl FocusRing { | ||
| 72 | 72 | }; |
| 73 | 73 | |
| 74 | 74 | for buf in &mut self.buffers { |
| 75 | - buf.set_color(color.into()); | |
| 75 | + buf.set_color(color.to_array_premul()); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | let radius = radius.fit_to(self.full_size.w as f32, self.full_size.h as f32); |
| @@ -91,6 +91,7 @@ impl FocusRing { | ||
| 91 | 91 | to: color, |
| 92 | 92 | angle: 0, |
| 93 | 93 | relative_to: GradientRelativeTo::Window, |
| 94 | + in_: GradientInterpolation::default(), | |
| 94 | 95 | }); |
| 95 | 96 | |
| 96 | 97 | let full_rect = Rectangle::from_loc_and_size((-width, -width), self.full_size); |
| @@ -178,8 +179,9 @@ impl FocusRing { | ||
| 178 | 179 | border.update( |
| 179 | 180 | size, |
| 180 | 181 | Rectangle::from_loc_and_size(gradient_area.loc - loc, gradient_area.size), |
| 181 | - gradient.from.into(), | |
| 182 | - gradient.to.into(), | |
| 182 | + gradient.in_, | |
| 183 | + gradient.from, | |
| 184 | + gradient.to, | |
| 183 | 185 | ((gradient.angle as f32) - 90.).to_radians(), |
| 184 | 186 | Rectangle::from_loc_and_size(full_rect.loc - loc, full_rect.size), |
| 185 | 187 | rounded_corner_border_width, |
| @@ -198,8 +200,9 @@ impl FocusRing { | ||
| 198 | 200 | gradient_area.loc - self.locations[0], |
| 199 | 201 | gradient_area.size, |
| 200 | 202 | ), |
| 201 | - gradient.from.into(), | |
| 202 | - gradient.to.into(), | |
| 203 | + gradient.in_, | |
| 204 | + gradient.from, | |
| 205 | + gradient.to, | |
| 203 | 206 | ((gradient.angle as f32) - 90.).to_radians(), |
| 204 | 207 | Rectangle::from_loc_and_size(full_rect.loc - self.locations[0], full_rect.size), |
| 205 | 208 | rounded_corner_border_width, |
src/layout/tile.rsmodified+4 -3
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::rc::Rc; |
| 2 | 2 | use std::time::Duration; |
| 3 | 3 | |
| 4 | -use niri_config::CornerRadius; | |
| 4 | +use niri_config::{Color, CornerRadius, GradientInterpolation}; | |
| 5 | 5 | use smithay::backend::allocator::Fourcc; |
| 6 | 6 | use smithay::backend::renderer::element::{Element, Kind}; |
| 7 | 7 | use smithay::backend::renderer::gles::GlesRenderer; |
| @@ -757,8 +757,9 @@ impl<W: LayoutElement> Tile<W> { | ||
| 757 | 757 | return BorderRenderElement::new( |
| 758 | 758 | geo.size, |
| 759 | 759 | Rectangle::from_loc_and_size((0., 0.), geo.size), |
| 760 | - elem.color(), | |
| 761 | - elem.color(), | |
| 760 | + GradientInterpolation::default(), | |
| 761 | + Color::from_array_premul(elem.color()), | |
| 762 | + Color::from_array_premul(elem.color()), | |
| 762 | 763 | 0., |
| 763 | 764 | Rectangle::from_loc_and_size((0., 0.), geo.size), |
| 764 | 765 | 0., |
src/render_helpers/border.rsmodified+34 -9
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | use std::collections::HashMap; |
| 2 | 2 | |
| 3 | 3 | use glam::{Mat3, Vec2}; |
| 4 | -use niri_config::CornerRadius; | |
| 4 | +use niri_config::{ | |
| 5 | + Color, CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, | |
| 6 | +}; | |
| 5 | 7 | use smithay::backend::renderer::element::{Element, Id, Kind, RenderElement, UnderlyingStorage}; |
| 6 | 8 | use smithay::backend::renderer::gles::{GlesError, GlesFrame, GlesRenderer, Uniform}; |
| 7 | 9 | use smithay::backend::renderer::utils::{CommitCounter, DamageSet, OpaqueRegions}; |
| @@ -28,8 +30,9 @@ pub struct BorderRenderElement { | ||
| 28 | 30 | struct Parameters { |
| 29 | 31 | size: Size<f64, Logical>, |
| 30 | 32 | gradient_area: Rectangle<f64, Logical>, |
| 31 | - color_from: [f32; 4], | |
| 32 | - color_to: [f32; 4], | |
| 33 | + gradient_format: GradientInterpolation, | |
| 34 | + color_from: Color, | |
| 35 | + color_to: Color, | |
| 33 | 36 | angle: f32, |
| 34 | 37 | geometry: Rectangle<f64, Logical>, |
| 35 | 38 | border_width: f32, |
| @@ -43,8 +46,9 @@ impl BorderRenderElement { | ||
| 43 | 46 | pub fn new( |
| 44 | 47 | size: Size<f64, Logical>, |
| 45 | 48 | gradient_area: Rectangle<f64, Logical>, |
| 46 | - color_from: [f32; 4], | |
| 47 | - color_to: [f32; 4], | |
| 49 | + gradient_format: GradientInterpolation, | |
| 50 | + color_from: Color, | |
| 51 | + color_to: Color, | |
| 48 | 52 | angle: f32, |
| 49 | 53 | geometry: Rectangle<f64, Logical>, |
| 50 | 54 | border_width: f32, |
| @@ -57,6 +61,7 @@ impl BorderRenderElement { | ||
| 57 | 61 | params: Parameters { |
| 58 | 62 | size, |
| 59 | 63 | gradient_area, |
| 64 | + gradient_format, | |
| 60 | 65 | color_from, |
| 61 | 66 | color_to, |
| 62 | 67 | angle, |
| @@ -77,6 +82,7 @@ impl BorderRenderElement { | ||
| 77 | 82 | params: Parameters { |
| 78 | 83 | size: Default::default(), |
| 79 | 84 | gradient_area: Default::default(), |
| 85 | + gradient_format: GradientInterpolation::default(), | |
| 80 | 86 | color_from: Default::default(), |
| 81 | 87 | color_to: Default::default(), |
| 82 | 88 | angle: 0., |
| @@ -97,8 +103,9 @@ impl BorderRenderElement { | ||
| 97 | 103 | &mut self, |
| 98 | 104 | size: Size<f64, Logical>, |
| 99 | 105 | gradient_area: Rectangle<f64, Logical>, |
| 100 | - color_from: [f32; 4], | |
| 101 | - color_to: [f32; 4], | |
| 106 | + gradient_format: GradientInterpolation, | |
| 107 | + color_from: Color, | |
| 108 | + color_to: Color, | |
| 102 | 109 | angle: f32, |
| 103 | 110 | geometry: Rectangle<f64, Logical>, |
| 104 | 111 | border_width: f32, |
| @@ -108,6 +115,7 @@ impl BorderRenderElement { | ||
| 108 | 115 | let params = Parameters { |
| 109 | 116 | size, |
| 110 | 117 | gradient_area, |
| 118 | + gradient_format, | |
| 111 | 119 | color_from, |
| 112 | 120 | color_to, |
| 113 | 121 | angle, |
| @@ -128,6 +136,7 @@ impl BorderRenderElement { | ||
| 128 | 136 | let Parameters { |
| 129 | 137 | size, |
| 130 | 138 | gradient_area, |
| 139 | + gradient_format, | |
| 131 | 140 | color_from, |
| 132 | 141 | color_to, |
| 133 | 142 | angle, |
| @@ -162,13 +171,29 @@ impl BorderRenderElement { | ||
| 162 | 171 | let input_to_geo = |
| 163 | 172 | Mat3::from_scale(area_size) * Mat3::from_translation(-geo_loc / area_size); |
| 164 | 173 | |
| 174 | + let colorspace = match gradient_format.color_space { | |
| 175 | + GradientColorSpace::Srgb => 0., | |
| 176 | + GradientColorSpace::SrgbLinear => 1., | |
| 177 | + GradientColorSpace::Oklab => 2., | |
| 178 | + GradientColorSpace::Oklch => 3., | |
| 179 | + }; | |
| 180 | + | |
| 181 | + let hue_interpolation = match gradient_format.hue_interpolation { | |
| 182 | + HueInterpolation::Shorter => 0., | |
| 183 | + HueInterpolation::Longer => 1., | |
| 184 | + HueInterpolation::Increasing => 2., | |
| 185 | + HueInterpolation::Decreasing => 3., | |
| 186 | + }; | |
| 187 | + | |
| 165 | 188 | self.inner.update( |
| 166 | 189 | size, |
| 167 | 190 | None, |
| 168 | 191 | scale, |
| 169 | 192 | vec | |
| 253 | + | |
| 254 | +```kdl | |
| 255 | +layout { | |
| 256 | + border { | |
| 257 | + active-gradient from="#f00f" to="#0f05" angle=45 in="oklch longer hue" | |
| 258 | + } | |
| 259 | +} | |
| 260 | +``` | |
| 261 | + | |
| 241 | 262 | ### `struts` |
| 242 | 263 | |
| 243 | 264 | Struts shrink the area occupied by windows, similarly to layer-shell panels. |
wiki/img/gradients-oklch.pngadded+3 -0
| @@ -0,0 +1,3 @@ | ||
| 1 | +version https://git-lfs.github.com/spec/v1 | |
| 2 | +oid sha256:a3e4db583ac849ec3bd6c2312a84a16eaad810ebb7599cad3762a7dfc66e865b | |
| 3 | +size 23180 |