utils: New geometry spaces local/global

This commit is contained in:
Victoria Brekenfeld 2023-10-25 19:24:51 +02:00
parent c38a236ffa
commit 42aaafe586
18 changed files with 516 additions and 300 deletions

View file

@ -47,7 +47,7 @@ use crate::{
},
shell::{CosmicMappedRenderElement, CosmicSurface, WorkspaceRenderElement},
state::{BackendData, ClientState, Common, State},
utils::prelude::OutputExt,
utils::prelude::{OutputExt, PointExt},
wayland::protocols::{
screencopy::{
delegate_screencopy, BufferInfo, BufferParams, CursorMode as ScreencopyCursorMode,
@ -106,7 +106,7 @@ impl ScreencopyHandler for State {
if let Some(pointer) = seat.get_pointer() {
if output
.geometry()
.contains(pointer.current_location().to_i32_round())
.contains(pointer.current_location().to_i32_round().as_global())
{
session.cursor_enter(seat, InputType::Pointer);
}

View file

@ -27,27 +27,28 @@ use std::sync::Mutex;
use tracing::{trace, warn};
impl Shell {
pub fn unconstrain_popup(&self, surface: &PopupSurface, positioner: &PositionerState) {
pub fn unconstrain_popup(&self, surface: &PopupSurface) {
if let Some(parent) = get_popup_toplevel(&surface) {
if let Some(elem) = self.element_for_wl_surface(&parent) {
let workspace = self.space_for(elem).unwrap();
let mut element_geo = workspace.element_geometry(elem).unwrap();
let mut element_geo = workspace
.element_geometry(elem)
.unwrap()
.to_global(workspace.output());
let (window, offset) = elem
.windows()
.find(|(w, _)| w.wl_surface().as_ref() == Some(&parent))
.unwrap();
let window_geo_offset = window.geometry().loc;
let window_loc = element_geo.loc + offset + window_geo_offset;
let anchor_point = get_anchor_point(&positioner) + window_loc;
let window_loc: Point<i32, Global> =
element_geo.loc + offset.as_global() + window_geo_offset.as_global();
if workspace.is_tiled(elem) {
element_geo.loc = (0, 0).into(); //-= window_loc;
if !unconstrain_xdg_popup_tile(surface, element_geo) {
if let Some(output) = workspace.output_under(anchor_point) {
unconstrain_xdg_popup(surface, window_loc, output.geometry());
}
element_geo.loc = (0, 0).into();
if !unconstrain_xdg_popup_tile(surface, element_geo.as_logical()) {
unconstrain_xdg_popup(surface, window_loc, workspace.output().geometry());
}
} else if let Some(output) = workspace.output_under(anchor_point) {
unconstrain_xdg_popup(surface, window_loc, output.geometry());
} else {
unconstrain_xdg_popup(surface, window_loc, workspace.output().geometry());
}
} else if let Some((output, layer_surface)) = self.outputs().find_map(|o| {
let map = layer_map_for_output(o);
@ -62,7 +63,7 @@ impl Shell {
pub fn update_reactive_popups<'a>(
window: &Window,
loc: Point<i32, Logical>,
loc: Point<i32, Global>,
outputs: impl Iterator<Item = &'a Output>,
) {
let output_geo = outputs.map(|o| o.geometry()).collect::<Vec<_>>();
@ -79,7 +80,7 @@ pub fn update_reactive_popups<'a>(
attributes.current.positioner.clone()
});
if positioner.reactive {
let anchor_point = get_anchor_point(&positioner) + loc;
let anchor_point = loc + get_anchor_point(&positioner).as_global();
if let Some(rect) = output_geo
.iter()
.find(|geo| geo.contains(anchor_point))
@ -116,11 +117,11 @@ fn unconstrain_xdg_popup_tile(surface: &PopupSurface, rect: Rectangle<i32, Logic
fn unconstrain_xdg_popup(
surface: &PopupSurface,
window_loc: Point<i32, Logical>,
rect: Rectangle<i32, Logical>,
window_loc: Point<i32, Global>,
mut rect: Rectangle<i32, Global>,
) {
let mut relative = rect;
relative.loc -= window_loc;
rect.loc -= window_loc;
let relative = rect.as_logical();
let geometry = surface.with_pending_state(|state| state.positioner.get_geometry());
let offset = check_constrained(geometry, relative);
@ -139,7 +140,7 @@ fn unconstrain_layer_popup(surface: &PopupSurface, output: &Output, layer_surfac
let layer_geo = map.layer_geometry(layer_surface).unwrap();
// the output_rect represented relative to the parents coordinate system
let mut relative = Rectangle::from_loc_and_size((0, 0), output.geometry().size);
let mut relative = Rectangle::from_loc_and_size((0, 0), output.geometry().size).as_logical();
relative.loc -= layer_geo.loc;
let geometry = surface.with_pending_state(|state| state.positioner.get_geometry());
let offset = check_constrained(geometry, relative);