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,45 +634,51 @@ 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;
state.last_kb_serial = Some(( };
data.get::<&client::wl_seat::WlSeat>() let Some((window, surface, output)) = query.get() else {
.as_deref() return;
.unwrap() };
.clone(), state.last_kb_serial = Some((
serial, data.get::<&client::wl_seat::WlSeat>()
)); .as_deref()
let output_name = get_output_name(output, &state.world); .unwrap()
state.to_focus = Some(FocusData { .clone(),
window: *window, serial,
output_name, ));
}); let output_name = get_output_name(output, &state.world);
keyboard.enter(serial, surface, keys); state.to_focus = Some(FocusData {
} window: *window,
output_name,
});
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;
if state.to_focus.as_ref().map(|d| d.window) == Some(*window) { };
state.to_focus.take(); let Some((window, surface)) = query.get() else {
} else { return;
state.unfocus = true; };
} if state.to_focus.as_ref().map(|d| d.window) == Some(*window) {
keyboard.leave(serial, surface); state.to_focus.take();
} else {
state.unfocus = true;
} }
keyboard.leave(serial, surface);
} }
client::wl_keyboard::Event::Key { client::wl_keyboard::Event::Key {
serial, serial,
@ -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(),