use crate::async_engine::{AsyncEngine, SpawnedFuture}; use crate::backend::{ Backend, BackendEvent, Keyboard, KeyboardId, KeyboardIds, MouseId, MouseIds, OutputId, OutputIds, }; use crate::client::{Client, Clients}; use crate::config::ConfigProxy; use crate::cursor::ServerCursors; use crate::event_loop::EventLoop; use crate::forker::ForkerProxy; use crate::globals::{Globals, GlobalsError, WaylandGlobal}; use crate::ifs::wl_output::WlOutputGlobal; use crate::ifs::wl_seat::{SeatIds, WlSeatGlobal}; use crate::ifs::wl_surface::NoneSurfaceExt; use crate::render::RenderContext; use crate::theme::Theme; use crate::tree::{ContainerNode, DisplayNode, NodeIds}; 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::xkbcommon::XkbKeymap; use crate::{ErrorFmt, Wheel, XkbContext}; use ahash::AHashMap; use std::cell::{Cell, RefCell}; use std::rc::Rc; pub struct State { pub xkb_ctx: XkbContext, pub forker: CloneCell>>, pub backend: CloneCell>, pub default_keymap: Rc, 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 kb_ids: KeyboardIds, pub mouse_ids: MouseIds, pub node_ids: NodeIds, pub root: Rc, pub backend_events: AsyncQueue, pub output_handlers: RefCell>>, pub mouse_handlers: RefCell>, pub kb_handlers: RefCell>, pub outputs: CopyHashMap>, pub seat_queue: LinkedList>, pub slow_clients: AsyncQueue>, pub none_surface_ext: Rc, pub tree_changed_sent: Cell, pub config: CloneCell>>, pub theme: Theme, pub pending_container_layout: AsyncQueue>, pub pending_container_titles: AsyncQueue>, } pub struct MouseData { pub handler: SpawnedFuture<()>, pub id: MouseId, pub data: Rc, } pub struct KeyboardData { pub handler: SpawnedFuture<()>, pub id: KeyboardId, pub kb: Rc, pub data: Rc, } pub struct DeviceHandlerData { pub seat: CloneCell>>, } 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.globals.seats.lock(); for seat in seats.values() { seat.trigger_tree_changed(); } } }