Add unified window focus opacity and dimming effects
This commit is contained in:
1 parent
02ec7e5199
commit
bbc5b27c25
21 files changed
+553
-342
No files matched your search
@@ -15,7 +15,6 @@ pub(crate) struct ClosedWindow {
|
||||
pub radius: f64,
|
||||
pub shape: CornerShape,
|
||||
pub decorations: f64,
|
||||
pub dim: f64,
|
||||
pub fill: Option<[f32; 4]>,
|
||||
pub material: Option<(
|
||||
smithay::reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
@@ -110,7 +109,7 @@ pub(super) fn grouped_elements(
|
||||
window.presentation.id,
|
||||
constrain,
|
||||
corners,
|
||||
[0.0, 0.0, 0.0, window.dim as f32 * alpha],
|
||||
[0.0, 0.0, 0.0, window.presentation.dim as f32 * alpha],
|
||||
false,
|
||||
output,
|
||||
) {
|
||||
|
||||
@@ -153,10 +153,17 @@ fn scene_elements(
|
||||
}
|
||||
let sample = frame.windows.get(&id)?;
|
||||
let visual = sample.presentation.bounds.current;
|
||||
let close_alpha = sample.presentation.alpha();
|
||||
let presentation_alpha = sample.presentation.alpha();
|
||||
let decoration_progress = sample.geometry.decorations.clamp(0.0, 1.0);
|
||||
|
||||
Some((window.clone(), id, sample, visual, decoration_progress, close_alpha))
|
||||
Some((
|
||||
window.clone(),
|
||||
id,
|
||||
sample,
|
||||
visual,
|
||||
decoration_progress,
|
||||
presentation_alpha,
|
||||
))
|
||||
};
|
||||
let windows = if state.overview.is_active() {
|
||||
state
|
||||
@@ -180,7 +187,7 @@ fn scene_elements(
|
||||
windows.iter().map(|(_, id, ..)| *id),
|
||||
frame.delta,
|
||||
);
|
||||
for (window, id, sample, visual, decoration_progress, close_alpha) in windows {
|
||||
for (window, id, sample, visual, decoration_progress, presentation_alpha) in windows {
|
||||
if let Some(group) = closing.remove(&Some(id)) {
|
||||
elements.extend(group);
|
||||
}
|
||||
@@ -205,14 +212,14 @@ fn scene_elements(
|
||||
let scale_content = sample.presentation.scale_content;
|
||||
let behavior = resize_content_behavior(scale_content);
|
||||
|
||||
let dim = sample.dim;
|
||||
let dim = sample.presentation.dim;
|
||||
if let Some(overlay) = window_tint_element(
|
||||
&mut state.render,
|
||||
renderer,
|
||||
id,
|
||||
constrain,
|
||||
corners,
|
||||
[0.0, 0.0, 0.0, dim as f32 * close_alpha],
|
||||
[0.0, 0.0, 0.0, dim as f32 * presentation_alpha],
|
||||
false,
|
||||
output,
|
||||
) {
|
||||
@@ -244,7 +251,7 @@ fn scene_elements(
|
||||
border_color,
|
||||
gradient,
|
||||
focus as f32,
|
||||
close_alpha * decoration_progress as f32,
|
||||
presentation_alpha * decoration_progress as f32,
|
||||
output,
|
||||
&programs,
|
||||
) {
|
||||
@@ -260,7 +267,7 @@ fn scene_elements(
|
||||
scale,
|
||||
shadow_offset_y * offset_factor,
|
||||
shadow_blur * blur_factor,
|
||||
shadow_opacity * opacity_factor * f64::from(close_alpha) * decoration_progress,
|
||||
shadow_opacity * opacity_factor * f64::from(presentation_alpha) * decoration_progress,
|
||||
shadow_color,
|
||||
output,
|
||||
&programs,
|
||||
@@ -286,7 +293,7 @@ fn scene_elements(
|
||||
&window,
|
||||
corners,
|
||||
scale,
|
||||
close_alpha,
|
||||
presentation_alpha,
|
||||
sample.geometry.presentation_changed || corner_shape_changed,
|
||||
output,
|
||||
programs.clone(),
|
||||
@@ -299,7 +306,7 @@ fn scene_elements(
|
||||
&& (source.w < constrain.size.w || source.h < constrain.size.h)
|
||||
{
|
||||
let mut color = state.theme_settings.surface_base_color.0;
|
||||
color[3] = close_alpha;
|
||||
color[3] = presentation_alpha;
|
||||
if let Some(fill) =
|
||||
window_tint_element(&mut state.render, renderer, id, constrain, corners, color, true, output)
|
||||
{
|
||||
@@ -321,7 +328,7 @@ fn scene_elements(
|
||||
corners,
|
||||
index: 0,
|
||||
capture_geometry: constrain,
|
||||
alpha: close_alpha,
|
||||
alpha: presentation_alpha,
|
||||
},
|
||||
)
|
||||
{
|
||||
@@ -335,7 +342,7 @@ fn scene_elements(
|
||||
renderer,
|
||||
&window,
|
||||
constrain.loc,
|
||||
close_alpha,
|
||||
presentation_alpha,
|
||||
scale,
|
||||
constrain,
|
||||
ConstrainBehavior {
|
||||
|
||||
@@ -84,8 +84,13 @@ mod tests {
|
||||
);
|
||||
let mut resources = RenderResources::default();
|
||||
let programs = corner_program(&mut resources, &mut renderer, CornerShape::Continuous).unwrap();
|
||||
for scale in [1.0, 1.25, 1.5, 2.0] {
|
||||
for (scale, focus_alpha) in [1.0, 1.25, 1.5, 2.0]
|
||||
.into_iter()
|
||||
.flat_map(|scale| [1.0, 0.8].map(|alpha| (scale, alpha)))
|
||||
{
|
||||
let live = crate::presentation::WindowPresentation {
|
||||
focus_alpha,
|
||||
dim: 0.0,
|
||||
id: ferese_layout::WindowId(1),
|
||||
bounds: AnimatedRect::new(ferese_layout::Rect::new(20.25, 20.5, 32.25, 24.25)),
|
||||
opacity: AnimatedValue::new(1.0),
|
||||
@@ -147,7 +152,16 @@ mod tests {
|
||||
pixels.push(renderer.map_texture(&mapping).unwrap().to_vec());
|
||||
}
|
||||
assert_eq!(pixels[0], pixels[1], "close handoff changed pixels at scale {scale}");
|
||||
assert!(pixels[0].chunks_exact(4).any(|pixel| pixel[3] == 255));
|
||||
let expected = (focus_alpha * 255.0).round() as u8;
|
||||
assert!(
|
||||
pixels[0].chunks_exact(4).any(|pixel| pixel[3].abs_diff(expected) <= 1),
|
||||
"snapshot alpha must be applied once"
|
||||
);
|
||||
assert!(
|
||||
pixels[0]
|
||||
.chunks_exact(4)
|
||||
.all(|pixel| pixel[3] <= expected.saturating_add(1))
|
||||
);
|
||||
let mut retained = super::super::closing::ClosedWindow {
|
||||
presentation: closing,
|
||||
output: ferese_core::OutputId(1),
|
||||
@@ -157,7 +171,6 @@ mod tests {
|
||||
radius: 8.0,
|
||||
shape: CornerShape::Continuous,
|
||||
decorations: 1.0,
|
||||
dim: 0.0,
|
||||
fill: None,
|
||||
material: None,
|
||||
};
|
||||
@@ -166,6 +179,7 @@ mod tests {
|
||||
retained.handoff.as_mut().unwrap().0.elapsed = Duration::from_millis(20);
|
||||
let mut predicted = retained.clone();
|
||||
predicted.advance(Duration::from_millis(20), Default::default());
|
||||
assert_eq!(predicted.presentation.focus_alpha, focus_alpha);
|
||||
let faded = &predicted.handoff.as_ref().unwrap().0;
|
||||
assert_eq!(faded.elapsed, Duration::from_millis(40));
|
||||
assert_eq!(retained.handoff.as_ref().unwrap().0.elapsed, Duration::from_millis(20));
|
||||
|
||||
Reference in new issue
Block a user