Skip to content

Commit 64bbfbe

Browse files
committed
fix: are_transitions_ongoing condition and border fade implementation
1 parent 6b15272 commit 64bbfbe

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

src/layout/focus_ring.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl FocusRing {
6767
alpha: f32,
6868
exponent: f32,
6969
gradient_angle_offset: f32,
70+
mix_ratio: f32,
7071
) {
7172
let width = self.config.width;
7273
self.full_size = win_size + Size::from((width, width)).upscale(2.);
@@ -86,6 +87,24 @@ impl FocusRing {
8687

8788
let radius = radius.fit_to(self.full_size.w as f32, self.full_size.h as f32);
8889

90+
fn mix_color(active: Gradient, inactive: Gradient, mix_ratio: f32) -> Gradient {
91+
let t = mix_ratio;
92+
let inv = 1. - mix_ratio;
93+
94+
let mut new = active.clone();
95+
new.from.r = active.from.r * t + inactive.from.r * inv;
96+
new.from.g = active.from.g * t + inactive.from.g * inv;
97+
new.from.b = active.from.b * t + inactive.from.b * inv;
98+
new.from.a = active.from.a * t + inactive.from.a * inv;
99+
100+
new.to.r = active.to.r * t + inactive.to.r * inv;
101+
new.to.g = active.to.g * t + inactive.to.g * inv;
102+
new.to.b = active.to.b * t + inactive.to.b * inv;
103+
new.to.a = active.to.a * t + inactive.to.a * inv;
104+
105+
new
106+
}
107+
89108
let gradient = if is_urgent {
90109
self.config.urgent_gradient
91110
} else if is_active {
@@ -97,7 +116,38 @@ impl FocusRing {
97116
self.use_border_shader = radius != CornerRadius::default() || gradient.is_some();
98117

99118
// Set the defaults for solid color + rounded corners.
100-
let gradient = gradient.unwrap_or_else(|| Gradient::from(color));
119+
// let gradient = gradient.unwrap_or_else(|| Gradient::from(color));
120+
let gradient = if is_urgent {
121+
mix_color(
122+
self.config
123+
.urgent_gradient
124+
.unwrap_or_else(|| Gradient::from(self.config.urgent_color)),
125+
self.config
126+
.inactive_gradient
127+
.unwrap_or_else(|| Gradient::from(self.config.inactive_color)),
128+
mix_ratio,
129+
)
130+
} else if is_active {
131+
mix_color(
132+
self.config
133+
.active_gradient
134+
.unwrap_or_else(|| Gradient::from(self.config.active_color)),
135+
self.config
136+
.inactive_gradient
137+
.unwrap_or_else(|| Gradient::from(self.config.inactive_color)),
138+
mix_ratio,
139+
)
140+
} else {
141+
mix_color(
142+
self.config
143+
.active_gradient
144+
.unwrap_or_else(|| Gradient::from(self.config.active_color)),
145+
self.config
146+
.inactive_gradient
147+
.unwrap_or_else(|| Gradient::from(self.config.inactive_color)),
148+
mix_ratio,
149+
)
150+
};
101151

102152
let full_rect = Rectangle::new(Point::from((-width, -width)), self.full_size);
103153
let gradient_area = match gradient.relative_to {

src/layout/insert_hint_element.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl InsertHintElement {
5656
scale: f64,
5757
) {
5858
self.inner.update_render_elements(
59-
size, true, false, false, view_rect, radius, scale, 1., 2.8, 0.,
59+
size, true, false, false, view_rect, radius, scale, 1., 2.8, 0., 1.,
6060
);
6161
}
6262

src/layout/tile.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,12 @@ impl<W: LayoutElement> Tile<W> {
481481
.focus_ring_anim
482482
.as_ref()
483483
.is_some_and(|anim| !anim.is_done())
484-
|| (self.was_focus_active && self.options.layout.focus_ring.gradient_spin_speed > 0.)
485-
|| (self.was_focus_active && self.options.layout.border.gradient_spin_speed > 0.)
484+
|| (self.was_focus_active
485+
&& !self.options.layout.focus_ring.off
486+
&& self.options.layout.focus_ring.gradient_spin_speed > 0.)
487+
|| (self.was_focus_active
488+
&& !self.options.layout.border.off
489+
&& self.options.layout.border.gradient_spin_speed > 0.)
486490
}
487491

488492
pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
@@ -549,7 +553,13 @@ impl<W: LayoutElement> Tile<W> {
549553
};
550554
let radius = radius.expanded_by(self.focus_ring.width() as f32);
551555

552-
let fade_ms = self.options.layout.focus_ring.fade_duration_ms;
556+
let fade_ms = if !self.options.layout.focus_ring.off {
557+
self.options.layout.focus_ring.fade_duration_ms
558+
} else if !self.options.layout.border.off {
559+
self.options.layout.border.fade_duration_ms
560+
} else {
561+
0
562+
};
553563

554564
// Animate focus ring fade in/out on focus change.
555565
if is_active != self.was_focus_active {
@@ -619,6 +629,7 @@ impl<W: LayoutElement> Tile<W> {
619629
focus_ring_alpha * (1. - expanded_progress as f32),
620630
exponent,
621631
gradient_angle_offset,
632+
1.,
622633
);
623634

624635
self.border.update_render_elements(
@@ -635,6 +646,7 @@ impl<W: LayoutElement> Tile<W> {
635646
1. - expanded_progress as f32,
636647
exponent,
637648
gradient_angle_offset,
649+
focus_ring_alpha * (1. - expanded_progress as f32),
638650
);
639651

640652
self.fullscreen_backdrop.resize(animated_tile_size);

src/ui/mru.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ impl Thumbnail {
546546
0.5,
547547
exponent,
548548
0.,
549+
1.,
549550
);
550551
background.render(ctx.renderer, loc, &mut |elem| {
551552
push(WindowMruUiRenderElement::FocusRing(elem))
@@ -569,6 +570,7 @@ impl Thumbnail {
569570
1.,
570571
exponent,
571572
0.,
573+
1.,
572574
);
573575

574576
border.render(ctx.renderer, loc, &mut |elem| {

0 commit comments

Comments
 (0)