diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index a266b6ca..d21f60be 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -1304,12 +1304,15 @@ impl State { } fn unconstrain_window_popup(&self, popup: &PopupKind, window: &Window) { + let ime = matches!(popup, PopupKind::InputMethod(_)); + // The target geometry for the positioner should be relative to its parent's geometry, so // we will compute that here. - let mut target = self.niri.layout.popup_target_rect(window); + let mut target = self.niri.layout.popup_target_rect(window, ime); target.loc -= get_popup_toplevel_coords(popup).to_f64(); - self.position_popup_within_rect(popup, target, true); + // Don't add padding for IME popups; better to give them more space. + self.position_popup_within_rect(popup, target, !ime); } pub fn unconstrain_layer_shell_popup( @@ -1377,7 +1380,7 @@ impl State { bbox.loc.x -= overflow_x; } - // Ensure that the popup starts within the window. + // Ensure that the popup starts within the target rect. bbox.loc.x = f64::max(bbox.loc.x, target.loc.x); // Try to position IME popup below the text input rectangle. diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 97f917a9..8575a1af 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1465,24 +1465,39 @@ impl Layout { /// Computes the window-geometry-relative target rect for popup unconstraining. /// /// We will try to fit popups inside this rect. - pub fn popup_target_rect(&self, window: &W::Id) -> Rectangle { + /// + /// If `overflow` is true, prefer to return the working area region even for the scrolling + /// layout where popups are normally kept constrained to the column width. This is used for + /// IME popups where this is a more expected behavior. + pub fn popup_target_rect(&self, window: &W::Id, overflow: bool) -> Rectangle { if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { if move_.tile.window().id() == window { - // Follow the scrolling layout logic and fit the popup horizontally within the - // window geometry. - let width = move_.tile.window_size().w; - let height = output_size(&move_.output).h; - let mut target = Rectangle::from_size(Size::from((width, height))); - // FIXME: ideally this shouldn't include the tile render offset, but the code - // duplication would be a bit annoying for this edge case. - target.loc.y -= move_.tile_render_location(1.).y; - target.loc.y -= move_.tile.window_loc().y; + // Follow the scrolling layout logic. + let output_size = output_size(&move_.output); + let tile_pos = move_.tile_render_location(1.); + + let target = if overflow { + let mut target = Rectangle::from_size(output_size); + target.loc -= tile_pos; + target.loc -= move_.tile.window_loc(); + target + } else { + let width = move_.tile.window_size().w; + let height = output_size.h; + let mut target = Rectangle::from_size(Size::from((width, height))); + // FIXME: ideally this shouldn't include the tile render offset, but the code + // duplication would be a bit annoying for this edge case. + target.loc.y -= tile_pos.y; + target.loc.y -= move_.tile.window_loc().y; + target + }; + return target; } } self.workspaces() - .find_map(|(_, _, ws)| ws.popup_target_rect(window)) + .find_map(|(_, _, ws)| ws.popup_target_rect(window, overflow)) .unwrap() } diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index c7d94c54..ed85342e 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -2604,21 +2604,36 @@ impl ScrollingSpace { view.intersection(window_rect) } - pub fn popup_target_rect(&self, id: &W::Id) -> Option> { - for col in &self.columns { + pub fn popup_target_rect(&self, id: &W::Id, overflow: bool) -> Option> { + let view_pos = self.target_view_pos(); + let col_xs = self.column_xs(self.data.iter().copied()); + for (col, col_x) in zip(&self.columns, col_xs) { for (tile, pos) in col.tiles() { if tile.window().id() == id { // In the scrolling layout, we try to position popups horizontally within the // window geometry (so they remain visible even if the window scrolls flush with // the left/right edge of the screen), and vertically within the whole parent // working area. - let width = tile.window_size().w; - let height = self.parent_area.size.h; - - let mut target = Rectangle::from_size(Size::from((width, height))); - target.loc.y += self.parent_area.loc.y; - target.loc.y -= pos.y; - target.loc.y -= tile.window_loc().y; + let target = if overflow { + // For IME popups, this is a bit of an unexpected behavior though; people + // are used to them extending to the right. Also, IME popups disappear when + // keyboard focus changes, so changing scroll position is not a problem. So, + // constrain them to the parent area instead. + let mut target = self.parent_area; + target.loc.x -= col_x - view_pos; + target.loc -= pos; + target.loc -= tile.window_loc(); + target + } else { + let width = tile.window_size().w; + let height = self.parent_area.size.h; + + let mut target = Rectangle::from_size(Size::from((width, height))); + target.loc.y += self.parent_area.loc.y; + target.loc.y -= pos.y; + target.loc.y -= tile.window_loc().y; + target + }; return Some(target); } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 8851a92f..4da404de 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -1647,11 +1647,15 @@ impl Workspace { } } - pub fn popup_target_rect(&self, window: &W::Id) -> Option> { + pub fn popup_target_rect( + &self, + window: &W::Id, + overflow: bool, + ) -> Option> { if self.floating.has_window(window) { self.floating.popup_target_rect(window) } else { - self.scrolling.popup_target_rect(window) + self.scrolling.popup_target_rect(window, overflow) } }