anvil: make into a library+bin crate

This commit is contained in:
Victor Berger 2021-07-08 16:27:12 +02:00 committed by Victor Berger
parent 7e4eff529e
commit 56c3f53575
7 changed files with 63 additions and 72 deletions

View File

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

27
anvil/src/lib.rs Normal file
View File

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

View File

@ -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);

View File

@ -335,7 +335,7 @@ pub fn init_shell<BackendData: 'static>(display: Rc<RefCell<Display>>, 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(),

View File

@ -100,11 +100,10 @@ impl Backend for UdevData {
}
}
pub fn run_udev(
display: Rc<RefCell<Display>>,
event_loop: &mut EventLoop<'static, AnvilState<UdevData>>,
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<SessionFd>;

View File

@ -238,19 +238,13 @@ pub struct Popup {
popup: PopupKind,
}
#[derive(Default)]
pub struct WindowMap {
windows: Vec<Window>,
popups: Vec<Popup>,
}
impl WindowMap {
pub fn new() -> Self {
WindowMap {
windows: Vec::new(),
popups: Vec::new(),
}
}
pub fn insert(&mut self, toplevel: Kind, location: Point<i32, Logical>) {
let mut window = Window {
location,

View File

@ -39,14 +39,17 @@ impl Backend for WinitData {
}
}
pub fn run_winit(
display: Rc<RefCell<Display>>,
event_loop: &mut EventLoop<'static, AnvilState<WinitData>>,
log: Logger,
) -> Result<(), ()> {
let (renderer, mut input) = winit::init(log.clone()).map_err(|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(())
}