anvil: make into a library+bin crate
This commit is contained in:
parent
7e4eff529e
commit
56c3f53575
|
@ -24,7 +24,7 @@ xkbcommon = "0.4.0"
|
||||||
[dependencies.smithay]
|
[dependencies.smithay]
|
||||||
path = ".."
|
path = ".."
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [ "renderer_gl", "backend_egl", "wayland_frontend", "slog-stdlog" ]
|
features = [ "wayland_frontend", "slog-stdlog" ]
|
||||||
|
|
||||||
[dependencies.x11rb]
|
[dependencies.x11rb]
|
||||||
optional = true
|
optional = true
|
||||||
|
@ -39,7 +39,7 @@ gl_generator = "0.14"
|
||||||
default = [ "winit", "udev", "logind", "egl", "xwayland" ]
|
default = [ "winit", "udev", "logind", "egl", "xwayland" ]
|
||||||
egl = [ "smithay/use_system_lib", "smithay/backend_egl" ]
|
egl = [ "smithay/use_system_lib", "smithay/backend_egl" ]
|
||||||
winit = [ "smithay/backend_winit" ]
|
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" ]
|
logind = [ "smithay/backend_session_logind" ]
|
||||||
elogind = ["logind", "smithay/backend_session_elogind" ]
|
elogind = ["logind", "smithay/backend_session_elogind" ]
|
||||||
libseat = ["smithay/backend_session_libseat" ]
|
libseat = ["smithay/backend_session_libseat" ]
|
||||||
|
|
|
@ -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;
|
|
@ -1,36 +1,4 @@
|
||||||
#![warn(rust_2018_idioms)]
|
use slog::{crit, info, o, Drain};
|
||||||
// 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;
|
|
||||||
|
|
||||||
static POSSIBLE_BACKENDS: &[&str] = &[
|
static POSSIBLE_BACKENDS: &[&str] = &[
|
||||||
#[cfg(feature = "winit")]
|
#[cfg(feature = "winit")]
|
||||||
|
@ -54,20 +22,12 @@ fn main() {
|
||||||
#[cfg(feature = "winit")]
|
#[cfg(feature = "winit")]
|
||||||
Some("--winit") => {
|
Some("--winit") => {
|
||||||
info!(log, "Starting anvil with winit backend");
|
info!(log, "Starting anvil with winit backend");
|
||||||
let mut event_loop = EventLoop::try_new().unwrap();
|
anvil::winit::run_winit(log);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[cfg(feature = "udev")]
|
#[cfg(feature = "udev")]
|
||||||
Some("--tty-udev") => {
|
Some("--tty-udev") => {
|
||||||
info!(log, "Starting anvil on a tty using udev");
|
info!(log, "Starting anvil on a tty using udev");
|
||||||
let mut event_loop = EventLoop::try_new().unwrap();
|
anvil::udev::run_udev(log);
|
||||||
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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(other) => {
|
Some(other) => {
|
||||||
crit!(log, "Unknown backend: {}", other);
|
crit!(log, "Unknown backend: {}", other);
|
||||||
|
|
|
@ -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
|
// 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(
|
let output_map = Rc::new(RefCell::new(OutputMap::new(
|
||||||
display.clone(),
|
display.clone(),
|
||||||
window_map.clone(),
|
window_map.clone(),
|
||||||
|
|
|
@ -100,11 +100,10 @@ impl Backend for UdevData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_udev(
|
pub fn run_udev(log: Logger) {
|
||||||
display: Rc<RefCell<Display>>,
|
let mut event_loop = EventLoop::try_new().unwrap();
|
||||||
event_loop: &mut EventLoop<'static, AnvilState<UdevData>>,
|
let display = Rc::new(RefCell::new(Display::new()));
|
||||||
log: Logger,
|
|
||||||
) -> Result<(), ()> {
|
|
||||||
let name = display
|
let name = display
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.add_socket_auto()
|
.add_socket_auto()
|
||||||
|
@ -116,7 +115,13 @@ pub fn run_udev(
|
||||||
/*
|
/*
|
||||||
* Initialize session
|
* 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();
|
let session_signal = notifier.signaler();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -150,7 +155,13 @@ pub fn run_udev(
|
||||||
/*
|
/*
|
||||||
* Initialize the udev backend
|
* 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)
|
* 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(session_event_source);
|
||||||
event_loop.handle().remove(libinput_event_source);
|
event_loop.handle().remove(libinput_event_source);
|
||||||
event_loop.handle().remove(udev_event_source);
|
event_loop.handle().remove(udev_event_source);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type RenderSurface = GbmBufferedSurface<SessionFd>;
|
pub type RenderSurface = GbmBufferedSurface<SessionFd>;
|
||||||
|
|
|
@ -238,19 +238,13 @@ pub struct Popup {
|
||||||
popup: PopupKind,
|
popup: PopupKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct WindowMap {
|
pub struct WindowMap {
|
||||||
windows: Vec<Window>,
|
windows: Vec<Window>,
|
||||||
popups: Vec<Popup>,
|
popups: Vec<Popup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowMap {
|
impl WindowMap {
|
||||||
pub fn new() -> Self {
|
|
||||||
WindowMap {
|
|
||||||
windows: Vec::new(),
|
|
||||||
popups: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, toplevel: Kind, location: Point<i32, Logical>) {
|
pub fn insert(&mut self, toplevel: Kind, location: Point<i32, Logical>) {
|
||||||
let mut window = Window {
|
let mut window = Window {
|
||||||
location,
|
location,
|
||||||
|
|
|
@ -39,14 +39,17 @@ impl Backend for WinitData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_winit(
|
pub fn run_winit(log: Logger) {
|
||||||
display: Rc<RefCell<Display>>,
|
let mut event_loop = EventLoop::try_new().unwrap();
|
||||||
event_loop: &mut EventLoop<'static, AnvilState<WinitData>>,
|
let display = Rc::new(RefCell::new(Display::new()));
|
||||||
log: Logger,
|
|
||||||
) -> Result<(), ()> {
|
let (renderer, mut input) = match winit::init(log.clone()) {
|
||||||
let (renderer, mut input) = winit::init(log.clone()).map_err(|err| {
|
Ok(ret) => ret,
|
||||||
|
Err(err) => {
|
||||||
slog::crit!(log, "Failed to initialize Winit backend: {}", err);
|
slog::crit!(log, "Failed to initialize Winit backend: {}", err);
|
||||||
})?;
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
let renderer = Rc::new(RefCell::new(renderer));
|
let renderer = Rc::new(RefCell::new(renderer));
|
||||||
|
|
||||||
#[cfg(feature = "egl")]
|
#[cfg(feature = "egl")]
|
||||||
|
@ -245,6 +248,4 @@ pub fn run_winit(
|
||||||
|
|
||||||
// Cleanup stuff
|
// Cleanup stuff
|
||||||
state.window_map.borrow_mut().clear();
|
state.window_map.borrow_mut().clear();
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue