cosmic-comp/src/state.rs

45 lines
1 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
2021-12-17 17:53:01 +01:00
use crate::{backend::x11::X11State, shell::workspaces::Workspaces};
use smithay::reexports::wayland_server::Display;
2021-12-15 23:23:49 +01:00
use std::{cell::RefCell, rc::Rc, time::Instant};
pub struct State {
pub display: Rc<RefCell<Display>>,
2021-12-17 17:53:01 +01:00
pub spaces: Workspaces,
2021-12-15 23:23:49 +01:00
pub start_time: Instant,
pub should_stop: bool,
2021-12-15 23:23:49 +01:00
pub backend: BackendData,
}
pub enum BackendData {
X11(X11State),
// TODO
// Wayland(WaylandState),
// Udev(UdevState),
Unset,
}
impl BackendData {
pub fn x11(&mut self) -> &mut X11State {
match self {
BackendData::X11(ref mut x11_state) => x11_state,
_ => unreachable!("Called x11 in non x11 backend"),
}
}
}
impl State {
pub fn new(display: Display) -> State {
State {
display: Rc::new(RefCell::new(display)),
2021-12-17 17:53:01 +01:00
spaces: Workspaces::new(),
2021-12-15 23:23:49 +01:00
start_time: Instant::now(),
should_stop: false,
2021-12-15 23:23:49 +01:00
backend: BackendData::Unset,
}
}
}