Fix Error handling in layershell producer (#61)

previous error handling resulted in a softlock when the connection
to the compositor was lost
This commit is contained in:
Ferdinand Schober
2024-01-01 22:07:21 +01:00
committed by GitHub
parent f5827bb31c
commit 6cdb607b11
8 changed files with 88 additions and 46 deletions

View File

@@ -24,9 +24,13 @@ impl Default for DummyProducer {
}
impl EventProducer for DummyProducer {
fn notify(&mut self, _: ClientEvent) {}
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
fn release(&mut self) {}
fn release(&mut self) -> io::Result<()> {
Ok(())
}
}
impl Stream for DummyProducer {

View File

@@ -3,7 +3,11 @@ use std::{io, task::Poll};
use futures_core::Stream;
use crate::{client::ClientHandle, event::Event, producer::EventProducer};
use crate::{
client::{ClientEvent, ClientHandle},
event::Event,
producer::EventProducer,
};
pub struct LibeiProducer {}
@@ -14,9 +18,13 @@ impl LibeiProducer {
}
impl EventProducer for LibeiProducer {
fn notify(&mut self, _event: crate::client::ClientEvent) {}
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
fn release(&mut self) {}
fn release(&mut self) -> io::Result<()> {
Ok(())
}
}
impl Stream for LibeiProducer {

View File

@@ -23,7 +23,11 @@ impl Stream for MacOSProducer {
}
impl EventProducer for MacOSProducer {
fn notify(&mut self, _event: ClientEvent) {}
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
fn release(&mut self) {}
fn release(&mut self) -> io::Result<()> {
Ok(())
}
}

View File

@@ -527,24 +527,25 @@ impl Inner {
}
}
fn flush_events(&mut self) {
fn flush_events(&mut self) -> io::Result<()> {
// flush outgoing events
match self.queue.flush() {
Ok(_) => (),
Err(e) => match e {
WaylandError::Io(e) => {
log::error!("error writing to wayland socket: {e}")
return Err(e);
}
WaylandError::Protocol(e) => {
panic!("wayland protocol violation: {e}")
}
},
}
Ok(())
}
}
impl EventProducer for WaylandEventProducer {
fn notify(&mut self, client_event: ClientEvent) {
fn notify(&mut self, client_event: ClientEvent) -> io::Result<()> {
match client_event {
ClientEvent::Create(handle, pos) => {
self.0.get_mut().state.add_client(handle, pos);
@@ -564,14 +565,14 @@ impl EventProducer for WaylandEventProducer {
}
}
let inner = self.0.get_mut();
inner.flush_events();
inner.flush_events()
}
fn release(&mut self) {
fn release(&mut self) -> io::Result<()> {
log::debug!("releasing pointer");
let inner = self.0.get_mut();
inner.state.ungrab();
inner.flush_events();
inner.flush_events()
}
}
@@ -602,7 +603,11 @@ impl Stream for WaylandEventProducer {
inner.dispatch_events();
// flush outgoing events
inner.flush_events();
if let Err(e) = inner.flush_events() {
if e.kind() != ErrorKind::WouldBlock {
return Poll::Ready(Some(Err(e)));
}
}
// prepare for the next read
match inner.prepare_read() {

View File

@@ -12,9 +12,13 @@ use crate::{
pub struct WindowsProducer {}
impl EventProducer for WindowsProducer {
fn notify(&mut self, _: ClientEvent) {}
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
fn release(&mut self) {}
fn release(&mut self) -> io::Result<()> {
Ok(())
}
}
impl WindowsProducer {

View File

@@ -18,9 +18,13 @@ impl X11Producer {
}
impl EventProducer for X11Producer {
fn notify(&mut self, _: ClientEvent) {}
fn notify(&mut self, _event: ClientEvent) -> io::Result<()> {
Ok(())
}
fn release(&mut self) {}
fn release(&mut self) -> io::Result<()> {
Ok(())
}
}
impl Stream for X11Producer {