forge
Explore
Log in

Don't you dare go Hollow

Take window geometry into account for IME unconstraining

Browse files at this commit

d0cd58ec5ac6b2d41d42478fb4f3cc7c0c687db9Ivan MolodetskikhParent: 39dc219
Unlike regular popups, IMEs use surface-local coordinates, so we need to
adjust the target rect accordingly.

Seems to be working correctly now with fcitx5 and combinations of:
- toplevel with geometry
- with a subsurface at an offset
- with a popup with its own geometry
- all of this but on a layer surface
src/handlers/xdg_shell.rsmodified+14 -3
@@ -19,7 +19,7 @@ use smithay::reexports::wayland_server::protocol::wl_output;
1919 use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
2020 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
2121 use smithay::reexports::wayland_server::{self, Resource, WEnum};
22-use smithay::utils::{Logical, Rectangle, Serial};
22+use smithay::utils::{Logical, Point, Rectangle, Serial};
2323 use smithay::wayland::compositor::{
2424 add_blocker, add_pre_commit_hook, with_states, BufferAssignment, CompositorHandler as _,
2525 HookId, SurfaceAttributes,
@@ -1311,8 +1311,10 @@ impl State {
13111311 let mut target = self.niri.layout.popup_target_rect(window, ime);
13121312 target.loc -= get_popup_toplevel_coords(popup).to_f64();
13131313
1314+ let geo_off = window.geometry().loc.to_f64();
1315+
13141316 // Don't add padding for IME popups; better to give them more space.
1315- self.position_popup_within_rect(popup, target, !ime);
1317+ self.position_popup_within_rect(popup, geo_off, target, !ime);
13161318 }
13171319
13181320 pub fn unconstrain_layer_shell_popup(
@@ -1346,13 +1348,17 @@ impl State {
13461348 target.loc -= layer_geo.loc;
13471349 target.loc -= get_popup_toplevel_coords(popup);
13481350
1351+ // Layer surfaces don't have geometry.
1352+ let geo_off = Point::new(0., 0.);
1353+
13491354 // Don't add padding to layer-shell popups. It's not really needed, and it's unexpected.
1350- self.position_popup_within_rect(popup, target.to_f64(), false);
1355+ self.position_popup_within_rect(popup, geo_off, target.to_f64(), false);
13511356 }
13521357
13531358 fn position_popup_within_rect(
13541359 &self,
13551360 popup: &PopupKind,
1361+ geo_off: Point<f64, Logical>,
13561362 target: Rectangle<f64, Logical>,
13571363 padding: bool,
13581364 ) {
@@ -1369,6 +1375,11 @@ impl State {
13691375 });
13701376 }
13711377 PopupKind::InputMethod(popup) => {
1378+ // IME popups are positioned in surface-local coordinates, but target is in
1379+ // geometry-relative coordinates.
1380+ let mut target = target;
1381+ target.loc += geo_off;
1382+
13721383 let text_input_rectangle = popup.text_input_rectangle();
13731384 let mut bbox =
13741385 utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc)