refactor: make handle_pending_enter fn function

This commit is contained in:
En-En 2025-11-05 13:30:30 +00:00 committed by Supreeeme
parent e8079bc072
commit 56256a1340

View file

@ -460,39 +460,45 @@ impl Event for client::wl_pointer::Event {
// Niri). Other compositors do not run into this problem because they appear to not send // Niri). Other compositors do not run into this problem because they appear to not send
// wl_pointer.enter until the user actually moves the mouse in the popup. // wl_pointer.enter until the user actually moves the mouse in the popup.
let handle_pending_enter = |target: Entity, state: &mut ServerState<C>, event_str: &str| loop { fn handle_pending_enter<C: XConnection>(
let Ok(pe) = state.world.get::<&PendingEnter>(target) else { target: Entity,
return true; state: &mut ServerState<C>,
}; event_str: &str,
let PendingEnter(client::wl_pointer::Event::Enter { ) -> bool {
serial, loop {
surface, let Ok(pe) = state.world.get::<&PendingEnter>(target) else {
surface_x, return true;
surface_y,
}) = pe.deref()
else {
unreachable!();
};
if surface
.data()
.copied()
.is_some_and(|key| state.world.contains(key))
{
trace!("resending enter ({serial}) before {}", event_str);
let enter_event = client::wl_pointer::Event::Enter {
serial: *serial,
surface: surface.clone(),
surface_x: *surface_x,
surface_y: *surface_y,
}; };
let PendingEnter(client::wl_pointer::Event::Enter {
serial,
surface,
surface_x,
surface_y,
}) = pe.deref()
else {
unreachable!();
};
if surface
.data()
.copied()
.is_some_and(|key| state.world.contains(key))
{
trace!("resending enter ({serial}) before {}", event_str);
let enter_event = client::wl_pointer::Event::Enter {
serial: *serial,
surface: surface.clone(),
surface_x: *surface_x,
surface_y: *surface_y,
};
drop(pe); drop(pe);
Self::handle(enter_event, target, state); Event::handle(enter_event, target, state);
} else { } else {
warn!("could not move pointer to surface: stale surface"); warn!("could not move pointer to surface: stale surface");
return false; return false;
}
} }
}; }
match self { match self {
Self::Enter { Self::Enter {