Skip to content

Commit

Permalink
Only cast floating window shadows if not contained by a previous floa…
Browse files Browse the repository at this point in the history
…ting window
  • Loading branch information
Kethku committed Nov 8, 2023
1 parent 3cc98d5 commit 6419eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ impl Renderer {
};

let settings = SETTINGS.get::<RendererSettings>();
let mut floating_rects = Vec::new();

self.window_regions = windows
.into_iter()
Expand All @@ -191,6 +192,7 @@ impl Renderer {
&settings,
default_background.with_a((255.0 * transparency) as u8),
font_dimensions,
&mut floating_rects,
)
})
.collect();
Expand Down
13 changes: 10 additions & 3 deletions src/renderer/rendered_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use skia_safe::{
image_filters::blur,
scalar,
utils::shadow_utils::{draw_shadow, ShadowFlags},
BlendMode, Canvas, ClipOp, Color, Matrix, Paint, Path, Picture, PictureRecorder, Point, Point3,
Rect,
BlendMode, Canvas, ClipOp, Color, Contains, Matrix, Paint, Path, Picture, PictureRecorder,
Point, Point3, Rect,
};

use crate::{
Expand Down Expand Up @@ -279,13 +279,19 @@ impl RenderedWindow {
settings: &RendererSettings,
default_background: Color,
font_dimensions: Dimensions,
previous_floating_rects: &mut Vec<Rect>,
) -> WindowDrawDetails {
let has_transparency = default_background.a() != 255 || self.has_transparency();

let pixel_region = self.pixel_region(font_dimensions);
let transparent_floating = self.anchor_info.is_some() && has_transparency;

if self.anchor_info.is_some() && settings.floating_shadow {
if self.anchor_info.is_some()
&& settings.floating_shadow
&& !previous_floating_rects
.iter()
.any(|rect| rect.contains(pixel_region))
{
root_canvas.save();
let shadow_path = Path::rect(pixel_region, None);
// We clip using the Difference op to make sure that the shadow isn't rendered inside
Expand Down Expand Up @@ -313,6 +319,7 @@ impl RenderedWindow {
Some(ShadowFlags::DIRECTIONAL_LIGHT),
);
root_canvas.restore();
previous_floating_rects.push(pixel_region.clone());
}

root_canvas.save();
Expand Down

0 comments on commit 6419eb4

Please sign in to comment.