Unconstrain InputMethod's PopupSurface
Browse files at this commit279659ac90eef4082157f427f006c9a4c5a02ac2Parent: c2d03d84 changed files +87 -30
- Cargo.lock +31 -11
- src/handlers/mod.rs +11 -2
- src/handlers/xdg_shell.rs +44 -16
- src/niri.rs +1 -1
Cargo.lockmodified+31 -11
| @@ -889,13 +889,13 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" | ||
| 889 | 889 | |
| 890 | 890 | [[package]] |
| 891 | 891 | name = "drm" |
| 892 | -version = "0.11.1" | |
| 892 | +version = "0.12.0" | |
| 893 | 893 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 894 | -checksum = "a0f8a69e60d75ae7dab4ef26a59ca99f2a89d4c142089b537775ae0c198bdcde" | |
| 894 | +checksum = "98888c4bbd601524c11a7ed63f814b8825f420514f78e96f752c437ae9cbb5d1" | |
| 895 | 895 | dependencies = [ |
| 896 | 896 | "bitflags 2.5.0", |
| 897 | 897 | "bytemuck", |
| 898 | - "drm-ffi", | |
| 898 | + "drm-ffi 0.8.0", | |
| 899 | 899 | "drm-fourcc", |
| 900 | 900 | "rustix 0.38.32", |
| 901 | 901 | ] |
| @@ -906,7 +906,17 @@ version = "0.7.1" | ||
| 906 | 906 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 907 | 907 | checksum = "41334f8405792483e32ad05fbb9c5680ff4e84491883d2947a4757dc54cb2ac6" |
| 908 | 908 | dependencies = [ |
| 909 | - "drm-sys", | |
| 909 | + "drm-sys 0.6.1", | |
| 910 | + "rustix 0.38.32", | |
| 911 | +] | |
| 912 | + | |
| 913 | +[[package]] | |
| 914 | +name = "drm-ffi" | |
| 915 | +version = "0.8.0" | |
| 916 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 917 | +checksum = "97c98727e48b7ccb4f4aea8cfe881e5b07f702d17b7875991881b41af7278d53" | |
| 918 | +dependencies = [ | |
| 919 | + "drm-sys 0.7.0", | |
| 910 | 920 | "rustix 0.38.32", |
| 911 | 921 | ] |
| 912 | 922 | |
| @@ -926,6 +936,16 @@ dependencies = [ | ||
| 926 | 936 | "linux-raw-sys 0.6.4", |
| 927 | 937 | ] |
| 928 | 938 | |
| 939 | +[[package]] | |
| 940 | +name = "drm-sys" | |
| 941 | +version = "0.7.0" | |
| 942 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 943 | +checksum = "fd39dde40b6e196c2e8763f23d119ddb1a8714534bf7d77fa97a65b0feda3986" | |
| 944 | +dependencies = [ | |
| 945 | + "libc", | |
| 946 | + "linux-raw-sys 0.6.4", | |
| 947 | +] | |
| 948 | + | |
| 929 | 949 | [[package]] |
| 930 | 950 | name = "edid-rs" |
| 931 | 951 | version = "0.1.0" |
| @@ -1239,11 +1259,11 @@ dependencies = [ | ||
| 1239 | 1259 | |
| 1240 | 1260 | [[package]] |
| 1241 | 1261 | name = "gbm" |
| 1242 | -version = "0.14.2" | |
| 1262 | +version = "0.15.0" | |
| 1243 | 1263 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1244 | -checksum = "313702b30cdeb83ddc72bc14dcee67803cd0ae2d12282ea06e368c25a900c844" | |
| 1264 | +checksum = "45bf55ba6dd53ad0ac115046ff999c5324c283444ee6e0be82454c4e8eb2f36a" | |
| 1245 | 1265 | dependencies = [ |
| 1246 | - "bitflags 1.3.2", | |
| 1266 | + "bitflags 2.5.0", | |
| 1247 | 1267 | "drm", |
| 1248 | 1268 | "drm-fourcc", |
| 1249 | 1269 | "gbm-sys", |
| @@ -2149,7 +2169,7 @@ dependencies = [ | ||
| 2149 | 2169 | "calloop 0.13.0", |
| 2150 | 2170 | "clap", |
| 2151 | 2171 | "directories", |
| 2152 | - "drm-ffi", | |
| 2172 | + "drm-ffi 0.7.1", | |
| 2153 | 2173 | "futures-util", |
| 2154 | 2174 | "git-version", |
| 2155 | 2175 | "glam", |
| @@ -3116,7 +3136,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" | ||
| 3116 | 3136 | [[package]] |
| 3117 | 3137 | name = "smithay" |
| 3118 | 3138 | version = "0.3.0" |
| 3119 | -source = "git+https://github.com/Smithay/smithay.git#c5e9a697e41f50dc56b918d9ef1e3d2e52c84ac0" | |
| 3139 | +source = "git+https://github.com/Smithay/smithay.git#40acc58b83400aa10fc62a51a235d1991ab46be5" | |
| 3120 | 3140 | dependencies = [ |
| 3121 | 3141 | "appendlist", |
| 3122 | 3142 | "bitflags 2.5.0", |
| @@ -3126,7 +3146,7 @@ dependencies = [ | ||
| 3126 | 3146 | "cursor-icon", |
| 3127 | 3147 | "downcast-rs", |
| 3128 | 3148 | "drm", |
| 3129 | - "drm-ffi", | |
| 3149 | + "drm-ffi 0.8.0", | |
| 3130 | 3150 | "drm-fourcc", |
| 3131 | 3151 | "errno", |
| 3132 | 3152 | "gbm", |
| @@ -3188,7 +3208,7 @@ dependencies = [ | ||
| 3188 | 3208 | [[package]] |
| 3189 | 3209 | name = "smithay-drm-extras" |
| 3190 | 3210 | version = "0.1.0" |
| 3191 | -source = "git+https://github.com/Smithay/smithay.git#c5e9a697e41f50dc56b918d9ef1e3d2e52c84ac0" | |
| 3211 | +source = "git+https://github.com/Smithay/smithay.git#40acc58b83400aa10fc62a51a235d1991ab46be5" | |
| 3192 | 3212 | dependencies = [ |
| 3193 | 3213 | "drm", |
| 3194 | 3214 | "edid-rs", |
src/handlers/mod.rsmodified+11 -2
| @@ -133,25 +133,34 @@ delegate_pointer_constraints!(State); | ||
| 133 | 133 | |
| 134 | 134 | impl InputMethodHandler for State { |
| 135 | 135 | fn new_popup(&mut self, surface: PopupSurface) { |
| 136 | - let popup = PopupKind::from(surface.clone()); | |
| 136 | + let popup = PopupKind::InputMethod(surface); | |
| 137 | 137 | if let Some(output) = self.output_for_popup(&popup) { |
| 138 | 138 | let scale = output.current_scale().integer_scale(); |
| 139 | 139 | let transform = output.current_transform(); |
| 140 | - let wl_surface = surface.wl_surface(); | |
| 140 | + let wl_surface = popup.wl_surface(); | |
| 141 | 141 | with_states(wl_surface, |data| { |
| 142 | 142 | send_surface_state(wl_surface, data, scale, transform); |
| 143 | 143 | }); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | + self.unconstrain_popup(&popup); | |
| 147 | + | |
| 146 | 148 | if let Err(err) = self.niri.popups.track_popup(popup) { |
| 147 | 149 | warn!("error tracking ime popup {err:?}"); |
| 148 | 150 | } |
| 149 | 151 | } |
| 152 | + | |
| 153 | + fn popup_repositioned(&mut self, surface: PopupSurface) { | |
| 154 | + let popup = PopupKind::InputMethod(surface); | |
| 155 | + self.unconstrain_popup(&popup); | |
| 156 | + } | |
| 157 | + | |
| 150 | 158 | fn dismiss_popup(&mut self, surface: PopupSurface) { |
| 151 | 159 | if let Some(parent) = surface.get_parent().map(|parent| parent.surface.clone()) { |
| 152 | 160 | let _ = PopupManager::dismiss_popup(&parent, &PopupKind::from(surface)); |
| 153 | 161 | } |
| 154 | 162 | } |
| 163 | + | |
| 155 | 164 | fn parent_geometry(&self, parent: &WlSurface) -> Rectangle<i32, Logical> { |
| 156 | 165 | self.niri |
| 157 | 166 | .layout |
src/handlers/xdg_shell.rsmodified+44 -16
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use smithay::desktop::{ |
| 2 | - find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, LayerSurface, | |
| 2 | + find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface, | |
| 3 | 3 | PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window, |
| 4 | 4 | WindowSurfaceType, |
| 5 | 5 | }; |
| @@ -177,7 +177,7 @@ impl XdgShellHandler for State { | ||
| 177 | 177 | |
| 178 | 178 | trace!("new grab for root {:?}", root); |
| 179 | 179 | keyboard.set_focus(self, grab.current_grab(), serial); |
| 180 | - keyboard.set_grab(PopupKeyboardGrab::new(&grab), serial); | |
| 180 | + keyboard.set_grab(self, PopupKeyboardGrab::new(&grab), serial); | |
| 181 | 181 | pointer.set_grab(self, PopupPointerGrab::new(&grab), serial, Focus::Keep); |
| 182 | 182 | self.niri.popup_grab = Some(PopupGrabState { root, grab }); |
| 183 | 183 | } |
| @@ -649,8 +649,11 @@ impl State { | ||
| 649 | 649 | popup.send_configure().expect("initial configure failed"); |
| 650 | 650 | } |
| 651 | 651 | } |
| 652 | - // Input method popups don't require a configure. | |
| 653 | - PopupKind::InputMethod(_) => (), | |
| 652 | + // Input method popup can arbitrary change its geometry, so we need to unconstraint | |
| 653 | + // it on commit. | |
| 654 | + PopupKind::InputMethod(_) => { | |
| 655 | + self.unconstrain_popup(&popup); | |
| 656 | + } | |
| 654 | 657 | } |
| 655 | 658 | } |
| 656 | 659 | } |
| @@ -696,14 +699,7 @@ impl State { | ||
| 696 | 699 | target.loc.y -= self.niri.layout.window_y(window).unwrap(); |
| 697 | 700 | target.loc -= get_popup_toplevel_coords(popup); |
| 698 | 701 | |
| 699 | - match popup { | |
| 700 | - PopupKind::Xdg(popup) => { | |
| 701 | - popup.with_pending_state(|state| { | |
| 702 | - state.geometry = unconstrain_with_padding(state.positioner, target); | |
| 703 | - }); | |
| 704 | - } | |
| 705 | - PopupKind::InputMethod(_) => todo!(), | |
| 706 | - } | |
| 702 | + self.position_popup_within_rect(popup, target); | |
| 707 | 703 | } |
| 708 | 704 | |
| 709 | 705 | pub fn unconstrain_layer_shell_popup( |
| @@ -724,11 +720,43 @@ impl State { | ||
| 724 | 720 | target.loc -= layer_geo.loc; |
| 725 | 721 | target.loc -= get_popup_toplevel_coords(popup); |
| 726 | 722 | |
| 723 | + self.position_popup_within_rect(popup, target); | |
| 724 | + } | |
| 725 | + | |
| 726 | + fn position_popup_within_rect(&self, popup: &PopupKind, target: Rectangle<i32, Logical>) { | |
| 727 | 727 | match popup { |
| 728 | - PopupKind::Xdg(popup) => popup.with_pending_state(|state| { | |
| 729 | - state.geometry = unconstrain_with_padding(state.positioner, target); | |
| 730 | - }), | |
| 731 | - PopupKind::InputMethod(_) => todo!(), | |
| 728 | + PopupKind::Xdg(popup) => { | |
| 729 | + popup.with_pending_state(|state| { | |
| 730 | + state.geometry = unconstrain_with_padding(state.positioner, target); | |
| 731 | + }); | |
| 732 | + } | |
| 733 | + PopupKind::InputMethod(popup) => { | |
| 734 | + let text_input_rectangle = popup.text_input_rectangle(); | |
| 735 | + let mut bbox = | |
| 736 | + utils::bbox_from_surface_tree(popup.wl_surface(), text_input_rectangle.loc); | |
| 737 | + | |
| 738 | + // Position bbox horizontally first. | |
| 739 | + let overflow_x = (bbox.loc.x + bbox.size.w) - (target.loc.x + target.size.w); | |
| 740 | + if overflow_x > 0 { | |
| 741 | + bbox.loc.x -= overflow_x; | |
| 742 | + } | |
| 743 | + | |
| 744 | + // Ensure that the popup starts within the window. | |
| 745 | + bbox.loc.x = bbox.loc.x.max(target.loc.x); | |
| 746 | + | |
| 747 | + // Try to position IME popup below the text input rectangle. | |
| 748 | + let mut below = bbox; | |
| 749 | + below.loc.y += text_input_rectangle.size.h; | |
| 750 | + | |
| 751 | + let mut above = bbox; | |
| 752 | + above.loc.y -= bbox.size.h; | |
| 753 | + | |
| 754 | + if target.loc.y + target.size.h >= below.loc.y + below.size.h { | |
| 755 | + popup.set_location(below.loc); | |
| 756 | + } else { | |
| 757 | + popup.set_location(above.loc); | |
| 758 | + } | |
| 759 | + } | |
| 732 | 760 | } |
| 733 | 761 | } |
| 734 | 762 |
src/niri.rsmodified+1 -1
| @@ -768,7 +768,7 @@ impl State { | ||
| 768 | 768 | ); |
| 769 | 769 | |
| 770 | 770 | grab.grab.ungrab(PopupUngrabStrategy::All); |
| 771 | - keyboard.unset_grab(); | |
| 771 | + keyboard.unset_grab(self); | |
| 772 | 772 | self.niri.seat.get_pointer().unwrap().unset_grab( |
| 773 | 773 | self, |
| 774 | 774 | SERIAL_COUNTER.next_serial(), |