diff --git a/Cargo.toml b/Cargo.toml index ccb44ec..4f99f5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ description = "Smithay is a library for writing wayland compositors." repository = "https://github.com/Smithay/smithay" [dependencies] -wayland-server = "0.13.0" -wayland-sys = "0.13.0" +wayland-server = "0.14.0" +wayland-sys = "0.14.0" nix = "0.9.0" xkbcommon = "0.2.1" tempfile = "2.1.5" @@ -24,7 +24,7 @@ input = { version = "0.4.0", optional = true } udev = { version = "0.2.0", optional = true } dbus = { version = "0.6.1", optional = true } systemd = { version = "^0.2.0", optional = true } -wayland-protocols = { version = "0.13.0", features = ["unstable_protocols", "server"] } +wayland-protocols = { version = "0.14.0", features = ["unstable_protocols", "server"] } image = "0.17.0" error-chain = "0.11.0" lazy_static = "1.0.0" diff --git a/examples/drm.rs b/examples/drm.rs index 325f0fb..86e81b9 100644 --- a/examples/drm.rs +++ b/examples/drm.rs @@ -147,7 +147,8 @@ fn main() { drawer: renderer, logger: log, }, - ).unwrap(); + ).map_err(|(err, _)| err) + .unwrap(); loop { event_loop.dispatch(Some(16)).unwrap(); @@ -166,7 +167,8 @@ pub struct DrmHandlerImpl { impl DrmHandler for DrmHandlerImpl { fn ready( - &mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, _crtc: crtc::Handle, _frame: u32, _duration: Duration + &mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, _crtc: crtc::Handle, + _frame: u32, _duration: Duration, ) { let mut frame = self.drawer.draw(); frame.clear_color(0.8, 0.8, 0.9, 1.0); diff --git a/examples/udev.rs b/examples/udev.rs index e0ae6b5..cfe5134 100644 --- a/examples/udev.rs +++ b/examples/udev.rs @@ -357,10 +357,16 @@ fn main() { running: running.clone(), }, ); - let libinput_event_source = libinput_bind(libinput_backend, &mut event_loop).unwrap(); + let libinput_event_source = libinput_bind(libinput_backend, &mut event_loop) + .map_err(|(err, _)| err) + .unwrap(); - let session_event_source = auto_session_bind(notifier, &mut event_loop).unwrap(); - let udev_event_source = udev_backend_bind(&mut event_loop, udev_backend).unwrap(); + let session_event_source = auto_session_bind(notifier, &mut event_loop) + .map_err(|(err, _)| err) + .unwrap(); + let udev_event_source = udev_backend_bind(&mut event_loop, udev_backend) + .map_err(|(err, _)| err) + .unwrap(); while running.load(Ordering::SeqCst) { if let Err(_) = event_loop.dispatch(Some(16)) { @@ -506,8 +512,8 @@ pub struct DrmHandlerImpl { impl DrmHandler for DrmHandlerImpl { fn ready( - &mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, crtc: crtc::Handle, _frame: u32, - _duration: Duration, + &mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, + crtc: crtc::Handle, _frame: u32, _duration: Duration, ) { if let Some(drawer) = self.backends.borrow().get(&crtc) { { @@ -597,7 +603,9 @@ impl DrmHandler for DrmHandlerImpl { } } - fn error(&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, error: DrmError) { + fn error( + &mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice, error: DrmError + ) { error!(self.logger, "{:?}", error); } } diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index 294cd73..91fe4b3 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -203,7 +203,7 @@ //! // render something (like clear_color) //! backend.swap_buffers().unwrap(); //! -//! let _source = drm_device_bind(&mut event_loop, device, MyDrmHandler(backend)).unwrap(); +//! let _source = drm_device_bind(&mut event_loop, device, MyDrmHandler(backend)).map_err(|(err, _)| err).unwrap(); //! //! event_loop.run().unwrap(); //! # } @@ -226,7 +226,7 @@ use nix::sys::stat::{self, dev_t, fstat}; use std::cell::RefCell; use std::collections::HashMap; use std::hash::{Hash, Hasher}; -use std::io::Result as IoResult; +use std::io::Error as IoError; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::PathBuf; use std::rc::{Rc, Weak}; @@ -548,7 +548,7 @@ pub trait DrmHandler { /// This will cause it to recieve events and feed them into an `DrmHandler` pub fn drm_device_bind( evlh: &mut EventLoopHandle, device: DrmDevice, handler: H -) -> IoResult, H)>> +) -> ::std::result::Result, H)>, (IoError, (DrmDevice, H))> where A: ControlDevice + 'static, H: DrmHandler + 'static, @@ -612,6 +612,7 @@ pub struct DrmDeviceObserver { logger: ::slog::Logger, } +#[cfg(feature = "backend_session")] impl AsSessionObserver> for DrmDevice { fn observer(&mut self) -> DrmDeviceObserver { DrmDeviceObserver { diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 148f7be..07f6561 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -7,7 +7,7 @@ use input as libinput; use input::event; use std::collections::hash_map::{DefaultHasher, Entry, HashMap}; use std::hash::{Hash, Hasher}; -use std::io::{Error as IoError, Result as IoResult}; +use std::io::Error as IoError; use std::os::unix::io::RawFd; use std::path::Path; use std::rc::Rc; @@ -635,7 +635,7 @@ impl libinput::LibinputInterface for LibinputSessionInterface { /// `dispatch_new_events`. Should be used to achieve the smallest possible latency. pub fn libinput_bind( backend: LibinputInputBackend, evlh: &mut EventLoopHandle -) -> IoResult> { +) -> ::std::result::Result, (IoError, LibinputInputBackend)> { let fd = unsafe { backend.context.fd() }; evlh.add_fd_event_source( fd, diff --git a/src/backend/session/auto.rs b/src/backend/session/auto.rs index a32ed03..c65d5ad 100644 --- a/src/backend/session/auto.rs +++ b/src/backend/session/auto.rs @@ -35,7 +35,7 @@ use super::direct::{self, direct_session_bind, DirectSession, DirectSessionNotif use super::logind::{self, logind_session_bind, BoundLogindSession, LogindSession, LogindSessionNotifier}; use nix::fcntl::OFlag; use std::cell::RefCell; -use std::io::Result as IoResult; +use std::io::Error as IoError; use std::os::unix::io::RawFd; use std::path::Path; use std::rc::Rc; @@ -154,11 +154,13 @@ impl AutoSession { /// session state and call it's `SessionObservers`. pub fn auto_session_bind( notifier: AutoSessionNotifier, evlh: &mut EventLoopHandle -) -> IoResult { +) -> ::std::result::Result { Ok(match notifier { #[cfg(feature = "backend_session_logind")] - AutoSessionNotifier::Logind(logind) => BoundAutoSession::Logind(logind_session_bind(logind, evlh)?), - AutoSessionNotifier::Direct(direct) => BoundAutoSession::Direct(direct_session_bind(direct, evlh)?), + AutoSessionNotifier::Logind(logind) => BoundAutoSession::Logind(logind_session_bind(logind, evlh) + .map_err(|(error, notifier)| (error, AutoSessionNotifier::Logind(notifier)))?), + AutoSessionNotifier::Direct(direct) => BoundAutoSession::Direct(direct_session_bind(direct, evlh) + .map_err(|(error, notifier)| (error, AutoSessionNotifier::Direct(notifier)))?), }) } diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index 38ce38d..54a3e4c 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -36,7 +36,7 @@ use dbus::{BusName, BusType, Connection, ConnectionItem, ConnectionItems, Interf use nix::fcntl::OFlag; use nix::sys::stat::{fstat, major, minor, stat}; use std::cell::RefCell; -use std::io::Result as IoResult; +use std::io::Error as IoError; use std::os::unix::io::RawFd; use std::path::Path; use std::rc::{Rc, Weak}; @@ -432,8 +432,10 @@ pub struct BoundLogindSession { /// session state and call it's `SessionObservers`. pub fn logind_session_bind( notifier: LogindSessionNotifier, evlh: &mut EventLoopHandle -) -> IoResult { +) -> ::std::result::Result { let watches = notifier.internal.conn.borrow().watch_fds(); + + let internal_for_error = notifier.internal.clone(); let sources = watches .clone() .into_iter() @@ -448,7 +450,15 @@ pub fn logind_session_bind( interest, ) }) - .collect::>>>>()?; + .collect::<::std::result::Result>>, (IoError, _)>>() + .map_err(|(err, _)| { + ( + err, + LogindSessionNotifier { + internal: internal_for_error, + }, + ) + })?; Ok(BoundLogindSession { notifier, diff --git a/src/backend/session/direct.rs b/src/backend/session/direct.rs index d5567aa..eaeded8 100644 --- a/src/backend/session/direct.rs +++ b/src/backend/session/direct.rs @@ -52,7 +52,7 @@ use nix::libc::c_int; use nix::sys::signal::{self, Signal}; use nix::sys::stat::{dev_t, fstat, major, minor, Mode}; use nix::unistd::{close, dup}; -use std::io::Result as IoResult; +use std::io::Error as IoError; use std::os::unix::io::RawFd; use std::path::Path; use std::sync::Arc; @@ -369,7 +369,7 @@ impl SessionNotifier for DirectSessionNotifier { /// session state and call it's `SessionObservers`. pub fn direct_session_bind( notifier: DirectSessionNotifier, evlh: &mut EventLoopHandle -) -> IoResult> { +) -> ::std::result::Result, (IoError, DirectSessionNotifier)> { let signal = notifier.signal; evlh.add_signal_event_source( diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 49a3dd2..c849d27 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -18,7 +18,7 @@ use nix::sys::stat::dev_t; use std::cell::RefCell; use std::collections::HashMap; use std::ffi::OsString; -use std::io::{Error as IoError, Result as IoResult}; +use std::io::Error as IoError; use std::mem::drop; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::{Path, PathBuf}; @@ -92,20 +92,21 @@ impl + 'static, S: Session + 'static, T: UdevH ) { // Call the handler, which might add it to the runloop Ok(mut device) => { - let fd = device.as_raw_fd(); let devnum = device.device_id(); + let fd = device.as_raw_fd(); match handler.device_added(evlh, &mut device) { Some(drm_handler) => { - if let Ok(event_source) = drm_device_bind(&mut evlh, device, drm_handler) { - Some((devnum, event_source)) - } else { - //TODO fix wayland_server to return idata on error - // handler.device_removed(evlh, &mut device); - // drop(device); - if let Err(err) = session.close(fd) { - warn!(logger, "Failed to close dropped device. Error: {:?}. Ignoring", err); - }; - None + match drm_device_bind(&mut evlh, device, drm_handler) { + Ok(event_source) => Some((devnum, event_source)), + Err((err, (mut device, _))) => { + warn!(logger, "Failed to bind device. Error: {:?}.", err); + handler.device_removed(evlh, &mut device); + drop(device); + if let Err(err) = session.close(fd) { + warn!(logger, "Failed to close dropped device. Error: {:?}. Ignoring", err); + }; + None + } } }, None => { @@ -211,7 +212,7 @@ impl + 'static> SessionObserver for UdevBacken /// No runtime functionality can be provided without using this function. pub fn udev_backend_bind( evlh: &mut EventLoopHandle, udev: UdevBackend -) -> IoResult>> +) -> ::std::result::Result>, (IoError, UdevBackend)> where H: DrmHandler + 'static, T: UdevHandler + 'static, @@ -273,15 +274,14 @@ where }; let fd = device.as_raw_fd(); match udev.handler.device_added(evlh, &mut device) { - Some(drm_handler) => { - if let Ok(fd_event_source) = - drm_device_bind(&mut evlh, device, drm_handler) - { + Some(drm_handler) => match drm_device_bind(&mut evlh, device, drm_handler) { + Ok(fd_event_source) => { udev.devices.borrow_mut().insert(devnum, fd_event_source); - } else { - //TODO fix wayland_server to return idata on error - //udev.handler.device_removed(evlh, &mut device); - //drop(device); + } + Err((err, (mut device, _))) => { + warn!(udev.logger, "Failed to bind device. Error: {:?}.", err); + udev.handler.device_removed(evlh, &mut device); + drop(device); if let Err(err) = udev.session.close(fd) { warn!( udev.logger, @@ -289,8 +289,9 @@ where ); }; } - } + }, None => { + udev.handler.device_removed(evlh, &mut device); drop(device); if let Err(err) = udev.session.close(fd) { warn!(