diff --git a/src/event_loop/run.rs b/src/event_loop/run.rs index edc99c1..afc9551 100644 --- a/src/event_loop/run.rs +++ b/src/event_loop/run.rs @@ -386,13 +386,25 @@ pub( crate ) fn try_run( app: A ) -> Result<(), RunError> Err( calloop::Error::OtherError( ref e ) ) => { // wayland-client surfaces the closed-socket condition as an - // OtherError wrapping an IoError rather than as the - // calloop::Error::IoError variant handled above. Treat any - // BrokenPipe / ConnectionReset here the same way: exit cleanly. - let is_closed = e.downcast_ref::() - .map( |io| matches!( io.kind(), - std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::ConnectionReset ) ) - .unwrap_or( false ); + // OtherError wrapping a WaylandError::Io(BrokenPipe) — one + // level deeper than a direct io::Error. Walk the source() + // chain so we catch it regardless of how many wrapper types + // sit between calloop and the raw io::Error. + let mut src: Option<&dyn std::error::Error> = Some( e.as_ref() ); + let mut is_closed = false; + while let Some( err ) = src + { + if let Some( io ) = err.downcast_ref::() + { + if matches!( io.kind(), + std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::ConnectionReset ) + { + is_closed = true; + break; + } + } + src = err.source(); + } if is_closed { eprintln!( "ltk: wayland connection lost; exiting" );