Skip to content

Commit 3465ce7

Browse files
wash2Drakulix
authored andcommitted
feat: corner radius for CosmicMapped
1 parent 228af10 commit 3465ce7

File tree

7 files changed

+49
-23
lines changed

7 files changed

+49
-23
lines changed

src/backend/render/shaders/rounded_rectangle.frag

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,29 @@ varying vec2 v_coords;
99
uniform vec3 color;
1010
uniform float radius;
1111

12-
float rounded_box(vec2 center, vec2 size, float radius) {
13-
return length(max(abs(center) - size + radius, 0.0)) - radius;
12+
float rounded_box(in vec2 p, in vec2 b, in vec4 r)
13+
{
14+
r.xy = (p.x > 0.0) ? r.xy : r.zw;
15+
r.x = (p.y > 0.0) ? r.x : r.y;
16+
vec2 q = abs(p) - b + r.x;
17+
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;
1418
}
1519

1620
void main() {
1721
vec2 center = size / 2.0;
1822
vec2 location = v_coords * size;
1923
vec4 mix_color;
24+
vec4 corners = vec4(radius);
2025

21-
float distance = rounded_box(location - center, size / 2.0, radius);
26+
float distance = rounded_box(location - center, size / 2.0, corners);
2227
float smoothedAlpha = 1.0 - smoothstep(0.0, 1.0, distance);
23-
28+
2429
mix_color = mix(vec4(0.0, 0.0, 0.0, 0.0), vec4(color, alpha), smoothedAlpha);
25-
26-
#if defined(DEBUG_FLAGS)
30+
31+
#if defined(DEBUG_FLAGS)
2732
if (tint == 1.0)
2833
mix_color = vec4(0.0, 0.3, 0.0, 0.2) + mix_color * 0.8;
29-
#endif
34+
#endif
3035

3136
gl_FragColor = mix_color;
32-
}
37+
}

src/shell/element/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,16 @@ impl CosmicMapped {
848848
_ => unreachable!(),
849849
}
850850
}
851+
852+
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>, default_radius: u8) -> [u8; 4] {
853+
match &self.element {
854+
CosmicMappedInternal::Window(w) => w
855+
.corner_radius(geometry_size)
856+
.unwrap_or([default_radius; 4]),
857+
CosmicMappedInternal::Stack(s) => s.corner_radius(geometry_size, default_radius),
858+
_ => unreachable!(),
859+
}
860+
}
851861
}
852862

853863
impl IsAlive for CosmicMapped {

src/shell/element/stack.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,20 @@ impl CosmicStack {
785785
(Some(max), Some(min)) => Some((max.w.max(min.w), max.h.max(min.h)).into()),
786786
}
787787
}
788+
789+
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>, default_radius: u8) -> [u8; 4] {
790+
self.0.with_program(|p| {
791+
let active_window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)];
792+
let mut corners = active_window
793+
.corner_radius(geometry_size)
794+
.unwrap_or([default_radius; 4]);
795+
796+
corners[1] = 8;
797+
corners[3] = 8;
798+
799+
corners
800+
})
801+
}
788802
}
789803

790804
#[derive(Debug, Clone, Copy)]

src/shell/element/window.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ impl CosmicWindow {
421421
}
422422
})
423423
}
424+
425+
pub fn corner_radius(&self, geometry_size: Size<i32, Logical>) -> Option<[u8; 4]> {
426+
self.0
427+
.with_program(|p| p.window.corner_radius(geometry_size))
428+
}
424429
}
425430

426431
#[derive(Debug, Clone, Copy)]

src/shell/grabs/moving.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ impl MoveGrabState {
110110

111111
let active_window_hint = crate::theme::active_window_hint(theme);
112112
let radius = self
113-
.window()
114-
.corner_radius(window_geo.size)
115-
.unwrap_or([self.indicator_thickness; 4]);
113+
.element()
114+
.corner_radius(window_geo.size, self.indicator_thickness);
116115

117116
let focus_element = if self.indicator_thickness > 0 {
118117
Some(

src/shell/layout/floating/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,10 +1589,7 @@ impl FloatingLayout {
15891589
}
15901590

15911591
let active_window_hint = crate::theme::active_window_hint(theme);
1592-
let radius = elem
1593-
.active_window()
1594-
.corner_radius(geometry.size.as_logical())
1595-
.unwrap_or([indicator_thickness; 4]);
1592+
let radius = elem.corner_radius(geometry.size.as_logical(), indicator_thickness);
15961593
if indicator_thickness > 0 {
15971594
let element = IndicatorShader::focus_element(
15981595
renderer,

src/shell/layout/tiling/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5015,10 +5015,7 @@ where
50155015
x => Some(x),
50165016
}
50175017
}));
5018-
let radius = mapped
5019-
.active_window()
5020-
.corner_radius(geo.size.as_logical())
5021-
.unwrap_or([indicator_thickness; 4]);
5018+
let radius = mapped.corner_radius(geo.size.as_logical(), indicator_thickness);
50225019
if is_minimizing && indicator_thickness > 0 {
50235020
elements.push(CosmicMappedRenderElement::FocusIndicator(
50245021
IndicatorShader::focus_element(
@@ -5369,10 +5366,9 @@ where
53695366
));
53705367
}
53715368
let radius = match data {
5372-
Data::Mapped { mapped, .. } => mapped
5373-
.active_window()
5374-
.corner_radius(geo.size.as_logical())
5375-
.unwrap_or([indicator_thickness; 4]),
5369+
Data::Mapped { mapped, .. } => {
5370+
mapped.corner_radius(geo.size.as_logical(), indicator_thickness)
5371+
}
53765372
_ => [1; 4],
53775373
};
53785374
if !swap_desc

0 commit comments

Comments
 (0)