desktop: fix popup placement
This commit is contained in:
parent
171456c7ba
commit
5b6700c151
|
@ -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<i32, Logical> {
|
||||
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::<SurfaceCachedState>()
|
||||
.geometry
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn location(&self) -> Point<i32, Logical> {
|
||||
let wl_surface = match self.get_surface() {
|
||||
Some(s) => s,
|
||||
|
|
|
@ -49,7 +49,7 @@ impl SurfaceState {
|
|||
.input_region
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(point.to_i32_floor())
|
||||
.contains(point.to_i32_round())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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::<Vec<_>>();
|
||||
draw_surface_tree(
|
||||
renderer,
|
||||
frame,
|
||||
surface,
|
||||
scale,
|
||||
location + p_location,
|
||||
&damage,
|
||||
log,
|
||||
)?;
|
||||
draw_surface_tree(renderer, frame, surface, scale, location + offset, &damage, log)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue