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;
19 use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;19 use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
20 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;20 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
21 use smithay::reexports::wayland_server::{self, Resource, WEnum};21 use smithay::reexports::wayland_server::{self, Resource, WEnum};
22-use smithay::utils::{Logical, Rectangle, Serial};22+use smithay::utils::{Logical, Point, Rectangle, Serial};
23 use smithay::wayland::compositor::{23 use smithay::wayland::compositor::{
24 add_blocker, add_pre_commit_hook, with_states, BufferAssignment, CompositorHandler as _,24 add_blocker, add_pre_commit_hook, with_states, BufferAssignment, CompositorHandler as _,
25 HookId, SurfaceAttributes,25 HookId, SurfaceAttributes,
@@ -1311,8 +1311,10 @@ impl State {
1311 let mut target = self.niri.layout.popup_target_rect(window, ime);1311 let mut target = self.niri.layout.popup_target_rect(window, ime);
1312 target.loc -= get_popup_toplevel_coords(popup).to_f64();1312 target.loc -= get_popup_toplevel_coords(popup).to_f64();
1313 1313
1314+ let geo_off = window.geometry().loc.to_f64();
1315+
1314 // Don't add padding for IME popups; better to give them more space.1316 // 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);
1316 }1318 }
1317 1319
1318 pub fn unconstrain_layer_shell_popup(1320 pub fn unconstrain_layer_shell_popup(
@@ -1346,13 +1348,17 @@ impl State {
1346 target.loc -= layer_geo.loc;1348 target.loc -= layer_geo.loc;
1347 target.loc -= get_popup_toplevel_coords(popup);1349 target.loc -= get_popup_toplevel_coords(popup);
1348 1350
1351+ // Layer surfaces don't have geometry.
1352+ let geo_off = Point::new(0., 0.);
1353+
1349 // Don't add padding to layer-shell popups. It's not really needed, and it's unexpected.1354 // 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);
1351 }1356 }
1352 1357
1353 fn position_popup_within_rect(1358 fn position_popup_within_rect(
1354 &self,1359 &self,
1355 popup: &PopupKind,1360 popup: &PopupKind,
1361+ geo_off: Point<f64, Logical>,
1356 target: Rectangle<f64, Logical>,1362 target: Rectangle<f64, Logical>,
1357 padding: bool,1363 padding: bool,
1358 ) {1364 ) {
@@ -1369,6 +1375,11 @@ impl State {
1369 });1375 });
1370 }1376 }
1371 PopupKind::InputMethod(popup) => {1377 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+
1372 let text_input_rectangle = popup.text_input_rectangle();1383 let text_input_rectangle = popup.text_input_rectangle();
1373 let mut bbox =1384 let mut bbox =
1374 utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc)1385 utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc)