2021-12-15 23:23:49 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2022-07-04 15:29:31 +02:00
|
|
|
use crate::state::{Data, State};
|
2022-07-15 14:21:20 +02:00
|
|
|
use anyhow::{Context, Result};
|
2022-07-04 16:00:29 +02:00
|
|
|
use smithay::reexports::{calloop::EventLoop, wayland_server::DisplayHandle};
|
2021-12-15 23:23:49 +01:00
|
|
|
|
2022-02-04 21:04:17 +01:00
|
|
|
pub mod render;
|
|
|
|
|
|
2022-01-20 19:51:46 +01:00
|
|
|
pub mod kms;
|
2022-01-18 19:42:04 +01:00
|
|
|
pub mod winit;
|
2022-01-18 19:42:56 +01:00
|
|
|
pub mod x11;
|
2021-12-15 23:23:49 +01:00
|
|
|
// TODO
|
|
|
|
|
// pub mod wayland; // tbd in smithay
|
|
|
|
|
|
2022-05-03 13:37:51 +02:00
|
|
|
pub fn init_backend_auto(
|
2022-07-04 15:29:31 +02:00
|
|
|
dh: &DisplayHandle,
|
|
|
|
|
event_loop: &mut EventLoop<'static, Data>,
|
2022-05-03 13:37:51 +02:00
|
|
|
state: &mut State,
|
|
|
|
|
) -> Result<()> {
|
2022-07-15 14:21:20 +02:00
|
|
|
let res = match std::env::var("COSMIC_BACKEND") {
|
2022-07-04 15:29:31 +02:00
|
|
|
Ok(x) if x == "x11" => x11::init_backend(dh, event_loop, state),
|
|
|
|
|
Ok(x) if x == "winit" => winit::init_backend(dh, event_loop, state),
|
|
|
|
|
Ok(x) if x == "kms" => kms::init_backend(dh, event_loop, state),
|
2022-01-18 19:42:04 +01:00
|
|
|
Ok(_) => unimplemented!("There is no backend with this identifier"),
|
2022-01-18 19:42:56 +01:00
|
|
|
Err(_) => {
|
|
|
|
|
if std::env::var_os("DISPLAY").is_some()
|
|
|
|
|
|| std::env::var_os("WAYLAND_DISPLAY").is_some()
|
|
|
|
|
{
|
2022-07-04 15:29:31 +02:00
|
|
|
match x11::init_backend(dh, event_loop, state) {
|
2022-01-18 19:42:56 +01:00
|
|
|
Ok(_) => Ok(()),
|
|
|
|
|
Err(err) => {
|
|
|
|
|
slog_scope::warn!("X11 Backend failed with error: {}", err);
|
|
|
|
|
slog_scope::info!("Falling back to winit backend.");
|
2022-07-04 15:29:31 +02:00
|
|
|
winit::init_backend(dh, event_loop, state)
|
2022-01-18 19:42:56 +01:00
|
|
|
}
|
2022-01-18 19:42:04 +01:00
|
|
|
}
|
2022-01-18 19:42:56 +01:00
|
|
|
} else {
|
2022-07-04 15:29:31 +02:00
|
|
|
kms::init_backend(dh, event_loop, state)
|
2022-01-18 19:42:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-15 14:21:20 +02:00
|
|
|
};
|
2022-09-28 12:01:29 +02:00
|
|
|
|
2022-07-15 14:21:20 +02:00
|
|
|
if res.is_ok() {
|
2022-09-28 12:01:29 +02:00
|
|
|
let output = state
|
|
|
|
|
.common
|
|
|
|
|
.shell
|
|
|
|
|
.outputs()
|
|
|
|
|
.next()
|
|
|
|
|
.with_context(|| "Backend initialized without output")?;
|
|
|
|
|
let initial_seat = crate::input::add_seat(
|
|
|
|
|
dh,
|
|
|
|
|
&mut state.common.seat_state,
|
|
|
|
|
output,
|
|
|
|
|
&state.common.config,
|
|
|
|
|
"seat-0".into(),
|
|
|
|
|
);
|
|
|
|
|
state.common.add_seat(initial_seat);
|
2021-12-15 23:23:49 +01:00
|
|
|
}
|
2022-07-15 14:21:20 +02:00
|
|
|
res
|
2021-12-15 23:23:49 +01:00
|
|
|
}
|