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