From 2979eb9da96c2b5940e94af863dd8fa966518aeb Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 18 Dec 2023 18:32:03 -0800 Subject: [PATCH] Allow transparent divs to be considered "top layers" This changes the meaning of `was_top_layer` so that it is checking that nothing opaque is on top of the given layer. The layer in question need not be opaque. --- crates/gpui2/src/window.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 0cef164460..ccfdb6a273 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -942,16 +942,20 @@ impl<'a> WindowContext<'a> { } } - /// Returns true if the top-most opaque layer painted over this point was part of the - /// same layer as the given stacking order. + /// Returns true if there is no opaque layer containing the given point + /// on top of the given level. Layers whose level is an extension of the + /// level are not considered to be on top of the level. pub fn was_top_layer(&self, point: &Point, level: &StackingOrder) -> bool { - for (stack, bounds) in self.window.rendered_frame.depth_map.iter() { - if bounds.contains(point) { - return level.starts_with(stack) || stack.starts_with(level); + for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() { + if level >= opaque_level { + break; + } + + if bounds.contains(point) && !opaque_level.starts_with(level) { + return false; } } - - false + true } pub fn was_top_layer_under_active_drag( @@ -959,16 +963,19 @@ impl<'a> WindowContext<'a> { point: &Point, level: &StackingOrder, ) -> bool { - for (stack, bounds) in self.window.rendered_frame.depth_map.iter() { - if stack.starts_with(&[ACTIVE_DRAG_Z_INDEX]) { + for (opaque_level, bounds) in self.window.rendered_frame.depth_map.iter() { + if level >= opaque_level { + break; + } + if opaque_level.starts_with(&[ACTIVE_DRAG_Z_INDEX]) { continue; } - if bounds.contains(point) { - return level.starts_with(stack) || stack.starts_with(level); + + if bounds.contains(point) && !opaque_level.starts_with(level) { + return false; } } - - false + true } /// Called during painting to get the current stacking order.