Upgrade backends to calloop 0.4 and renamed gl-traits

This commit is contained in:
Victor Brekenfeld 2018-11-21 09:37:57 +01:00
parent 38ec44f70c
commit 505791e336
3 changed files with 46 additions and 46 deletions

View File

@ -10,8 +10,8 @@ repository = "https://github.com/Smithay/smithay"
members = [ "anvil" ] members = [ "anvil" ]
[dependencies] [dependencies]
wayland-server = "0.21.1" wayland-server = "0.21.4"
wayland-sys = "0.21.1" wayland-sys = "0.21.3"
wayland-commons = "0.21.1" wayland-commons = "0.21.1"
nix = "0.11" nix = "0.11"
xkbcommon = "0.2.1" xkbcommon = "0.2.1"
@ -28,7 +28,7 @@ input = { version = "0.4.0", optional = true }
udev = { version = "0.2.0", optional = true } udev = { version = "0.2.0", optional = true }
dbus = { version = "0.6.1", optional = true } dbus = { version = "0.6.1", optional = true }
systemd = { version = "^0.2.0", 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" image = "0.17.0"
error-chain = "0.11.0" error-chain = "0.11.0"
lazy_static = "1.0.0" lazy_static = "1.0.0"

View File

@ -7,25 +7,22 @@ use input as libinput;
use input::event; use input::event;
use std::{ use std::{
cell::RefCell,
collections::hash_map::{DefaultHasher, Entry, HashMap}, collections::hash_map::{DefaultHasher, Entry, HashMap},
hash::{Hash, Hasher}, hash::{Hash, Hasher},
io::Error as IoError, io::Error as IoError,
os::unix::io::RawFd, os::unix::io::{AsRawFd, RawFd},
path::Path,
rc::Rc,
}; };
use wayland_server::calloop::{ use wayland_server::calloop::{
generic::{EventedRawFd, Generic}, generic::{EventedFd, Generic},
mio::Ready, mio::Ready,
LoopHandle, Source, LoopHandle, Source, InsertError,
}; };
// No idea if this is the same across unix platforms // No idea if this is the same across unix platforms
// Lets make this linux exclusive for now, once someone tries to build it for // 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. // 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; const INPUT_MAJOR: u32 = 13;
/// Libinput based `InputBackend`. /// Libinput based `InputBackend`.
@ -590,6 +587,12 @@ impl<S: Session> libinput::LibinputInterface for LibinputSessionInterface<S> {
} }
} }
impl AsRawFd for LibinputInputBackend {
fn as_raw_fd(&self) -> RawFd {
unsafe { self.context.fd() }
}
}
/// Binds a `LibinputInputBackend` to a given `EventLoop`. /// Binds a `LibinputInputBackend` to a given `EventLoop`.
/// ///
/// Automatically feeds the backend with incoming events without any manual calls to /// Automatically feeds the backend with incoming events without any manual calls to
@ -597,22 +600,16 @@ impl<S: Session> libinput::LibinputInterface for LibinputSessionInterface<S> {
pub fn libinput_bind<Data: 'static>( pub fn libinput_bind<Data: 'static>(
backend: LibinputInputBackend, backend: LibinputInputBackend,
handle: LoopHandle<Data>, handle: LoopHandle<Data>,
) -> ::std::result::Result<Source<Generic<EventedRawFd>>, (IoError, LibinputInputBackend)> { ) -> ::std::result::Result<Source<Generic<EventedFd<LibinputInputBackend>>>, InsertError<Generic<EventedFd<LibinputInputBackend>>>> {
let mut source = Generic::from_raw_fd(unsafe { backend.context.fd() }); let mut source = Generic::from_fd_source(backend);
source.set_interest(Ready::readable()); source.set_interest(Ready::readable());
let backend = Rc::new(RefCell::new(backend));
let fail_backend = backend.clone(); handle.insert_source(source, move |evt, _| {
handle use backend::input::InputBackend;
.insert_source(source, move |_, _| {
use backend::input::InputBackend; let mut backend = evt.source.borrow_mut();
if let Err(error) = backend.borrow_mut().dispatch_new_events() { if let Err(error) = backend.0.dispatch_new_events() {
warn!(backend.borrow().logger, "Libinput errored: {}", error); warn!(backend.0.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)
})
} }

View File

@ -2,15 +2,16 @@
use backend::{ use backend::{
graphics::{ graphics::{
egl::{ gl::{GLGraphicsBackend, PixelFormat},
context::GlAttributes, CursorBackend,
error as egl_error, SwapBuffersError,
error::Result as EGLResult, },
native, egl::{
wayland::{EGLDisplay, EGLWaylandExtensions}, context::GlAttributes,
EGLContext, EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError, error as egl_error,
}, error::Result as EGLResult,
GraphicsBackend, native,
EGLDisplay, EGLContext, EGLGraphicsBackend, EGLSurface,
}, },
input::{ input::{
Axis, AxisSource, Event as BackendEvent, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, Axis, AxisSource, Event as BackendEvent, InputBackend, InputHandler, KeyState, KeyboardKeyEvent,
@ -156,12 +157,12 @@ where
let reqs = Default::default(); let reqs = Default::default();
let window = Rc::new( let window = Rc::new(
if native::NativeDisplay::<native::Wayland>::is_backend(&winit_window) { if native::NativeDisplay::<native::Wayland>::is_backend(&winit_window) {
let context = let mut context =
EGLContext::<native::Wayland, WinitWindow>::new(winit_window, attributes, reqs, log.clone())?; EGLContext::<native::Wayland, WinitWindow>::new(winit_window, attributes, reqs, log.clone())?;
let surface = context.create_surface(())?; let surface = context.create_surface(())?;
Window::Wayland { context, surface } Window::Wayland { context, surface }
} else if native::NativeDisplay::<native::X11>::is_backend(&winit_window) { } else if native::NativeDisplay::<native::X11>::is_backend(&winit_window) {
let context = let mut context =
EGLContext::<native::X11, WinitWindow>::new(winit_window, attributes, reqs, log.clone())?; EGLContext::<native::X11, WinitWindow>::new(winit_window, attributes, reqs, log.clone())?;
let surface = context.create_surface(())?; let surface = context.create_surface(())?;
Window::X11 { context, surface } Window::X11 { context, surface }
@ -226,8 +227,8 @@ impl WinitGraphicsBackend {
} }
} }
impl GraphicsBackend for WinitGraphicsBackend { impl<'a> CursorBackend<'a> for WinitGraphicsBackend {
type CursorFormat = MouseCursor; type CursorFormat = &'a MouseCursor;
type Error = (); type Error = ();
fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> { fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> {
@ -240,11 +241,13 @@ impl GraphicsBackend for WinitGraphicsBackend {
}) })
} }
fn set_cursor_representation( fn set_cursor_representation<'b>(
&self, &'b self,
cursor: &Self::CursorFormat, cursor: Self::CursorFormat,
_hotspot: (u32, u32), _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 // Cannot log this one, as `CursorFormat` is not `Debug` and should not be
debug!(self.logger, "Changing cursor representation"); debug!(self.logger, "Changing cursor representation");
self.window.window().set_cursor(*cursor); 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> { fn swap_buffers(&self) -> ::std::result::Result<(), SwapBuffersError> {
trace!(self.logger, "Swapping buffers"); trace!(self.logger, "Swapping buffers");
match *self.window { 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<EGLDisplay> { fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
match *self.window { match *self.window {
Window::Wayland { ref context, .. } => context.bind_wl_display(display), Window::Wayland { ref context, .. } => context.bind_wl_display(display),