layout/tiling: Resize shadows to fit scaled windows

This commit is contained in:
Victoria Brekenfeld 2025-12-16 18:48:40 +01:00 committed by Victoria Brekenfeld
parent 23e1bae96e
commit 6d0f1b273f
6 changed files with 57 additions and 44 deletions

View file

@ -596,7 +596,8 @@ impl CosmicMapped {
&self, &self,
renderer: &mut R, renderer: &mut R,
location: smithay::utils::Point<i32, smithay::utils::Physical>, location: smithay::utils::Point<i32, smithay::utils::Physical>,
scale: smithay::utils::Scale<f64>, output_scale: smithay::utils::Scale<f64>,
scale: f64,
alpha: f32, alpha: f32,
) -> Option<C> ) -> Option<C>
where where
@ -608,12 +609,20 @@ impl CosmicMapped {
match &self.element { match &self.element {
CosmicMappedInternal::Stack(s) => s CosmicMappedInternal::Stack(s) => s
.shadow_render_element::<R, CosmicMappedRenderElement<R>>( .shadow_render_element::<R, CosmicMappedRenderElement<R>>(
renderer, location, scale, alpha, renderer,
location,
output_scale,
scale,
alpha,
) )
.map(Into::into), .map(Into::into),
CosmicMappedInternal::Window(w) => w CosmicMappedInternal::Window(w) => w
.shadow_render_element::<R, CosmicMappedRenderElement<R>>( .shadow_render_element::<R, CosmicMappedRenderElement<R>>(
renderer, location, scale, alpha, renderer,
location,
output_scale,
scale,
alpha,
) )
.map(Into::into), .map(Into::into),
_ => unreachable!(), _ => unreachable!(),

View file

@ -660,7 +660,8 @@ impl CosmicStack {
&self, &self,
renderer: &mut R, renderer: &mut R,
location: Point<i32, Physical>, location: Point<i32, Physical>,
scale: Scale<f64>, output_scale: Scale<f64>,
scale: f64,
alpha: f32, alpha: f32,
) -> Option<C> ) -> Option<C>
where where
@ -690,13 +691,14 @@ impl CosmicStack {
.cosmic() .cosmic()
.radius_s() .radius_s()
.map(|x| if x < 4.0 { x } else { x + 4.0 }) .map(|x| if x < 4.0 { x } else { x + 4.0 })
.map(|x| x.round() as u8) .map(|x| (x * scale as f32).round() as u8)
}) })
.unwrap_or([0, 0, 0, 0]); .unwrap_or([0, 0, 0, 0]);
let mut geo = SpaceElement::geometry(&windows[active]).to_f64(); let mut geo = SpaceElement::geometry(&windows[active]).to_f64();
geo.loc += location.to_f64().to_logical(scale);
geo.size.h += TAB_HEIGHT as f64; geo.size.h += TAB_HEIGHT as f64;
geo = geo.upscale(scale);
geo.loc += location.to_f64().to_logical(output_scale);
let window_key = let window_key =
CosmicMappedKey(CosmicMappedKeyInner::Stack(Arc::downgrade(&self.0.0))); CosmicMappedKey(CosmicMappedKeyInner::Stack(Arc::downgrade(&self.0.0)));
@ -708,7 +710,7 @@ impl CosmicStack {
geo.to_i32_round().as_local(), geo.to_i32_round().as_local(),
radii, radii,
if activated { alpha } else { alpha * 0.75 }, if activated { alpha } else { alpha * 0.75 },
scale.x, output_scale.x,
)) ))
.into(), .into(),
) )

View file

