diff --git a/src/desktop/popup.rs b/src/desktop/popup.rs index a6e2de6..58aa164 100644 --- a/src/desktop/popup.rs +++ b/src/desktop/popup.rs @@ -1,8 +1,8 @@ use crate::{ - utils::{DeadResource, Logical, Point}, + utils::{DeadResource, Logical, Point, Rectangle}, wayland::{ compositor::{get_role, with_states}, - shell::xdg::{PopupSurface, XdgPopupSurfaceRoleAttributes, XDG_POPUP_ROLE}, + shell::xdg::{PopupSurface, SurfaceCachedState, XdgPopupSurfaceRoleAttributes, XDG_POPUP_ROLE}, }, }; use std::sync::{Arc, Mutex}; @@ -235,6 +235,22 @@ impl PopupKind { } } + pub fn geometry(&self) -> Rectangle { + let wl_surface = match self.get_surface() { + Some(s) => s, + None => return Rectangle::from_loc_and_size((0, 0), (0, 0)), + }; + + with_states(wl_surface, |states| { + states + .cached_state + .current::() + .geometry + .unwrap_or_default() + }) + .unwrap() + } + fn location(&self) -> Point { let wl_surface = match self.get_surface() { Some(s) => s, diff --git a/src/desktop/utils.rs b/src/desktop/utils.rs index eb2cbf7..b0d847e 100644 --- a/src/desktop/utils.rs +++ b/src/desktop/utils.rs @@ -49,7 +49,7 @@ impl SurfaceState { .input_region .as_ref() .unwrap() - .contains(point.to_i32_floor()) + .contains(point.to_i32_round()) } } diff --git a/src/desktop/window.rs b/src/desktop/window.rs index 1ebd138..42c6954 100644 --- a/src/desktop/window.rs +++ b/src/desktop/window.rs @@ -171,7 +171,8 @@ impl Window { .flatten() { if let Some(surface) = popup.get_surface() { - bounding_box = bounding_box.merge(bbox_from_surface_tree(surface, location)); + let offset = self.geometry().loc + location - popup.geometry().loc; + bounding_box = bounding_box.merge(bbox_from_surface_tree(surface, offset)); } } } @@ -245,9 +246,10 @@ impl Window { .into_iter() .flatten() { + let offset = self.geometry().loc + location - popup.geometry().loc; if let Some(result) = popup .get_surface() - .and_then(|surface| under_from_surface_tree(surface, point, location)) + .and_then(|surface| under_from_surface_tree(surface, point, offset)) { return Some(result); } @@ -274,8 +276,9 @@ impl Window { .flatten() { if let Some(surface) = popup.get_surface() { - let bbox = bbox_from_surface_tree(surface, location); - let popup_damage = damage_from_surface_tree(surface, location, for_values); + let offset = self.geometry().loc + location - popup.geometry().loc; + let bbox = bbox_from_surface_tree(surface, offset); + let popup_damage = damage_from_surface_tree(surface, offset, for_values); damage.extend(popup_damage.into_iter().flat_map(|rect| rect.intersection(bbox))); } } @@ -317,23 +320,16 @@ where .flatten() { if let Some(surface) = popup.get_surface() { + let offset = window.geometry().loc + p_location - popup.geometry().loc; let damage = damage .iter() .cloned() .map(|mut geo| { - geo.loc -= p_location; + geo.loc -= offset; geo }) .collect::>(); - draw_surface_tree( - renderer, - frame, - surface, - scale, - location + p_location, - &damage, - log, - )?; + draw_surface_tree(renderer, frame, surface, scale, location + offset, &damage, log)?; } } }