Allow input-method popups to overflow the window
Browse files at this commit39dc21971327abe1d488a31173f81620430bb25bParent: 2c82b774 changed files +62 -25
- src/handlers/xdg_shell.rs +6 -3
- src/layout/mod.rs +26 -11
- src/layout/scrolling.rs +24 -9
- src/layout/workspace.rs +6 -2
src/handlers/xdg_shell.rsmodified+6 -3
| @@ -1304,12 +1304,15 @@ impl State { | |||
| 1304 | } | 1304 | } |
| 1305 | 1305 | ||
| 1306 | fn unconstrain_window_popup(&self, popup: &PopupKind, window: &Window) { | 1306 | fn unconstrain_window_popup(&self, popup: &PopupKind, window: &Window) { |
| 1307 | + let ime = matches!(popup, PopupKind::InputMethod(_)); | ||
| 1308 | + | ||
| 1307 | // The target geometry for the positioner should be relative to its parent's geometry, so | 1309 | // The target geometry for the positioner should be relative to its parent's geometry, so |
| 1308 | // we will compute that here. | 1310 | // we will compute that here. |
| 1309 | - let mut target = self.niri.layout.popup_target_rect(window); | 1311 | + let mut target = self.niri.layout.popup_target_rect(window, ime); |
| 1310 | target.loc -= get_popup_toplevel_coords(popup).to_f64(); | 1312 | target.loc -= get_popup_toplevel_coords(popup).to_f64(); |
| 1311 | 1313 | ||
| 1312 | - self.position_popup_within_rect(popup, target, true); | 1314 | + // Don't add padding for IME popups; better to give them more space. |
| 1315 | + self.position_popup_within_rect(popup, target, !ime); | ||
| 1313 | } | 1316 | } |
| 1314 | 1317 | ||
| 1315 | pub fn unconstrain_layer_shell_popup( | 1318 | pub fn unconstrain_layer_shell_popup( |
| @@ -1377,7 +1380,7 @@ impl State { | |||
| 1377 | bbox.loc.x -= overflow_x; | 1380 | bbox.loc.x -= overflow_x; |
| 1378 | } | 1381 | } |
| 1379 | 1382 | ||
| 1380 | - // Ensure that the popup starts within the window. | 1383 | + // Ensure that the popup starts within the target rect. |
| 1381 | bbox.loc.x = f64::max(bbox.loc.x, target.loc.x); | 1384 | bbox.loc.x = f64::max(bbox.loc.x, target.loc.x); |
| 1382 | 1385 | ||
| 1383 | // Try to position IME popup below the text input rectangle. | 1386 | // Try to position IME popup below the text input rectangle. |
src/layout/mod.rsmodified+26 -11
| @@ -1465,24 +1465,39 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1465 | /// Computes the window-geometry-relative target rect for popup unconstraining. | 1465 | /// Computes the window-geometry-relative target rect for popup unconstraining. |
| 1466 | /// | 1466 | /// |
| 1467 | /// We will try to fit popups inside this rect. | 1467 | /// We will try to fit popups inside this rect. |
| 1468 | - pub fn popup_target_rect(&self, window: &W::Id) -> Rectangle<f64, Logical> { | 1468 | + /// |
| 1469 | + /// If `overflow` is true, prefer to return the working area region even for the scrolling | ||
| 1470 | + /// layout where popups are normally kept constrained to the column width. This is used for | ||
| 1471 | + /// IME popups where this is a more expected behavior. | ||
| 1472 | + pub fn popup_target_rect(&self, window: &W::Id, overflow: bool) -> Rectangle<f64, Logical> { | ||
| 1469 | if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { | 1473 | if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { |
| 1470 | if move_.tile.window().id() == window { | 1474 | if move_.tile.window().id() == window { |
| 1471 | - // Follow the scrolling layout logic and fit the popup horizontally within the | 1475 | + // Follow the scrolling layout logic. |
| 1472 | - // window geometry. | 1476 | + let output_size = output_size(&move_.output); |
| 1473 | - let width = move_.tile.window_size().w; | 1477 | + let tile_pos = move_.tile_render_location(1.); |
| 1474 | - let height = output_size(&move_.output).h; | 1478 | + |
| 1475 | - let mut target = Rectangle::from_size(Size::from((width, height))); | 1479 | + let target = if overflow { |
| 1476 | - // FIXME: ideally this shouldn't include the tile render offset, but the code | 1480 | + let mut target = Rectangle::from_size(output_size); |
| 1477 | - // duplication would be a bit annoying for this edge case. | 1481 | + target.loc -= tile_pos; |
| 1478 | - target.loc.y -= move_.tile_render_location(1.).y; | 1482 | + target.loc -= move_.tile.window_loc(); |
| 1479 | - target.loc.y -= move_.tile.window_loc().y; | 1483 | + target |
| 1484 | + } else { | ||
| 1485 | + let width = move_.tile.window_size().w; | ||
| 1486 | + let height = output_size.h; | ||
| 1487 | + let mut target = Rectangle::from_size(Size::from((width, height))); | ||
| 1488 | + // FIXME: ideally this shouldn't include the tile render offset, but the code | ||
| 1489 | + // duplication would be a bit annoying for this edge case. | ||
| 1490 | + target.loc.y -= tile_pos.y; | ||
| 1491 | + target.loc.y -= move_.tile.window_loc().y; | ||
| 1492 | + target | ||
| 1493 | + }; | ||
| 1494 | + | ||
| 1480 | return target; | 1495 | return target; |
| 1481 | } | 1496 | } |
| 1482 | } | 1497 | } |
| 1483 | 1498 | ||
| 1484 | self.workspaces() | 1499 | self.workspaces() |
| 1485 | - .find_map(|(_, _, ws)| ws.popup_target_rect(window)) | 1500 | + .find_map(|(_, _, ws)| ws.popup_target_rect(window, overflow)) |
| 1486 | .unwrap() | 1501 | .unwrap() |
| 1487 | } | 1502 | } |
| 1488 | 1503 | ||
src/layout/scrolling.rsmodified+24 -9
| @@ -2604,21 +2604,36 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2604 | view.intersection(window_rect) | 2604 | view.intersection(window_rect) |
| 2605 | } | 2605 | } |
| 2606 | 2606 | ||
| 2607 | - pub fn popup_target_rect(&self, id: &W::Id) -> Option<Rectangle<f64, Logical>> { | 2607 | + pub fn popup_target_rect(&self, id: &W::Id, overflow: bool) -> Option<Rectangle<f64, Logical>> { |
| 2608 | - for col in &self.columns { | 2608 | + let view_pos = self.target_view_pos(); |
| 2609 | + let col_xs = self.column_xs(self.data.iter().copied()); | ||
| 2610 | + for (col, col_x) in zip(&self.columns, col_xs) { | ||
| 2609 | for (tile, pos) in col.tiles() { | 2611 | for (tile, pos) in col.tiles() { |
| 2610 | if tile.window().id() == id { | 2612 | if tile.window().id() == id { |
| 2611 | // In the scrolling layout, we try to position popups horizontally within the | 2613 | // In the scrolling layout, we try to position popups horizontally within the |
| 2612 | // window geometry (so they remain visible even if the window scrolls flush with | 2614 | // window geometry (so they remain visible even if the window scrolls flush with |
| 2613 | // the left/right edge of the screen), and vertically within the whole parent | 2615 | // the left/right edge of the screen), and vertically within the whole parent |
| 2614 | // working area. | 2616 | // working area. |
| 2615 | - let width = tile.window_size().w; | 2617 | + let target = if overflow { |
| 2616 | - let height = self.parent_area.size.h; | 2618 | + // For IME popups, this is a bit of an unexpected behavior though; people |
| 2617 | - | 2619 | + // are used to them extending to the right. Also, IME popups disappear when |
| 2618 | - let mut target = Rectangle::from_size(Size::from((width, height))); | 2620 | + // keyboard focus changes, so changing scroll position is not a problem. So, |
| 2619 | - target.loc.y += self.parent_area.loc.y; | 2621 | + // constrain them to the parent area instead. |
| 2620 | - target.loc.y -= pos.y; | 2622 | + let mut target = self.parent_area; |
| 2621 | - target.loc.y -= tile.window_loc().y; | 2623 | + target.loc.x -= col_x - view_pos; |
| 2624 | + target.loc -= pos; | ||
| 2625 | + target.loc -= tile.window_loc(); | ||
| 2626 | + target | ||
| 2627 | + } else { | ||
| 2628 | + let width = tile.window_size().w; | ||
| 2629 | + let height = self.parent_area.size.h; | ||
| 2630 | + | ||
| 2631 | + let mut target = Rectangle::from_size(Size::from((width, height))); | ||
| 2632 | + target.loc.y += self.parent_area.loc.y; | ||
| 2633 | + target.loc.y -= pos.y; | ||
| 2634 | + target.loc.y -= tile.window_loc().y; | ||
| 2635 | + target | ||
| 2636 | + }; | ||
| 2622 | 2637 | ||
| 2623 | return Some(target); | 2638 | return Some(target); |
| 2624 | } | 2639 | } |
src/layout/workspace.rsmodified+6 -2
| @@ -1647,11 +1647,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1647 | } | 1647 | } |
| 1648 | } | 1648 | } |
| 1649 | 1649 | ||
| 1650 | - pub fn popup_target_rect(&self, window: &W::Id) -> Option<Rectangle<f64, Logical>> { | 1650 | + pub fn popup_target_rect( |
| 1651 | + &self, | ||
| 1652 | + window: &W::Id, | ||
| 1653 | + overflow: bool, | ||
| 1654 | + ) -> Option<Rectangle<f64, Logical>> { | ||
| 1651 | if self.floating.has_window(window) { | 1655 | if self.floating.has_window(window) { |
| 1652 | self.floating.popup_target_rect(window) | 1656 | self.floating.popup_target_rect(window) |
| 1653 | } else { | 1657 | } else { |
| 1654 | - self.scrolling.popup_target_rect(window) | 1658 | + self.scrolling.popup_target_rect(window, overflow) |
| 1655 | } | 1659 | } |
| 1656 | } | 1660 | } |
| 1657 | 1661 | ||