jay-compositor 1.15.0

The Jay compositor
use crate::client::Client;
use crate::client::ClientError;
use crate::utils::buffd::MsgParser;
use crate::utils::fuse::fuse_inode::FuseInodeWithKey;
use crate::utils::str_table::StrAccess;
use crate::wire::ObjectId;
use crate::wire::WlDisplayId;
use std::any::Any;
use std::cmp::Ordering;
use std::error::Error;
use std::rc::Rc;
use thiserror::Error;

mod object_dfs_g_fuse;

pub const WL_DISPLAY_ID: WlDisplayId = WlDisplayId::from_raw(1);

pub trait Object: AddObject + BreakLoops + ObjectDebugfs + Any {
    fn id(&self) -> ObjectId;
    fn version(&self) -> Version;
    fn handle_request(
        self: Rc<Self>,
        client: &Client,
        request: u32,
        parser: MsgParser<'_, '_>,
    ) -> Result<(), ClientError>;
    fn interface(&self) -> Interface;
}

pub trait AddObject {
    fn add(self: &Rc<Self>, client: &Client)
    where
        Self: Sized;
    fn remove(&self, client: &Client)
    where
        Self: Sized;
}

pub trait BreakLoops {
    fn break_loops(self: Rc<Self>) {}
}

pub trait ObjectDebugfs {
    fn object_debugfs(self: Rc<Self>, client: &Rc<Client>) -> FuseInodeWithKey;
}

#[derive(Copy, Clone, Debug)]
pub struct Interface(pub StrAccess);

impl Interface {
    pub fn name(self) -> &'static str {
        self.0.get()
    }
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct Version(pub u32);

impl Version {
    pub const ALL: Version = Version(0);
}

impl PartialEq<u32> for Version {
    fn eq(&self, other: &u32) -> bool {
        self.0 == *other
    }
}

impl PartialOrd<u32> for Version {
    fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
        self.0.partial_cmp(other)
    }
}

#[derive(Debug, Error)]
pub enum EventHandlingError {
    #[error("Compositor sent a non-existent event")]
    InvalidMethod,
    #[error("Could not process a `{}#{}.{}` event", .interface.name(), .id, .method)]
    MethodError {
        interface: Interface,
        id: ObjectId,
        method: StrAccess,
        #[source]
        error: Box<dyn Error + 'static>,
    },
}

pub trait SyntheticObjectEventHandler: 'static {
    fn handle_event(
        self: Rc<Self>,
        id: ObjectId,
        event: u32,
        parser: MsgParser<'_, '_>,
    ) -> Result<(), EventHandlingError>;
}