diff --git a/src/handlers.rs b/src/handlers.rs index 48e3512..897494f 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -22,8 +22,8 @@ use smithay::{ delegate_security_context, delegate_shm, delegate_tablet_manager, delegate_viewporter, delegate_xdg_activation, delegate_xwayland_keyboard_grab, delegate_xwayland_shell, desktop::{ - self, find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, PopupKind, - PopupManager, WindowSurfaceType, + self, find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, + space::SpaceElement, PopupKind, PopupManager, WindowSurfaceType, }, input::{ keyboard::LedState, @@ -914,7 +914,24 @@ impl PointerConstraintsHandler for State { pointer: &PointerHandle, location: Point, ) { - todo!() + if with_pointer_constraint(surface, pointer, |constraint| { + constraint.is_some_and(|c| c.is_active()) + }) { + // TODO: cache the current focus's location so you don't have to get it on demand + // through the current pointer location + let Some((current_focus, current_focus_loc)) = self + .pinnacle + .pointer_focus_target_under(pointer.current_location()) + else { + return; + }; + + if current_focus.wl_surface().as_deref() != Some(surface) { + return; + } + + pointer.set_location(current_focus_loc + location); + } } } delegate_pointer_constraints!(State); diff --git a/src/input.rs b/src/input.rs index ed8dbfa..d40a2fa 100644 --- a/src/input.rs +++ b/src/input.rs @@ -124,9 +124,6 @@ pub struct InputState { pub libinput_settings: HashMap, Box>, /// All libinput devices that have been connected pub libinput_devices: Vec, - - locked_pointer_position_hint: Option>, - // Keys that were used in a keybind and should not be released no_release_keys: HashSet, } @@ -340,46 +337,7 @@ impl State { let location = pointer.current_location(); let surface_under = self.pinnacle.pointer_focus_target_under(location); - // PERF: I'm not really a fan of polling all the time looking for locked pointer - // updates, but there doesn't seem to be a great way to get the final cursor - // position hint before destruction. I experimented with a - // `PointerConstraintsHandler::constraint_destroyed` method but doing so - // required threading the state through a bunch of different functions. - // Additionally, `PointerConstraintRef::deactivate` gets called in `WlSurface::leave`, - // so that would require all compositors implement `PointerConstraintsHandler` - // which seems very scuffed. if pointer.current_focus().as_ref() == surface_under.as_ref().map(|s| &s.0) { - if let Some((surf, surf_loc)) = - surface_under.and_then(|(foc, loc)| Some((foc.wl_surface()?.into_owned(), loc))) - { - let unlocked = with_pointer_constraint(&surf, &pointer, |constraint| { - let Some(constraint) = constraint else { - return true; - }; - if !constraint.is_active() { - return true; - } - match &*constraint { - PointerConstraint::Confined(_) => true, - PointerConstraint::Locked(locked) => { - self.pinnacle.input_state.locked_pointer_position_hint = - locked.cursor_position_hint(); - false - } - } - }); - - if unlocked { - if let Some(hint) = self - .pinnacle - .input_state - .locked_pointer_position_hint - .take() - { - self.warp_cursor_to_global_loc(hint + surf_loc.to_f64()); - } - } - } return; } @@ -809,7 +767,7 @@ impl State { let Some(constraint) = constraint else { return; }; - tracing::debug!(constraint = ?*constraint); + if !constraint.is_active() { return; }