shell: remove constraint when target changed

This commit is contained in:
Skygrango 2026-05-13 20:06:33 +08:00 committed by Ian Douglas Scott
parent 9702aae523
commit 81066d437a

View file

@ -1,6 +1,6 @@
use crate::{
shell::{CosmicSurface, MinimizedWindow, Shell, Trigger, element::CosmicMapped},
state::Common,
state::{Common, State},
utils::prelude::*,
wayland::handlers::{xdg_shell::PopupGrabData, xwayland_keyboard_grab::XWaylandGrabSeatData},
};
@ -12,6 +12,7 @@ use smithay::{
reexports::wayland_server::{Resource, protocol::wl_surface::WlSurface},
utils::{IsAlive, Point, SERIAL_COUNTER, Serial},
wayland::{
pointer_constraints::with_pointer_constraint,
seat::WaylandFocus,
selection::{data_device::set_data_device_focus, primary_selection::set_primary_focus},
shell::wlr_layer::{KeyboardInteractivity, Layer},
@ -347,6 +348,20 @@ fn update_focus_state(
) {
// update keyboard focus
if let Some(keyboard) = seat.get_keyboard() {
// remove constraint when target changed
let old_focus = keyboard.current_focus();
if let Some(old_target) = old_focus
&& target != Some(&old_target)
&& let Some(surface) = old_target.wl_surface()
&& let Some(pointer) = seat.get_pointer()
{
with_pointer_constraint(&surface, &pointer, |constraint| {
if let Some(constraint) = constraint {
constraint.deactivate();
}
});
}
if should_update_cursor
&& state.common.config.cosmic_conf.cursor_follows_focus
&& target.is_some()