feat: corner radius for CosmicMapped
This commit is contained in:
parent
228af1037a
commit
3465ce7602
7 changed files with 49 additions and 23 deletions
|
|
@ -9,24 +9,29 @@ varying vec2 v_coords;
|
|||
uniform vec3 color;
|
||||
uniform float radius;
|
||||
|
||||
float rounded_box(vec2 center, vec2 size, float radius) {
|
||||
return length(max(abs(center) - size + radius, 0.0)) - radius;
|
||||
float rounded_box(in vec2 p, in vec2 b, in vec4 r)
|
||||
{
|
||||
r.xy = (p.x > 0.0) ? r.xy : r.zw;
|
||||
r.x = (p.y > 0.0) ? r.x : r.y;
|
||||
vec2 q = abs(p) - b + r.x;
|
||||
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 center = size / 2.0;
|
||||
vec2 location = v_coords * size;
|
||||
vec4 mix_color;
|
||||
vec4 corners = vec4(radius);
|
||||
|
||||
float distance = rounded_box(location - center, size / 2.0, radius);
|
||||
float distance = rounded_box(location - center, size / 2.0, corners);
|
||||
float smoothedAlpha = 1.0 - smoothstep(0.0, 1.0, distance);
|
||||
|
||||
|
||||
mix_color = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(color, alpha), smoothedAlpha);
|
||||
|
||||
#if defined(DEBUG_FLAGS)
|
||||
|
||||
#if defined(DEBUG_FLAGS)
|
||||
if (tint == 1.0)
|
||||
mix_color = vec4(0.0, 0.3, 0.0, 0.2) + mix_color * 0.8;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = mix_color;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -848,6 +848,16 @@ impl CosmicMapped {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>, default_radius: u8) -> [u8; 4] {
|
||||
match &self.element {
|
||||
CosmicMappedInternal::Window(w) => w
|
||||
.corner_radius(geometry_size)
|
||||
.unwrap_or([default_radius; 4]),
|
||||
CosmicMappedInternal::Stack(s) => s.corner_radius(geometry_size, default_radius),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IsAlive for CosmicMapped {
|
||||
|
|
|
|||
|
|
@ -785,6 +785,20 @@ impl CosmicStack {
|
|||
(Some(max), Some(min)) => Some((max.w.max(min.w), max.h.max(min.h)).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>, default_radius: u8) -> [u8; 4] {
|
||||
self.0.with_program(|p| {
|
||||
let active_window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)];
|
||||
let mut corners = active_window
|
||||
.corner_radius(geometry_size)
|
||||
.unwrap_or([default_radius; 4]);
|
||||
|
||||
corners[1] = 8;
|
||||
corners[3] = 8;
|
||||
|
||||
corners
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
|
|||
|
|
@ -421,6 +421,11 @@ impl CosmicWindow {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>) -> Option<[u8; 4]> {
|
||||
self.0
|
||||
.with_program(|p| p.window.corner_radius(geometry_size))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
|
|||
|
|
@ -110,9 +110,8 @@ impl MoveGrabState {
|
|||
|
||||
let active_window_hint = crate::theme::active_window_hint(theme);
|
||||
let radius = self
|
||||
.window()
|
||||
.corner_radius(window_geo.size)
|
||||
.unwrap_or([self.indicator_thickness; 4]);
|
||||
.element()
|
||||
.corner_radius(window_geo.size, self.indicator_thickness);
|
||||
|
||||
let focus_element = if self.indicator_thickness > 0 {
|
||||
Some(
|
||||
|
|
|
|||
|
|
@ -1589,10 +1589,7 @@ impl FloatingLayout {
|
|||
}
|
||||
|
||||
let active_window_hint = crate::theme::active_window_hint(theme);
|
||||
let radius = elem
|
||||
.active_window()
|
||||
.corner_radius(geometry.size.as_logical())
|
||||
.unwrap_or([indicator_thickness; 4]);
|
||||
let radius = elem.corner_radius(geometry.size.as_logical(), indicator_thickness);
|
||||
if indicator_thickness > 0 {
|
||||
let element = IndicatorShader::focus_element(
|
||||
renderer,
|
||||
|
|
|
|||
|
|
@ -5015,10 +5015,7 @@ where
|
|||
x => Some(x),
|
||||
}
|
||||
}));
|
||||
let radius = mapped
|
||||
.active_window()
|
||||
.corner_radius(geo.size.as_logical())
|
||||
.unwrap_or([indicator_thickness; 4]);
|
||||
let radius = mapped.corner_radius(geo.size.as_logical(), indicator_thickness);
|
||||
if is_minimizing && indicator_thickness > 0 {
|
||||
elements.push(CosmicMappedRenderElement::FocusIndicator(
|
||||
IndicatorShader::focus_element(
|
||||
|
|
@ -5369,10 +5366,9 @@ where
|
|||
));
|
||||
}
|
||||
let radius = match data {
|
||||
Data::Mapped { mapped, .. } => mapped
|
||||
.active_window()
|
||||
.corner_radius(geo.size.as_logical())
|
||||
.unwrap_or([indicator_thickness; 4]),
|
||||
Data::Mapped { mapped, .. } => {
|
||||
mapped.corner_radius(geo.size.as_logical(), indicator_thickness)
|
||||
}
|
||||
_ => [1; 4],
|
||||
};
|
||||
if !swap_desc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue