reconfiguring fro css in

This commit is contained in:
K's Thinkpad 2024-07-06 13:30:19 +02:00
parent a745b7a5c0
commit 3aedbf7232
11 changed files with 141 additions and 109 deletions

View File

@ -413,8 +413,8 @@ pub struct Gradient {
pub angle: i16,
#[knuffel(property, default)]
pub relative_to: GradientRelativeTo,
#[knuffel(property, default)]
pub gradient_type: GradientType,
#[knuffel(child)]
pub _in: GradientInterpolation,
}
#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)]
@ -424,13 +424,30 @@ pub enum GradientRelativeTo {
WorkspaceView,
}
#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
pub struct GradientInterpolation {
#[knuffel(property, default)]
pub color_space: GradientColorSpace,
#[knuffel(property, default)]
pub hue_interpol: HueInterpolation
}
#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum GradientType {
pub enum GradientColorSpace {
#[default]
CssLinear,
Linear,
Srgb,
SrgbLinear,
Oklab,
Lch,
XyzD50,
}
#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum HueInterpolation {
#[default]
Shorter,
Longer,
Increasing,
Decreasing,
}
#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]

View File

@ -1,7 +1,7 @@
use std::iter::zip;
use arrayvec::ArrayVec;
use niri_config::{CornerRadius, Gradient, GradientRelativeTo, GradientType};
use niri_config::{CornerRadius, Gradient, GradientRelativeTo, GradientInterpolation, GradientColorSpace, HueInterpolation};
use smithay::backend::renderer::element::Kind;
use smithay::utils::{Logical, Point, Rectangle, Size};
@ -91,7 +91,10 @@ impl FocusRing {
to: color,
angle: 0,
relative_to: GradientRelativeTo::Window,
gradient_type: GradientType::CssLinear,
_in: GradientInterpolation {
color_space: GradientColorSpace::Srgb,
hue_interpol: HueInterpolation::Shorter
}
});
let full_rect = Rectangle::from_loc_and_size((-width, -width), self.full_size);
@ -100,12 +103,8 @@ impl FocusRing {
GradientRelativeTo::WorkspaceView => view_rect,
};
let gradient_format = match gradient.gradient_type {
GradientType::CssLinear => 0.,
GradientType::Linear => 1.,
GradientType::Oklab => 2.,
GradientType::Lch => 3.,
};
let gradient_format = gradient._in;
let rounded_corner_border_width = if self.is_border {
// HACK: increase the border width used for the inner rounded corners a tiny bit to

View File

@ -1,7 +1,7 @@
use std::rc::Rc;
use std::time::Duration;
use niri_config::CornerRadius;
use niri_config::{CornerRadius, GradientInterpolation, GradientColorSpace, HueInterpolation};
use smithay::backend::allocator::Fourcc;
use smithay::backend::renderer::element::{Element, Kind};
use smithay::backend::renderer::gles::GlesRenderer;
@ -757,7 +757,10 @@ impl<W: LayoutElement> Tile<W> {
return BorderRenderElement::new(
geo.size,
Rectangle::from_loc_and_size((0., 0.), geo.size),
0.,
GradientInterpolation{
color_space: GradientColorSpace::Srgb,
hue_interpol: HueInterpolation::Shorter
},
elem.color(),
elem.color(),
0.,

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use glam::{Mat3, Vec2};
use niri_config::CornerRadius;
use niri_config::{CornerRadius, GradientInterpolation, GradientColorSpace, HueInterpolation};
use smithay::backend::renderer::element::{Element, Id, Kind, RenderElement, UnderlyingStorage};
use smithay::backend::renderer::gles::{GlesError, GlesFrame, GlesRenderer, Uniform};
use smithay::backend::renderer::utils::{CommitCounter, DamageSet, OpaqueRegions};
@ -28,7 +28,7 @@ pub struct BorderRenderElement {
struct Parameters {
size: Size<f64, Logical>,
gradient_area: Rectangle<f64, Logical>,
gradient_format: f32,
gradient_format: GradientInterpolation,
color_from: [f32; 4],
color_to: [f32; 4],
angle: f32,
@ -44,7 +44,7 @@ impl BorderRenderElement {
pub fn new(
size: Size<f64, Logical>,
gradient_area: Rectangle<f64, Logical>,
gradient_format: f32,
gradient_format: GradientInterpolation,
color_from: [f32; 4],
color_to: [f32; 4],
angle: f32,
@ -80,7 +80,10 @@ impl BorderRenderElement {
params: Parameters {
size: Default::default(),
gradient_area: Default::default(),
gradient_format: 0.,
gradient_format: GradientInterpolation {
color_space: GradientColorSpace::Srgb,
hue_interpol: HueInterpolation::Shorter
},
color_from: Default::default(),
color_to: Default::default(),
angle: 0.,
@ -101,7 +104,7 @@ impl BorderRenderElement {
&mut self,
size: Size<f64, Logical>,
gradient_area: Rectangle<f64, Logical>,
gradient_format: f32,
gradient_format: GradientInterpolation,
color_from: [f32; 4],
color_to: [f32; 4],
angle: f32,
@ -169,12 +172,27 @@ impl BorderRenderElement {
let input_to_geo =
Mat3::from_scale(area_size) * Mat3::from_translation(-geo_loc / area_size);
let colorspace = match gradient_format.color_space {
GradientColorSpace::Srgb => 0.,
GradientColorSpace::SrgbLinear => 1.,
GradientColorSpace::Oklab => 2.,
GradientColorSpace::XyzD50 => 3.
};
let hue_interpolation = match gradient_format.hue_interpol {
HueInterpolation::Shorter => 0.,
HueInterpolation::Longer => 1.,
HueInterpolation::Increasing => 2.,
HueInterpolation::Decreasing => 3.
};
self.inner.update(
size,
None,
scale,
vec![
Uniform::new("grad_format", gradient_format),
Uniform::new("colorspace", colorspace),
Uniform::new("hue_interpolation", hue_interpolation),
Uniform::new("color_from", color_from),
Uniform::new("color_to", color_to),
Uniform::new("grad_offset", grad_offset.to_array()),

View File

@ -1,3 +1,75 @@
precision mediump float;
#if defined(DEBUG_FLAGS)
uniform float niri_tint;
#endif
uniform float niri_alpha;
uniform float niri_scale;
uniform vec2 niri_size;
varying vec2 niri_v_coords;
uniform float colorspace;
uniform float hue_interpolation;
uniform vec4 color_from;
uniform vec4 color_to;
uniform vec2 grad_offset;
uniform float grad_width;
uniform vec2 grad_vec;
uniform mat3 input_to_geo;
uniform vec2 geo_size;
uniform vec4 outer_radius;
uniform float border_width;
vec4 srgb_to_linear(vec4 color) {
return vec4(
(color.rgb / color.aaa) * (color.rgb / color.aaa),
color.a
);
}
vec4 linear_to_srgb(vec4 color) {
return vec4(
sqrt(color.r) * color.a,
sqrt(color.g) * color.a,
sqrt(color.b) * color.a,
color.a
);
}
vec4 color_mix(vec4 color1, vec4 color2, float color_ratio) {
if (colorspace == 0.0) // srgb
return mix(color1, color2, color_ratio);
vec4 color_out;
color1 = srgb_to_linear(color1);
color2 = srgb_to_linear(color2);
if (colorspace == 1.0) { // srgb-linear
color_out = mix(
color1,
color2,
color_ratio
);
} else if (colorspace == 2.0) { // oklab
color1 = xyz_to_oklab(linear_to_xyz(color1));
color2 = xyz_to_oklab(linear_to_xyz(color2));
color_out =
} else {
color_out = vec4(
255.0,
0.0,
0.0,
1.0
);
}
return linear_to_srgb(color_out);
}
vec4 gradient_color(vec2 coords) {
coords = coords + grad_offset;

View File

@ -1,30 +0,0 @@
precision mediump float;
#if defined(DEBUG_FLAGS)
uniform float niri_tint;
#endif
uniform float niri_alpha;
uniform float niri_scale;
uniform vec2 niri_size;
varying vec2 niri_v_coords;
uniform float grad_format;
uniform vec4 color_from;
uniform vec4 color_to;
uniform vec2 grad_offset;
uniform float grad_width;
uniform vec2 grad_vec;
uniform mat3 input_to_geo;
uniform vec2 geo_size;
uniform vec4 outer_radius;
uniform float border_width;
// FIXME this is a terrible solution however,
// I need to insert a different file with
// functions after this part as adding them ahead will cause errors at runtime
// and havent found a clean way to do this
// this is prob super simple and im just too stupid

View File

@ -1,42 +0,0 @@
vec4 color_linear(vec4 color) {
return vec4(
pow(color.r, 2.0),
pow(color.g, 2.0),
pow(color.b, 2.0),
color.a
);
}
vec4 color_root(vec4 color) {
return vec4(
sqrt(color.r),
sqrt(color.g),
sqrt(color.b),
color.a
);
}
vec4 color_mix(vec4 color1, vec4 color2, float color_ratio) {
if(grad_format == 0.0) { // CssLinear
return mix(color1, color2, color_ratio);
}
vec4 color_out;
color1 = color_linear(color1);
color2 = color_linear(color2);
if (grad_format == 1.0) { // rgb linear
color_out = mix(
color1,
color2,
color_ratio
);
}else{
color_out = vec4(255.0,0.0,0.0,1.0);
}
return color_root(color_out);
}

View File

@ -32,13 +32,10 @@ impl Shaders {
let border = ShaderProgram::compile(
renderer,
concat!(
include_str!("border_head.frag"),
include_str!("color_interpol.frag"),
include_str!("border.frag")
),
include_str!("border.frag"),
&[
UniformName::new("grad_format", UniformType::_1f),
UniformName::new("colorspace", UniformType::_1f),
UniformName::new("hue_interpolation", UniformType::_1f),
UniformName::new("color_from", UniformType::_4f),
UniformName::new("color_to", UniformType::_4f),
UniformName::new("grad_offset", UniformType::_2f),
@ -73,10 +70,7 @@ impl Shaders {
let resize = compile_resize_program(
renderer,
concat!(
include_str!("color_interpol.frag"),
include_str!("resize.frag")
)
include_str!("resize.frag")
)
.map_err(|err| {
warn!("error compiling resize shader: {err:?}");
@ -161,7 +155,6 @@ fn compile_resize_program(
renderer,
&program,
&[
UniformName::new("grad_format", UniformType::_1f),
UniformName::new("niri_input_to_curr_geo", UniformType::Matrix3x3),
UniformName::new("niri_curr_geo_to_prev_geo", UniformType::Matrix3x3),
UniformName::new("niri_curr_geo_to_next_geo", UniformType::Matrix3x3),

View File

@ -5,6 +5,6 @@ vec4 resize_color(vec3 coords_curr_geo, vec3 size_curr_geo) {
vec3 coords_tex_next = niri_geo_to_tex_next * coords_curr_geo;
vec4 color_next = texture2D(niri_tex_next, coords_tex_next.st);
vec4 color = color_mix(color_prev, color_next, niri_clamped_progress);
vec4 color = mix(color_prev, color_next, niri_clamped_progress);
return color;
}

View File

@ -7,7 +7,6 @@ uniform float niri_tint;
varying vec2 niri_v_coords;
uniform vec2 niri_size;
uniform float grad_format;
uniform mat3 niri_input_to_curr_geo;
uniform mat3 niri_curr_geo_to_prev_geo;
uniform mat3 niri_curr_geo_to_next_geo;

View File

@ -2,7 +2,7 @@ use std::cell::{Cell, RefCell};
use std::cmp::{max, min};
use std::time::Duration;
use niri_config::{CornerRadius, WindowRule};
use niri_config::{CornerRadius, GradientColorSpace, GradientInterpolation, HueInterpolation, WindowRule};
use smithay::backend::renderer::element::surface::render_elements_from_surface_tree;
use smithay::backend::renderer::element::{Id, Kind};
use smithay::backend::renderer::gles::GlesRenderer;
@ -289,7 +289,10 @@ impl Mapped {
return BorderRenderElement::new(
geo.size,
Rectangle::from_loc_and_size((0., 0.), geo.size),
0.,
GradientInterpolation{
color_space: GradientColorSpace::Srgb,
hue_interpol: HueInterpolation::Shorter
},
elem.color(),
elem.color(),
0.,