refactor: unify popup positioning logic for tiled layout into

position_popup_within_rect()
This commit is contained in:
KENZ 2026-05-05 12:08:55 +09:00 committed by Jacob Kauffmann
parent 1a57c104f6
commit f62c88a3d9

View file

@ -128,17 +128,7 @@ pub fn update_reactive_popups<'a>(
// Attempt to constraint to tile, without resize. Return `true` if it fits. // Attempt to constraint to tile, without resize. Return `true` if it fits.
fn unconstrain_xdg_popup_tile(surface: &PopupSurface, mut rect: Rectangle<i32, Logical>) -> bool { fn unconstrain_xdg_popup_tile(surface: &PopupSurface, mut rect: Rectangle<i32, Logical>) -> bool {
rect.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone())); rect.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone()));
let geometry = surface.with_pending_state(|state| { position_popup_within_rect(surface, rect.as_global(), true)
let mut positioner_no_resize = state.positioner;
positioner_no_resize
.constraint_adjustment
.remove(ConstraintAdjustment::ResizeX | ConstraintAdjustment::ResizeY);
positioner_no_resize.get_unconstrained_geometry(rect)
});
surface.with_pending_state(|state| {
state.geometry = geometry;
});
rect.contains_rect(geometry)
} }
fn unconstrain_xdg_popup( fn unconstrain_xdg_popup(
@ -148,7 +138,7 @@ fn unconstrain_xdg_popup(
) { ) {
rect.loc -= window_loc; rect.loc -= window_loc;
rect.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone())).as_global(); rect.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone())).as_global();
position_popup_within_rect(surface, rect); position_popup_within_rect(surface, rect, false);
} }
fn unconstrain_layer_popup(surface: &PopupSurface, output: &Output, layer_surface: &LayerSurface) { fn unconstrain_layer_popup(surface: &PopupSurface, output: &Output, layer_surface: &LayerSurface) {
@ -159,18 +149,31 @@ fn unconstrain_layer_popup(surface: &PopupSurface, output: &Output, layer_surfac
let mut relative = Rectangle::from_size(output.geometry().size).as_logical(); let mut relative = Rectangle::from_size(output.geometry().size).as_logical();
relative.loc -= layer_geo.loc; relative.loc -= layer_geo.loc;
relative.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone())); relative.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(surface.clone()));
position_popup_within_rect(surface, relative.as_global()); position_popup_within_rect(surface, relative.as_global(), false);
} }
fn position_popup_within_rect(surface: &PopupSurface, rect: Rectangle<i32, Global>) { fn position_popup_within_rect(
surface: &PopupSurface,
rect: Rectangle<i32, Global>,
is_tiled: bool,
) -> bool {
let rect = rect.as_logical();
let geometry = surface.with_pending_state(|state| { let geometry = surface.with_pending_state(|state| {
state let positioner = if is_tiled {
.positioner let mut positioner_no_resize = state.positioner;
.get_unconstrained_geometry(rect.as_logical()) positioner_no_resize
.constraint_adjustment
.remove(ConstraintAdjustment::ResizeX | ConstraintAdjustment::ResizeY);
positioner_no_resize
} else {
state.positioner
};
positioner.get_unconstrained_geometry(rect)
}); });
surface.with_pending_state(|state| { surface.with_pending_state(|state| {
state.geometry = geometry; state.geometry = geometry;
}); });
rect.contains_rect(geometry)
} }
pub fn get_popup_toplevel(popup: &PopupKind) -> Option<WlSurface> { pub fn get_popup_toplevel(popup: &PopupKind) -> Option<WlSurface> {