diff --git a/Cargo.toml b/Cargo.toml index 025e680..39730bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ repository = "https://github.com/Smithay/smithay" members = [ "anvil" ] [dependencies] -wayland-server = "0.21.1" -wayland-sys = "0.21.1" +wayland-server = "0.21.4" +wayland-sys = "0.21.3" wayland-commons = "0.21.1" nix = "0.11" xkbcommon = "0.2.1" @@ -28,7 +28,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.21.1", features = ["unstable_protocols", "native_server"] } +wayland-protocols = { version = "0.21.3", features = ["unstable_protocols", "native_server"] } image = "0.17.0" error-chain = "0.11.0" lazy_static = "1.0.0" diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 6a5407e..4e62ca7 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -7,25 +7,22 @@ use input as libinput; use input::event; use std::{ - cell::RefCell, collections::hash_map::{DefaultHasher, Entry, HashMap}, hash::{Hash, Hasher}, io::Error as IoError, - os::unix::io::RawFd, - path::Path, - rc::Rc, + os::unix::io::{AsRawFd, RawFd}, }; use wayland_server::calloop::{ - generic::{EventedRawFd, Generic}, + generic::{EventedFd, Generic}, mio::Ready, - LoopHandle, Source, + LoopHandle, Source, InsertError, }; // No idea if this is the same across unix platforms // Lets make this linux exclusive for now, once someone tries to build it for // any BSD-like system, they can verify if this is right and make a PR to change this. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(all(any(target_os = "linux", target_os = "android"), feature = "backend_session"))] const INPUT_MAJOR: u32 = 13; /// Libinput based `InputBackend`. @@ -590,6 +587,12 @@ impl libinput::LibinputInterface for LibinputSessionInterface { } } +impl AsRawFd for LibinputInputBackend { + fn as_raw_fd(&self) -> RawFd { + unsafe { self.context.fd() } + } +} + /// Binds a `LibinputInputBackend` to a given `EventLoop`. /// /// Automatically feeds the backend with incoming events without any manual calls to @@ -597,22 +600,16 @@ impl libinput::LibinputInterface for LibinputSessionInterface { pub fn libinput_bind( backend: LibinputInputBackend, handle: LoopHandle, -) -> ::std::result::Result>, (IoError, LibinputInputBackend)> { - let mut source = Generic::from_raw_fd(unsafe { backend.context.fd() }); +) -> ::std::result::Result>>, InsertError>>> { + let mut source = Generic::from_fd_source(backend); source.set_interest(Ready::readable()); - let backend = Rc::new(RefCell::new(backend)); - let fail_backend = backend.clone(); - handle - .insert_source(source, move |_, _| { - use backend::input::InputBackend; - if let Err(error) = backend.borrow_mut().dispatch_new_events() { - warn!(backend.borrow().logger, "Libinput errored: {}", error); - } - }).map_err(move |e| { - // the backend in the closure should already have been dropped - let backend = Rc::try_unwrap(fail_backend) - .unwrap_or_else(|_| unreachable!()) - .into_inner(); - (e.into(), backend) - }) + + handle.insert_source(source, move |evt, _| { + use backend::input::InputBackend; + + let mut backend = evt.source.borrow_mut(); + if let Err(error) = backend.0.dispatch_new_events() { + warn!(backend.0.logger, "Libinput errored: {}", error); + } + }) } diff --git a/src/backend/winit.rs b/src/backend/winit.rs index dd03a8e..f7d3a41 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -2,15 +2,16 @@ use backend::{ graphics::{ - egl::{ - context::GlAttributes, - error as egl_error, - error::Result as EGLResult, - native, - wayland::{EGLDisplay, EGLWaylandExtensions}, - EGLContext, EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError, - }, - GraphicsBackend, + gl::{GLGraphicsBackend, PixelFormat}, + CursorBackend, + SwapBuffersError, + }, + egl::{ + context::GlAttributes, + error as egl_error, + error::Result as EGLResult, + native, + EGLDisplay, EGLContext, EGLGraphicsBackend, EGLSurface, }, input::{ Axis, AxisSource, Event as BackendEvent, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, @@ -156,12 +157,12 @@ where let reqs = Default::default(); let window = Rc::new( if native::NativeDisplay::::is_backend(&winit_window) { - let context = + let mut context = EGLContext::::new(winit_window, attributes, reqs, log.clone())?; let surface = context.create_surface(())?; Window::Wayland { context, surface } } else if native::NativeDisplay::::is_backend(&winit_window) { - let context = + let mut context = EGLContext::::new(winit_window, attributes, reqs, log.clone())?; let surface = context.create_surface(())?; Window::X11 { context, surface } @@ -226,8 +227,8 @@ impl WinitGraphicsBackend { } } -impl GraphicsBackend for WinitGraphicsBackend { - type CursorFormat = MouseCursor; +impl<'a> CursorBackend<'a> for WinitGraphicsBackend { + type CursorFormat = &'a MouseCursor; type Error = (); fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> { @@ -240,11 +241,13 @@ impl GraphicsBackend for WinitGraphicsBackend { }) } - fn set_cursor_representation( - &self, - cursor: &Self::CursorFormat, + fn set_cursor_representation<'b>( + &'b self, + cursor: Self::CursorFormat, _hotspot: (u32, u32), - ) -> ::std::result::Result<(), ()> { + ) -> ::std::result::Result<(), ()> + where 'a: 'b + { // Cannot log this one, as `CursorFormat` is not `Debug` and should not be debug!(self.logger, "Changing cursor representation"); self.window.window().set_cursor(*cursor); @@ -252,7 +255,7 @@ impl GraphicsBackend for WinitGraphicsBackend { } } -impl EGLGraphicsBackend for WinitGraphicsBackend { +impl GLGraphicsBackend for WinitGraphicsBackend { fn swap_buffers(&self) -> ::std::result::Result<(), SwapBuffersError> { trace!(self.logger, "Swapping buffers"); match *self.window { @@ -303,7 +306,7 @@ impl EGLGraphicsBackend for WinitGraphicsBackend { } } -impl EGLWaylandExtensions for WinitGraphicsBackend { +impl EGLGraphicsBackend for WinitGraphicsBackend { fn bind_wl_display(&self, display: &Display) -> EGLResult { match *self.window { Window::Wayland { ref context, .. } => context.bind_wl_display(display),