2021-12-15 23:23:49 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2023-09-29 21:33:16 +02:00
|
|
|
use crate::state::State;
|
2025-02-12 05:35:22 -08:00
|
|
|
use anyhow::{anyhow, Context, Result};
|
|
|
|
|
use cosmic_comp_config::NumlockState;
|
2022-07-04 16:00:29 +02:00
|
|
|
use smithay::reexports::{calloop::EventLoop, wayland_server::DisplayHandle};
|
2023-02-24 17:41:52 +01:00
|
|
|
use tracing::{info, warn};
|
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,
|
2023-09-29 21:33:16 +02:00
|
|
|
event_loop: &mut EventLoop<'static, State>,
|
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) => {
|
2023-02-24 17:41:52 +01:00
|
|
|
warn!(?err, "Initializing X11 Backend failed.");
|
|
|
|
|
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
|
2024-04-10 15:49:08 +02:00
|
|
|
.read()
|
2022-09-28 12:01:29 +02:00
|
|
|
.outputs()
|
|
|
|
|
.next()
|
2024-04-10 15:49:08 +02:00
|
|
|
.with_context(|| "Backend initialized without output")
|
|
|
|
|
.cloned()?;
|
2024-04-05 13:53:35 +02:00
|
|
|
let initial_seat = crate::shell::create_seat(
|
2022-09-28 12:01:29 +02:00
|
|
|
dh,
|
|
|
|
|
&mut state.common.seat_state,
|
2024-04-10 15:49:08 +02:00
|
|
|
&output,
|
2022-09-28 12:01:29 +02:00
|
|
|
&state.common.config,
|
|
|
|
|
"seat-0".into(),
|
|
|
|
|
);
|
2025-02-12 05:35:22 -08:00
|
|
|
|
|
|
|
|
let keyboard = initial_seat
|
|
|
|
|
.get_keyboard()
|
|
|
|
|
.ok_or_else(|| anyhow!("`shell::create_seat` did not setup keyboard"))?;
|
|
|
|
|
|
2024-04-10 15:49:08 +02:00
|
|
|
state
|
|
|
|
|
.common
|
|
|
|
|
.shell
|
|
|
|
|
.write()
|
|
|
|
|
.seats
|
2025-02-14 19:14:43 +01:00
|
|
|
.add_seat(initial_seat.clone());
|
|
|
|
|
|
|
|
|
|
if state
|
|
|
|
|
.common
|
|
|
|
|
.config
|
|
|
|
|
.cosmic_conf
|
|
|
|
|
.accessibility_zoom
|
|
|
|
|
.start_on_login
|
|
|
|
|
{
|
2025-05-20 17:41:27 +02:00
|
|
|
state.common.shell.write().trigger_zoom(
|
2025-03-25 17:31:48 +01:00
|
|
|
&initial_seat,
|
|
|
|
|
None,
|
|
|
|
|
1.0 + (state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.),
|
|
|
|
|
&state.common.config.cosmic_conf.accessibility_zoom,
|
|
|
|
|
true,
|
|
|
|
|
&state.common.event_loop_handle,
|
|
|
|
|
);
|
2025-02-14 19:14:43 +01:00
|
|
|
}
|
2024-06-07 19:10:13 +02:00
|
|
|
|
2025-02-12 05:35:22 -08:00
|
|
|
let desired_numlock = state
|
|
|
|
|
.common
|
|
|
|
|
.config
|
|
|
|
|
.cosmic_conf
|
|
|
|
|
.keyboard_config
|
|
|
|
|
.numlock_state;
|
|
|
|
|
// Restore numlock state based on config.
|
|
|
|
|
let toggle_numlock = match desired_numlock {
|
|
|
|
|
NumlockState::BootOff => keyboard.modifier_state().num_lock,
|
|
|
|
|
NumlockState::BootOn => !keyboard.modifier_state().num_lock,
|
|
|
|
|
NumlockState::LastBoot => {
|
|
|
|
|
keyboard.modifier_state().num_lock
|
|
|
|
|
!= state.common.config.dynamic_conf.numlock().last_state
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// If we're enabling numlock...
|
|
|
|
|
if toggle_numlock {
|
|
|
|
|
/// Linux scancode for numlock key.
|
|
|
|
|
const NUMLOCK_SCANCODE: u32 = 69;
|
2025-02-12 12:13:54 +02:00
|
|
|
crate::config::change_modifier_state(&keyboard, NUMLOCK_SCANCODE, state);
|
2025-02-12 05:35:22 -08:00
|
|
|
}
|
2024-06-07 19:10:13 +02:00
|
|
|
{
|
|
|
|
|
{
|
2024-06-11 17:24:46 +02:00
|
|
|
state
|
|
|
|
|
.common
|
|
|
|
|
.startup_done
|
|
|
|
|
.store(true, std::sync::atomic::Ordering::SeqCst);
|
2025-05-20 17:41:27 +02:00
|
|
|
for output in state.common.shell.read().outputs() {
|
2024-06-11 17:24:46 +02:00
|
|
|
state.backend.schedule_render(&output);
|
|
|
|
|
}
|
2024-06-07 19:10:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|