use crate::async_engine::{AsyncEngine, SpawnedFuture}; use crate::backend::{BackendEvent, OutputId, OutputIds, SeatId, SeatIds}; use crate::client::{Client, Clients}; use crate::cursor::ServerCursors; use crate::event_loop::EventLoop; use crate::globals::{GlobalsError, Globals, WaylandGlobal}; use crate::ifs::wl_output::WlOutputGlobal; use crate::ifs::wl_seat::WlSeatGlobal; use crate::ifs::wl_surface::NoneSurfaceExt; use crate::render::RenderContext; use crate::tree::{DisplayNode, NodeIds}; use crate::utils::asyncevent::AsyncEvent; use crate::utils::clonecell::CloneCell; use crate::utils::copyhashmap::CopyHashMap; use crate::utils::linkedlist::LinkedList; use crate::utils::numcell::NumCell; use crate::utils::queue::AsyncQueue; use crate::{ErrorFmt, Wheel}; use ahash::AHashMap; use std::cell::{Cell, RefCell}; use std::rc::Rc; pub struct State { pub eng: Rc, pub el: Rc, pub render_ctx: CloneCell>>, pub cursors: CloneCell>>, pub wheel: Rc, pub clients: Clients, pub next_name: NumCell, pub globals: Globals, pub output_ids: OutputIds, pub seat_ids: SeatIds, pub node_ids: NodeIds, pub root: Rc, pub backend_events: AsyncQueue, pub output_handlers: RefCell>>, pub seats: RefCell>, pub outputs: CopyHashMap>, pub seat_queue: LinkedList>, pub slow_clients: AsyncQueue>, pub none_surface_ext: Rc, pub tree_changed_sent: Cell, } pub struct SeatData { pub handler: SpawnedFuture<()>, pub tree_changed: Rc, } impl State { pub fn set_render_ctx(&self, ctx: &Rc) { let cursors = match ServerCursors::load(ctx) { Ok(c) => Some(Rc::new(c)), Err(e) => { log::error!("Could not load the cursors: {}", ErrorFmt(e)); None } }; self.cursors.set(cursors); self.render_ctx.set(Some(ctx.clone())); } pub fn add_global(&self, global: &Rc) { self.globals.add_global(self, global) } pub fn remove_global(&self, global: &T) -> Result<(), GlobalsError> { self.globals.remove(self, global) } pub fn tree_changed(&self) { if self.tree_changed_sent.replace(true) { return; } let seats = self.seats.borrow(); for seat in seats.values() { seat.tree_changed.trigger(); } } }