desktop: fix popup placement
This commit is contained in:
parent
171456c7ba
commit
5b6700c151
|
@ -1,8 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
utils::{DeadResource, Logical, Point},
|
utils::{DeadResource, Logical, Point, Rectangle},
|
||||||
wayland::{
|
wayland::{
|
||||||
compositor::{get_role, with_states},
|
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};
|
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> {
|
fn location(&self) -> Point<i32, Logical> {
|
||||||
let wl_surface = match self.get_surface() {
|
let wl_surface = match self.get_surface() {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl SurfaceState {
|
||||||
.input_region
|
.input_region
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(point.to_i32_floor())
|
.contains(point.to_i32_round())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,8 @@ impl Window {
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if let Some(surface) = popup.get_surface() {
|
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()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
|
let offset = self.geometry().loc + location - popup.geometry().loc;
|
||||||
if let Some(result) = popup
|
if let Some(result) = popup
|
||||||
.get_surface()
|
.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);
|
return Some(result);
|
||||||
}
|
}
|
||||||
|
@ -274,8 +276,9 @@ impl Window {
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if let Some(surface) = popup.get_surface() {
|
if let Some(surface) = popup.get_surface() {
|
||||||
let bbox = bbox_from_surface_tree(surface, location);
|
let offset = self.geometry().loc + location - popup.geometry().loc;
|
||||||
let popup_damage = damage_from_surface_tree(surface, location, for_values);
|
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)));
|
damage.extend(popup_damage.into_iter().flat_map(|rect| rect.intersection(bbox)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,23 +320,16 @@ where
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if let Some(surface) = popup.get_surface() {
|
if let Some(surface) = popup.get_surface() {
|
||||||
|
let offset = window.geometry().loc + p_location - popup.geometry().loc;
|
||||||
let damage = damage
|
let damage = damage
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|mut geo| {
|
.map(|mut geo| {
|
||||||
geo.loc -= p_location;
|
geo.loc -= offset;
|
||||||
geo
|
geo
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
draw_surface_tree(
|
draw_surface_tree(renderer, frame, surface, scale, location + offset, &damage, log)?;
|
||||||
renderer,
|
|
||||||
frame,
|
|
||||||
surface,
|
|
||||||
scale,
|
|
||||||
location + p_location,
|
|
||||||
&damage,
|
|
||||||
log,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue