diff --git a/anvil/Cargo.toml b/anvil/Cargo.toml index 4bb079f..4dacbcf 100644 --- a/anvil/Cargo.toml +++ b/anvil/Cargo.toml @@ -24,7 +24,7 @@ xkbcommon = "0.4.0" [dependencies.smithay] path = ".." default-features = false -features = [ "renderer_gl", "backend_egl", "wayland_frontend", "slog-stdlog" ] +features = [ "wayland_frontend", "slog-stdlog" ] [dependencies.x11rb] optional = true @@ -39,7 +39,7 @@ gl_generator = "0.14" default = [ "winit", "udev", "logind", "egl", "xwayland" ] egl = [ "smithay/use_system_lib", "smithay/backend_egl" ] winit = [ "smithay/backend_winit" ] -udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm", "smithay/backend_gbm", "smithay/backend_egl", "smithay/backend_session", "input", "image", "xcursor" ] +udev = [ "smithay/backend_libinput", "smithay/backend_udev", "smithay/backend_drm", "smithay/backend_gbm", "smithay/backend_egl", "smithay/backend_session", "input", "image", "smithay/renderer_gl", "xcursor" ] logind = [ "smithay/backend_session_logind" ] elogind = ["logind", "smithay/backend_session_elogind" ] libseat = ["smithay/backend_session_libseat" ] diff --git a/anvil/src/lib.rs b/anvil/src/lib.rs new file mode 100644 index 0000000..5a1d98a --- /dev/null +++ b/anvil/src/lib.rs @@ -0,0 +1,27 @@ +#![warn(rust_2018_idioms)] +// If no backend is enabled, a large portion of the codebase is unused. +// So silence this useless warning for the CI. +#![cfg_attr( + not(any(feature = "winit", feature = "udev")), + allow(dead_code, unused_imports) +)] + +#[macro_use] +extern crate slog; + +#[cfg(feature = "udev")] +pub mod cursor; +pub mod drawing; +pub mod input_handler; +pub mod output_map; +pub mod shell; +pub mod state; +#[cfg(feature = "udev")] +pub mod udev; +pub mod window_map; +#[cfg(feature = "winit")] +pub mod winit; +#[cfg(feature = "xwayland")] +pub mod xwayland; + +pub use state::AnvilState; diff --git a/anvil/src/main.rs b/anvil/src/main.rs index 34f1e88..b1ab5e6 100644 --- a/anvil/src/main.rs +++ b/anvil/src/main.rs @@ -1,36 +1,4 @@ -#![warn(rust_2018_idioms)] -// If no backend is enabled, a large portion of the codebase is unused. -// So silence this useless warning for the CI. -#![cfg_attr( - not(any(feature = "winit", feature = "udev")), - allow(dead_code, unused_imports) -)] - -#[macro_use] -extern crate slog; - -use std::{cell::RefCell, rc::Rc}; - -use slog::Drain; -use smithay::reexports::{calloop::EventLoop, wayland_server::Display}; - -#[cfg(feature = "udev")] -mod cursor; -mod drawing; -mod input_handler; -mod shell; -mod state; -#[cfg(feature = "udev")] -mod udev; -mod window_map; -#[cfg(feature = "winit")] -mod winit; -#[cfg(feature = "xwayland")] -mod xwayland; - -mod output_map; - -use state::AnvilState; +use slog::{crit, info, o, Drain}; static POSSIBLE_BACKENDS: &[&str] = &[ #[cfg(feature = "winit")] @@ -54,20 +22,12 @@ fn main() { #[cfg(feature = "winit")] Some("--winit") => { info!(log, "Starting anvil with winit backend"); - let mut event_loop = EventLoop::try_new().unwrap(); - let display = Rc::new(RefCell::new(Display::new())); - if let Err(()) = winit::run_winit(display, &mut event_loop, log.clone()) { - crit!(log, "Failed to initialize winit backend."); - } + anvil::winit::run_winit(log); } #[cfg(feature = "udev")] Some("--tty-udev") => { info!(log, "Starting anvil on a tty using udev"); - let mut event_loop = EventLoop::try_new().unwrap(); - let display = Rc::new(RefCell::new(Display::new())); - if let Err(()) = udev::run_udev(display, &mut event_loop, log.clone()) { - crit!(log, "Failed to initialize tty backend."); - } + anvil::udev::run_udev(log); } Some(other) => { crit!(log, "Unknown backend: {}", other); diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 667b4d2..7191e9f 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -335,7 +335,7 @@ pub fn init_shell(display: Rc>, log: ::sl ); // Init a window map, to track the location of our windows - let window_map = Rc::new(RefCell::new(WindowMap::new())); + let window_map = Rc::new(RefCell::new(WindowMap::default())); let output_map = Rc::new(RefCell::new(OutputMap::new( display.clone(), window_map.clone(), diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index d1ad5d6..7049661 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -100,11 +100,10 @@ impl Backend for UdevData { } } -pub fn run_udev( - display: Rc>, - event_loop: &mut EventLoop<'static, AnvilState>, - log: Logger, -) -> Result<(), ()> { +pub fn run_udev(log: Logger) { + let mut event_loop = EventLoop::try_new().unwrap(); + let display = Rc::new(RefCell::new(Display::new())); + let name = display .borrow_mut() .add_socket_auto() @@ -116,7 +115,13 @@ pub fn run_udev( /* * Initialize session */ - let (session, notifier) = AutoSession::new(log.clone()).ok_or(())?; + let (session, notifier) = match AutoSession::new(log.clone()) { + Some(ret) => ret, + None => { + crit!(log, "Could not initialize a session"); + return; + } + }; let session_signal = notifier.signaler(); /* @@ -150,7 +155,13 @@ pub fn run_udev( /* * Initialize the udev backend */ - let udev_backend = UdevBackend::new(state.seat_name.clone(), log.clone()).map_err(|_| ())?; + let udev_backend = match UdevBackend::new(state.seat_name.clone(), log.clone()) { + Ok(ret) => ret, + Err(err) => { + crit!(log, "Failed to initialize udev backend"; "error" => err); + return; + } + }; /* * Initialize a fake output (we render one screen to every device in this example) @@ -248,8 +259,6 @@ pub fn run_udev( event_loop.handle().remove(session_event_source); event_loop.handle().remove(libinput_event_source); event_loop.handle().remove(udev_event_source); - - Ok(()) } pub type RenderSurface = GbmBufferedSurface; diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index 6f70ae3..08216c4 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -238,19 +238,13 @@ pub struct Popup { popup: PopupKind, } +#[derive(Default)] pub struct WindowMap { windows: Vec, popups: Vec, } impl WindowMap { - pub fn new() -> Self { - WindowMap { - windows: Vec::new(), - popups: Vec::new(), - } - } - pub fn insert(&mut self, toplevel: Kind, location: Point) { let mut window = Window { location, diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index dfe38a7..72c6a3b 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -39,14 +39,17 @@ impl Backend for WinitData { } } -pub fn run_winit( - display: Rc>, - event_loop: &mut EventLoop<'static, AnvilState>, - log: Logger, -) -> Result<(), ()> { - let (renderer, mut input) = winit::init(log.clone()).map_err(|err| { - slog::crit!(log, "Failed to initialize Winit backend: {}", err); - })?; +pub fn run_winit(log: Logger) { + let mut event_loop = EventLoop::try_new().unwrap(); + let display = Rc::new(RefCell::new(Display::new())); + + let (renderer, mut input) = match winit::init(log.clone()) { + Ok(ret) => ret, + Err(err) => { + slog::crit!(log, "Failed to initialize Winit backend: {}", err); + return; + } + }; let renderer = Rc::new(RefCell::new(renderer)); #[cfg(feature = "egl")] @@ -245,6 +248,4 @@ pub fn run_winit( // Cleanup stuff state.window_map.borrow_mut().clear(); - - Ok(()) }