smithay/anvil/src/main.rs

83 lines
2.5 KiB
Rust
Raw Normal View History

2018-12-15 20:58:43 +00:00
#![warn(rust_2018_idioms)]
2021-06-23 18:01:28 +00:00
// 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)
)]
2018-12-15 20:58:43 +00:00
#[macro_use]
extern crate slog;
use std::{cell::RefCell, rc::Rc};
use slog::Drain;
use smithay::reexports::{calloop::EventLoop, wayland_server::Display};
mod drawing;
2018-05-13 12:35:27 +00:00
mod input_handler;
mod shell;
mod state;
2018-05-08 17:39:38 +00:00
#[cfg(feature = "udev")]
mod udev;
mod window_map;
#[cfg(feature = "winit")]
mod winit;
#[cfg(feature = "xwayland")]
mod xwayland;
2018-05-08 10:47:09 +00:00
mod output_map;
use state::AnvilState;
static POSSIBLE_BACKENDS: &[&str] = &[
2018-05-08 10:47:09 +00:00
#[cfg(feature = "winit")]
2018-05-08 17:39:38 +00:00
"--winit : Run anvil as a X11 or Wayland client using winit.",
#[cfg(feature = "udev")]
"--tty-udev : Run anvil as a tty udev client (requires root if without logind).",
2018-05-08 10:47:09 +00:00
];
fn main() {
// A logger facility, here we use the terminal here
let log = slog::Logger::root(
slog_async::Async::default(slog_term::term_full().fuse()).fuse(),
//std::sync::Mutex::new(slog_term::term_full().fuse()).fuse(),
o!(),
);
let _guard = slog_scope::set_global_logger(log.clone());
slog_stdlog::init().expect("Could not setup log backend");
2018-06-27 12:04:29 +00:00
let arg = ::std::env::args().nth(1);
2018-05-08 10:47:09 +00:00
match arg.as_ref().map(|s| &s[..]) {
#[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()) {
2018-05-08 10:47:09 +00:00
crit!(log, "Failed to initialize winit backend.");
}
}
2018-05-08 17:39:38 +00:00
#[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()) {
2018-05-08 10:47:09 +00:00
crit!(log, "Failed to initialize tty backend.");
}
}
2021-06-23 18:01:28 +00:00
Some(other) => {
crit!(log, "Unknown backend: {}", other);
}
None => {
2018-05-08 10:47:09 +00:00
println!("USAGE: anvil --backend");
2018-06-27 12:04:29 +00:00
println!();
2018-05-08 10:47:09 +00:00
println!("Possible backends are:");
for b in POSSIBLE_BACKENDS {
println!("\t{}", b);
}
}
}
}