Skip to content

Commit

Permalink
feat: don't panic when getting events for dead objects
Browse files Browse the repository at this point in the history
While it's a compositor bug, make handling of such cases resulting in a
simple warning in the log instead of crashing user applications.

Fixes #458.
  • Loading branch information
kchibisov authored and wash2 committed Jul 3, 2024
1 parent ac2c420 commit fc0a26f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
22 changes: 17 additions & 5 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
sync::{Arc, Mutex, Weak},
};

use log::warn;
use wayland_client::{
globals::GlobalList,
protocol::wl_output::{self, Subpixel, Transform},
Expand Down Expand Up @@ -417,12 +418,18 @@ where
conn: &Connection,
qh: &QueueHandle<D>,
) {
let inner = state
let inner = match state
.output_state()
.outputs
.iter_mut()
.find(|inner| &inner.wl_output == output)
.expect("Received event for dead output");
{
Some(inner) => inner,
None => {
warn!("Received {event:?} for dead wl_output");
return;
}
};

match event {
wl_output::Event::Geometry {
Expand Down Expand Up @@ -533,7 +540,6 @@ where
}
}
}

_ => unreachable!(),
}
}
Expand Down Expand Up @@ -567,12 +573,18 @@ where
conn: &Connection,
qh: &QueueHandle<D>,
) {
let inner = state
let inner = match state
.output_state()
.outputs
.iter_mut()
.find(|inner| inner.xdg_output.as_ref() == Some(output))
.expect("Received event for dead output");
{
Some(inner) => inner,
None => {
warn!("Received {event:?} for dead xdg_output");
return;
}
};

// zxdg_output_v1::done is deprecated in version 3. So we only need
// to wait for wl_output::done, once we get any xdg output info.
Expand Down
18 changes: 11 additions & 7 deletions src/seat/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,17 @@ where
loop_handle.remove(token);
}

let surface = udata
.focus
.lock()
.unwrap()
.as_ref()
.cloned()
.expect("wl_keyboard::key with no focused surface");
let surface =
match udata.focus.lock().unwrap().as_ref().cloned()
{
Some(surface) => surface,

None => {
log::warn!(
"wl_keyboard::key with no focused surface");
return;
}
};

// Update the current repeat key.
repeat_data.current_repeat.replace(RepeatedKey {
Expand Down

0 comments on commit fc0a26f

Please sign in to comment.