@ -358,7 +358,8 @@ impl CosmicWindow {
&self, &self,
renderer: &mut R, renderer: &mut R,
location: Point<i32, Physical>, location: Point<i32, Physical>,
scale: Scale<f64>, output_scale: Scale<f64>,
scale: f64,
alpha: f32, alpha: f32,
) -> Option<C> ) -> Option<C>
where where
@ -394,7 +395,7 @@ impl CosmicWindow {
.cosmic() .cosmic()
.radius_s() .radius_s()
.map(|x| if x < 4.0 { x } else { x + 4.0 }) .map(|x| if x < 4.0 { x } else { x + 4.0 })
.map(|x| x.round() as u8); .map(|x| (x * scale as f32).round() as u8);
if has_ssd && !clip { if has_ssd && !clip {
// bottom corners // bottom corners
radii[0] = 0; radii[0] = 0;
@ -407,10 +408,11 @@ impl CosmicWindow {
} }
let mut geo = SpaceElement::geometry(&p.window).to_f64(); let mut geo = SpaceElement::geometry(&p.window).to_f64();
geo.loc += location.to_f64().to_logical(scale);
if has_ssd { if has_ssd {
geo.size.h += SSD_HEIGHT as f64; geo.size.h += SSD_HEIGHT as f64;
} }
geo = geo.upscale(scale);
geo.loc += location.to_f64().to_logical(output_scale);
let window_key = let window_key =
CosmicMappedKey(CosmicMappedKeyInner::Window(Arc::downgrade(&self.0.0))); CosmicMappedKey(CosmicMappedKeyInner::Window(Arc::downgrade(&self.0.0)));
@ -422,7 +424,7 @@ impl CosmicWindow {
geo.to_i32_round().as_local(), geo.to_i32_round().as_local(),
radii, radii,
if activated { alpha } else { alpha * 0.75 }, if activated { alpha } else { alpha * 0.75 },
scale.x, output_scale.x,
)) ))
.into(), .into(),
) )

View file

@ -209,6 +209,7 @@ impl MoveGrabState {
renderer, renderer,
(render_location - self.window.geometry().loc).to_physical_precise_round(output_scale), (render_location - self.window.geometry().loc).to_physical_precise_round(output_scale),
output_scale, output_scale,
scale,
alpha, alpha,
); );

View file

@ -1517,6 +1517,7 @@ impl FloatingLayout {
.as_logical() .as_logical()
.to_physical_precise_round(output_scale), .to_physical_precise_round(output_scale),
output_scale.into(), output_scale.into(),
1.,
alpha, alpha,
), ),
); );

View file

