Removed additional dubious unwraps

The wl_keyboard Enter event, wl_keyboard Leave event, the wl_touch
Self::Down event and the ServerState::reconfigure_window function had
similar uses of `unwrap` which appear to not consider the distinct
query preparation and query execution stages.
This commit is contained in:
En-En 2025-06-22 22:09:39 +00:00 committed by Supreeeme
parent da3b2838d2
commit 8dc4538662
2 changed files with 39 additions and 29 deletions

View file

@ -634,13 +634,17 @@ impl Event for client::wl_keyboard::Event {
surface,
keys,
} => {
if let Some(mut query) = surface.data().copied().and_then(|key| {
let Some(mut query) = surface.data().copied().and_then(|key| {
state
.world
.query_one::<(&x::Window, &WlSurface, Option<&OnOutput>)>(key)
.ok()
}) {
let (window, surface, output) = query.get().unwrap();
}) else {
return;
};
let Some((window, surface, output)) = query.get() else {
return;
};
state.last_kb_serial = Some((
data.get::<&client::wl_seat::WlSeat>()
.as_deref()
@ -655,17 +659,20 @@ impl Event for client::wl_keyboard::Event {
});
keyboard.enter(serial, surface, keys);
}
}
client::wl_keyboard::Event::Leave { serial, surface } => {
if !surface.is_alive() {
return;
}
if let Some(mut query) = surface
let Some(mut query) = surface
.data()
.copied()
.and_then(|key| state.world.query_one::<(&x::Window, &WlSurface)>(key).ok())
{
let (window, surface) = query.get().unwrap();
else {
return;
};
let Some((window, surface)) = query.get() else {
return;
};
if state.to_focus.as_ref().map(|d| d.window) == Some(*window) {
state.to_focus.take();
} else {
@ -673,7 +680,6 @@ impl Event for client::wl_keyboard::Event {
}
keyboard.leave(serial, surface);
}
}
client::wl_keyboard::Event::Key {
serial,
time,
@ -734,8 +740,10 @@ impl Event for client::wl_touch::Event {
}) else {
return;
};
let Some((s_surface, s_factor)) = s_query.get() else {
return;
};
let (s_surface, s_factor) = s_query.get().unwrap();
cmd.insert(target, (*s_factor,));
let touch = state.world.get::<&WlTouch>(target).unwrap();
touch.down(serial, time, s_surface, id, x * s_factor.0, y * s_factor.0);

View file

@ -736,8 +736,10 @@ impl<C: XConnection> ServerState<C> {
debug!("not reconfiguring unknown window {:?}", event.window());
return;
};
let mut win = data.get::<&mut WindowData>().unwrap();
let Some(mut win) = data.get::<&mut WindowData>() else {
debug!("not reconfiguring unknown window {:?}", event.window());
return;
};
let dims = WindowDims {
x: event.x(),