Update for wayland-server 0.14

This commit is contained in:
Drakulix 2018-02-21 20:26:10 +01:00
parent 6f597e2244
commit 5cfdf931fb
9 changed files with 71 additions and 47 deletions

View File

@ -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"

View File

@ -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<Card> for DrmHandlerImpl {
fn ready(
&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<Card>, _crtc: crtc::Handle, _frame: u32, _duration: Duration
&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<Card>, _crtc: crtc::Handle,
_frame: u32, _duration: Duration,
) {
let mut frame = self.drawer.draw();
frame.clear_color(0.8, 0.8, 0.9, 1.0);

View File

@ -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<SessionFdDrmDevice> for DrmHandlerImpl {
fn ready(
&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<SessionFdDrmDevice>, crtc: crtc::Handle, _frame: u32,
_duration: Duration,
&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<SessionFdDrmDevice>,
crtc: crtc::Handle, _frame: u32, _duration: Duration,
) {
if let Some(drawer) = self.backends.borrow().get(&crtc) {
{
@ -597,7 +603,9 @@ impl DrmHandler<SessionFdDrmDevice> for DrmHandlerImpl {
}
}
fn error(&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<SessionFdDrmDevice>, error: DrmError) {
fn error(
&mut self, _evlh: &mut EventLoopHandle, _device: &mut DrmDevice<SessionFdDrmDevice>, error: DrmError
) {
error!(self.logger, "{:?}", error);
}
}

View File

@ -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<A: ControlDevice + 'static> {
/// This will cause it to recieve events and feed them into an `DrmHandler`
pub fn drm_device_bind<A, H>(
evlh: &mut EventLoopHandle, device: DrmDevice<A>, handler: H
) -> IoResult<FdEventSource<(DrmDevice<A>, H)>>
) -> ::std::result::Result<FdEventSource<(DrmDevice<A>, H)>, (IoError, (DrmDevice<A>, H))>
where
A: ControlDevice + 'static,
H: DrmHandler<A> + 'static,
@ -612,6 +612,7 @@ pub struct DrmDeviceObserver<A: ControlDevice + 'static> {
logger: ::slog::Logger,
}
#[cfg(feature = "backend_session")]
impl<A: ControlDevice + 'static> AsSessionObserver<DrmDeviceObserver<A>> for DrmDevice<A> {
fn observer(&mut self) -> DrmDeviceObserver<A> {
DrmDeviceObserver {

View File

@ -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<S: Session> libinput::LibinputInterface for LibinputSessionInterface<S> {
/// `dispatch_new_events`. Should be used to achieve the smallest possible latency.
pub fn libinput_bind(
backend: LibinputInputBackend, evlh: &mut EventLoopHandle
) -> IoResult<FdEventSource<LibinputInputBackend>> {
) -> ::std::result::Result<FdEventSource<LibinputInputBackend>, (IoError, LibinputInputBackend)> {
let fd = unsafe { backend.context.fd() };
evlh.add_fd_event_source(
fd,

View File

@ -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<BoundAutoSession> {
) -> ::std::result::Result<BoundAutoSession, (IoError, AutoSessionNotifier)> {
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)))?),
})
}

View File

@ -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<BoundLogindSession> {
) -> ::std::result::Result<BoundLogindSession, (IoError, LogindSessionNotifier)> {
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::<IoResult<Vec<FdEventSource<Rc<LogindSessionImpl>>>>>()?;
.collect::<::std::result::Result<Vec<FdEventSource<Rc<LogindSessionImpl>>>, (IoError, _)>>()
.map_err(|(err, _)| {
(
err,
LogindSessionNotifier {
internal: internal_for_error,
},
)
})?;
Ok(BoundLogindSession {
notifier,

View File

@ -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<SignalEventSource<DirectSessionNotifier>> {
) -> ::std::result::Result<SignalEventSource<DirectSessionNotifier>, (IoError, DirectSessionNotifier)> {
let signal = notifier.signal;
evlh.add_signal_event_source(

View File

@ -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,21 +92,22 @@ impl<H: DrmHandler<SessionFdDrmDevice> + '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);
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 => {
drop(device); //drops master
@ -211,7 +212,7 @@ impl<H: DrmHandler<SessionFdDrmDevice> + 'static> SessionObserver for UdevBacken
/// No runtime functionality can be provided without using this function.
pub fn udev_backend_bind<S, H, T>(
evlh: &mut EventLoopHandle, udev: UdevBackend<H, S, T>
) -> IoResult<FdEventSource<UdevBackend<H, S, T>>>
) -> ::std::result::Result<FdEventSource<UdevBackend<H, S, T>>, (IoError, UdevBackend<H, S, T>)>
where
H: DrmHandler<SessionFdDrmDevice> + 'static,
T: UdevHandler<H> + '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!(