@ -4035,7 +4035,6 @@ impl TilingLayout {
let draw_groups = overview.0.alpha(); let draw_groups = overview.0.alpha();
let mut elements = Vec::default(); let mut elements = Vec::default();
let mut shadow_elements = Vec::default();
let is_overview = !matches!(overview.0, OverviewMode::None); let is_overview = !matches!(overview.0, OverviewMode::None);
let is_mouse_tiling = (matches!(overview.0.trigger(), Some(Trigger::Pointer(_)))) let is_mouse_tiling = (matches!(overview.0.trigger(), Some(Trigger::Pointer(_))))
@ -4078,7 +4077,6 @@ impl TilingLayout {
percentage, percentage,
indicator_thickness, indicator_thickness,
swap_desc.is_some(), swap_desc.is_some(),
&mut shadow_elements,
theme, theme,
)); ));
@ -4132,7 +4130,6 @@ impl TilingLayout {
overview, overview,
resize_indicator, resize_indicator,
swap_desc.clone(), swap_desc.clone(),
&mut shadow_elements,
&self.swapping_stack_surface_id, &self.swapping_stack_surface_id,
&self.backdrop_id, &self.backdrop_id,
theme, theme,
@ -4143,8 +4140,6 @@ impl TilingLayout {
elements.extend(group_elements); elements.extend(group_elements);
} }
elements.extend(shadow_elements);
Ok(elements) Ok(elements)
} }
@ -4993,7 +4988,6 @@ fn render_old_tree_windows<R>(
percentage: f32, percentage: f32,
indicator_thickness: u8, indicator_thickness: u8,
is_swap_mode: bool, is_swap_mode: bool,
shadow_elements: &mut Vec<CosmicMappedRenderElement<R>>,
theme: &cosmic::theme::CosmicTheme, theme: &cosmic::theme::CosmicTheme,
) -> Vec<CosmicMappedRenderElement<R>> ) -> Vec<CosmicMappedRenderElement<R>>
where where
@ -5005,6 +4999,7 @@ where
{ {
let window_hint = crate::theme::active_window_hint(theme); let window_hint = crate::theme::active_window_hint(theme);
let mut elements = Vec::default(); let mut elements = Vec::default();
let mut shadow_elements = Vec::default();
render_old_tree( render_old_tree(
reference_tree, reference_tree,
@ -5014,17 +5009,14 @@ where
percentage, percentage,
is_swap_mode, is_swap_mode,
|mapped, elem_geometry, geo, alpha, is_minimizing| { |mapped, elem_geometry, geo, alpha, is_minimizing| {
shadow_elements.extend( shadow_elements.extend(mapped.shadow_render_element(
mapped renderer,
.shadow_render_element( geo.loc.as_logical().to_physical_precise_round(output_scale) - elem_geometry.loc,
renderer, Scale::from(output_scale),
geo.loc.as_logical().to_physical_precise_round(output_scale) 1.,
- elem_geometry.loc, alpha,
Scale::from(output_scale), ));
alpha,
)
.into_iter(),
);
let window_elements = mapped.render_elements::<R, CosmicMappedRenderElement<R>>( let window_elements = mapped.render_elements::<R, CosmicMappedRenderElement<R>>(
renderer, renderer,
geo.loc.as_logical().to_physical_precise_round(output_scale) - elem_geometry.loc, geo.loc.as_logical().to_physical_precise_round(output_scale) - elem_geometry.loc,
@ -5079,7 +5071,10 @@ where
}, },
); );
elements shadow_elements
.into_iter()
.chain(elements.into_iter())
.collect()
} }
fn render_old_tree( fn render_old_tree(
@ -5237,7 +5232,6 @@ fn render_new_tree_windows<R>(
overview: (OverviewMode, Option<(SwapIndicator, Option<&Tree<Data>>)>), overview: (OverviewMode, Option<(SwapIndicator, Option<&Tree<Data>>)>),
mut resize_indicator: Option<(ResizeMode, ResizeIndicator)>, mut resize_indicator: Option<(ResizeMode, ResizeIndicator)>,
swap_desc: Option<NodeDesc>, swap_desc: Option<NodeDesc>,
shadow_elements: &mut Vec<CosmicMappedRenderElement<R>>,
swapping_stack_surface_id: &Id, swapping_stack_surface_id: &Id,
backdrop_id: &Id, backdrop_id: &Id,
theme: &cosmic::theme::CosmicTheme, theme: &cosmic::theme::CosmicTheme,
@ -5289,6 +5283,7 @@ where
let mut indicators = Vec::new(); let mut indicators = Vec::new();
let mut resize_elements = None; let mut resize_elements = None;
let mut swap_elements = Vec::new(); let mut swap_elements = Vec::new();
let mut shadow_elements = Vec::new();
let output_geo = output.geometry(); let output_geo = output.geometry();
let output_scale = output.current_scale().fractional_scale(); let output_scale = output.current_scale().fractional_scale();
@ -5387,7 +5382,7 @@ where
percentage, percentage,
swap_tree, swap_tree,
swap_desc.as_ref(), swap_desc.as_ref(),
|node_id, data, geo, _original_geo, alpha, animating| { |node_id, data, geo, original_geo, alpha, animating| {
if swap_desc.as_ref().map(|desc| &desc.node) == Some(&node_id) if swap_desc.as_ref().map(|desc| &desc.node) == Some(&node_id)
|| focused.as_ref() == Some(&node_id) || focused.as_ref() == Some(&node_id)
{ {
@ -5524,16 +5519,14 @@ where
if let Data::Mapped { mapped, .. } = data { if let Data::Mapped { mapped, .. } = data {
let elem_geometry = mapped.geometry().to_physical_precise_round(output_scale); let elem_geometry = mapped.geometry().to_physical_precise_round(output_scale);
shadow_elements.extend( let scale = geo.size.to_f64() / original_geo.size.to_f64();
mapped let shadow_element = mapped.shadow_render_element(
.shadow_render_element( renderer,
renderer, geo.loc.as_logical().to_physical_precise_round(output_scale)
geo.loc.as_logical().to_physical_precise_round(output_scale) - elem_geometry.loc,
- elem_geometry.loc, Scale::from(output_scale),
Scale::from(output_scale), scale.x.min(scale.y),
alpha, alpha,
)
.into_iter(),
); );
let mut elements = mapped.render_elements::<R, CosmicMappedRenderElement<R>>( let mut elements = mapped.render_elements::<R, CosmicMappedRenderElement<R>>(
renderer, renderer,
@ -5639,11 +5632,15 @@ where
}) })
.unwrap_or(false) .unwrap_or(false)
{ {
swap_elements.extend(shadow_element);
swap_elements.extend(elements); swap_elements.extend(elements);
} else if animating {
animating_window_elements.extend(elements);
} else { } else {
window_elements.extend(elements); shadow_elements.extend(shadow_element);
if animating {
animating_window_elements.extend(elements);
} else {
window_elements.extend(elements);
}
} }
} }
}, },
@ -5656,6 +5653,7 @@ where
.chain(indicators.into_iter().map(Into::into)) .chain(indicators.into_iter().map(Into::into))
.chain(window_elements) .chain(window_elements)
.chain(animating_window_elements) .chain(animating_window_elements)
.chain(shadow_elements)
.chain(group_backdrop.into_iter().map(Into::into)) .chain(group_backdrop.into_iter().map(Into::into))
.collect() .collect()
} }