Skip to content

Commit

Permalink
Fix panic when wayland display connection breaks
Browse files Browse the repository at this point in the history
Instead, terminate the thread and consider the clipboard dead. The
application can now gracefully deal with the situation.

Closes: #52
  • Loading branch information
tronical committed Feb 19, 2024
1 parent 858419b commit ee63d81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions examples/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// application. For more details on what is going on, consult the
// `smithay-client-toolkit` examples.

use std::convert::TryInto;

use sctk::compositor::{CompositorHandler, CompositorState};
use sctk::output::{OutputHandler, OutputState};
use sctk::reexports::calloop::{EventLoop, LoopHandle};
Expand All @@ -23,7 +21,7 @@ use sctk::{
delegate_compositor, delegate_keyboard, delegate_output, delegate_registry, delegate_seat,
delegate_shm, delegate_xdg_shell, delegate_xdg_window, registry_handlers,
};
use smithay_clipboard::{self, Clipboard};
use smithay_clipboard::Clipboard;

const MIN_DIM_SIZE: usize = 256;

Expand Down
6 changes: 3 additions & 3 deletions src/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl MimeType {
}
}

impl ToString for MimeType {
fn to_string(&self) -> String {
String::from(ALLOWED_MIME_TYPES[*self as usize])
impl std::fmt::Display for MimeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", ALLOWED_MIME_TYPES[*self as usize])
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ fn worker_impl(
WaylandSource::new(connection, event_queue).insert(loop_handle).unwrap();

loop {
event_loop.dispatch(None, &mut state).unwrap();

if state.exit {
if event_loop.dispatch(None, &mut state).is_err() || state.exit {
break;
}
}
Expand Down

0 comments on commit ee63d81

Please sign in to comment.