2018-12-15 20:58:43 +00:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
2018-05-07 17:56:38 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate glium;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate slog;
|
|
|
|
#[macro_use(define_roles)]
|
|
|
|
extern crate smithay;
|
|
|
|
|
2020-04-17 16:27:26 +00:00
|
|
|
use std::{
|
|
|
|
cell::RefCell,
|
|
|
|
rc::Rc,
|
|
|
|
sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-05-07 17:56:38 +00:00
|
|
|
use slog::Drain;
|
2020-04-10 15:01:49 +00:00
|
|
|
use smithay::reexports::{
|
|
|
|
calloop::{generic::Generic, mio::Interest, EventLoop},
|
|
|
|
wayland_server::Display,
|
|
|
|
};
|
2018-05-07 17:56:38 +00:00
|
|
|
|
2018-05-19 17:51:26 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod shaders;
|
2020-02-03 05:40:25 +00:00
|
|
|
mod buffer_utils;
|
2018-05-07 17:56:38 +00:00
|
|
|
mod glium_drawer;
|
2018-05-13 12:35:27 +00:00
|
|
|
mod input_handler;
|
2018-05-07 17:56:38 +00:00
|
|
|
mod shell;
|
2018-05-13 12:35:27 +00:00
|
|
|
mod shm_load;
|
2018-05-08 17:39:38 +00:00
|
|
|
#[cfg(feature = "udev")]
|
2018-05-07 17:56:38 +00:00
|
|
|
mod udev;
|
|
|
|
mod window_map;
|
|
|
|
#[cfg(feature = "winit")]
|
|
|
|
mod winit;
|
2018-05-08 10:47:09 +00:00
|
|
|
|
2020-01-01 10:43:16 +00:00
|
|
|
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
|
|
|
];
|
2018-05-07 17:56:38 +00:00
|
|
|
|
2020-04-05 17:01:08 +00:00
|
|
|
pub struct AnvilState {
|
2020-04-17 16:27:26 +00:00
|
|
|
pub running: Arc<AtomicBool>,
|
2020-04-05 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for AnvilState {
|
|
|
|
fn default() -> AnvilState {
|
|
|
|
AnvilState {
|
2020-04-17 16:27:26 +00:00
|
|
|
running: Arc::new(AtomicBool::new(true)),
|
2020-04-05 17:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 17:56:38 +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(),
|
|
|
|
o!(),
|
|
|
|
);
|
|
|
|
|
2020-04-17 16:27:26 +00:00
|
|
|
let event_loop = EventLoop::<AnvilState>::new().unwrap();
|
|
|
|
let display = Rc::new(RefCell::new(Display::new()));
|
2020-04-05 17:01:08 +00:00
|
|
|
|
|
|
|
// Glue for event dispatching
|
2020-04-17 16:27:26 +00:00
|
|
|
let mut wayland_event_source = Generic::from_raw_fd(display.borrow().get_poll_fd());
|
2020-04-05 17:01:08 +00:00
|
|
|
wayland_event_source.set_interest(Interest::READABLE);
|
2020-04-17 16:27:26 +00:00
|
|
|
let _wayland_source = event_loop.handle().insert_source(wayland_event_source, {
|
|
|
|
let display = display.clone();
|
|
|
|
let log = log.clone();
|
|
|
|
move |_, state: &mut AnvilState| {
|
|
|
|
let mut display = display.borrow_mut();
|
|
|
|
match display.dispatch(std::time::Duration::from_millis(0), state) {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(e) => {
|
|
|
|
error!(log, "I/O error on the Wayland display: {}", e);
|
|
|
|
state.running.store(false, Ordering::SeqCst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-05-07 17:56:38 +00:00
|
|
|
|
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");
|
2020-04-17 16:27:26 +00:00
|
|
|
if let Err(()) = winit::run_winit(display, event_loop, log.clone()) {
|
2018-05-08 10:47:09 +00:00
|
|
|
crit!(log, "Failed to initialize winit backend.");
|
|
|
|
}
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
2018-05-08 17:39:38 +00:00
|
|
|
#[cfg(feature = "udev")]
|
|
|
|
Some("--tty-udev") => {
|
|
|
|
info!(log, "Starting anvil on a tty using udev");
|
2018-05-08 10:47:09 +00:00
|
|
|
if let Err(()) = udev::run_udev(display, event_loop, log.clone()) {
|
|
|
|
crit!(log, "Failed to initialize tty backend.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
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);
|
|
|
|
}
|
2018-05-07 17:56:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|