Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stacked floating window shadows #2114

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}

root_canvas.save();
Expand Down