diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index d21f60be..6477d65a 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -19,7 +19,7 @@ use smithay::reexports::wayland_server::protocol::wl_output; use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::{self, Resource, WEnum}; -use smithay::utils::{Logical, Rectangle, Serial}; +use smithay::utils::{Logical, Point, Rectangle, Serial}; use smithay::wayland::compositor::{ add_blocker, add_pre_commit_hook, with_states, BufferAssignment, CompositorHandler as _, HookId, SurfaceAttributes, @@ -1311,8 +1311,10 @@ impl State { let mut target = self.niri.layout.popup_target_rect(window, ime); target.loc -= get_popup_toplevel_coords(popup).to_f64(); + let geo_off = window.geometry().loc.to_f64(); + // Don't add padding for IME popups; better to give them more space. - self.position_popup_within_rect(popup, target, !ime); + self.position_popup_within_rect(popup, geo_off, target, !ime); } pub fn unconstrain_layer_shell_popup( @@ -1346,13 +1348,17 @@ impl State { target.loc -= layer_geo.loc; target.loc -= get_popup_toplevel_coords(popup); + // Layer surfaces don't have geometry. + let geo_off = Point::new(0., 0.); + // Don't add padding to layer-shell popups. It's not really needed, and it's unexpected. - self.position_popup_within_rect(popup, target.to_f64(), false); + self.position_popup_within_rect(popup, geo_off, target.to_f64(), false); } fn position_popup_within_rect( &self, popup: &PopupKind, + geo_off: Point, target: Rectangle, padding: bool, ) { @@ -1369,6 +1375,11 @@ impl State { }); } PopupKind::InputMethod(popup) => { + // IME popups are positioned in surface-local coordinates, but target is in + // geometry-relative coordinates. + let mut target = target; + target.loc += geo_off; + let text_input_rectangle = popup.text_input_rectangle(); let mut bbox = utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc)