1
0
Fork 0
forked from wry/wry

autocommit 2022-01-02 15:13:33 CET

This commit is contained in:
Julian Orth 2022-01-02 15:13:33 +01:00
commit d6172b273f
50 changed files with 5807 additions and 0 deletions

View file

@ -0,0 +1,111 @@
mod types;
use crate::globals::{Global, GlobalName};
use crate::ifs::wl_surface::WlSurface;
use crate::objects::{Interface, Object, ObjectId};
use crate::utils::buffd::WlParser;
use crate::wl_client::WlClientData;
use std::rc::Rc;
pub use types::*;
use crate::ifs::wl_region::WlRegion;
const CREATE_SURFACE: u32 = 0;
const CREATE_REGION: u32 = 1;
pub struct WlCompositorGlobal {
name: GlobalName,
}
pub struct WlCompositorObj {
global: Rc<WlCompositorGlobal>,
id: ObjectId,
client: Rc<WlClientData>,
version: u32,
}
impl WlCompositorGlobal {
pub fn new(name: GlobalName) -> Self {
Self { name }
}
async fn bind_(
self: Rc<Self>,
id: ObjectId,
client: &Rc<WlClientData>,
version: u32,
) -> Result<(), WlCompositorError> {
let obj = Rc::new(WlCompositorObj {
global: self,
id,
client: client.clone(),
version,
});
client.attach_client_object(obj)?;
Ok(())
}
}
impl WlCompositorObj {
async fn create_surface(&self, parser: WlParser<'_, '_>) -> Result<(), CreateSurfaceError> {
let surface: CreateSurface = self.client.parse(self, parser)?;
let surface = Rc::new(WlSurface::new(surface.id, &self.client));
self.client.attach_client_object(surface)?;
Ok(())
}
async fn create_region(&self, parser: WlParser<'_, '_>) -> Result<(), CreateRegionError> {
let region: CreateRegion = self.client.parse(self, parser)?;
let region = Rc::new(WlRegion::new(region.id, &self.client));
self.client.attach_client_object(region)?;
Ok(())
}
async fn handle_request_(
&self,
request: u32,
parser: WlParser<'_, '_>,
) -> Result<(), WlCompositorError> {
match request {
CREATE_SURFACE => self.create_surface(parser).await?,
CREATE_REGION => self.create_region(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
bind!(WlCompositorGlobal);
impl Global for WlCompositorGlobal {
fn name(&self) -> GlobalName {
self.name
}
fn interface(&self) -> Interface {
Interface::WlCompositor
}
fn version(&self) -> u32 {
4
}
fn pre_remove(&self) {
unreachable!()
}
}
handle_request!(WlCompositorObj);
impl Object for WlCompositorObj {
fn id(&self) -> ObjectId {
self.id
}
fn interface(&self) -> Interface {
Interface::WlCompositor
}
fn num_requests(&self) -> u32 {
CREATE_REGION + 1
}
}

View file

@ -0,0 +1,76 @@
use crate::objects::{ObjectError, ObjectId};
use crate::utils::buffd::{WlParser, WlParserError};
use crate::wl_client::{RequestParser, WlClientError};
use std::fmt::{Debug, Formatter};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum WlCompositorError {
#[error(transparent)]
ObjectError(Box<ObjectError>),
#[error(transparent)]
ClientError(Box<WlClientError>),
#[error("Could not process `create_surface` request")]
CreateSurfaceError(#[source] Box<CreateSurfaceError>),
#[error("Could not process `create_region` request")]
CreateRegionError(#[source] Box<CreateRegionError>),
}
efrom!(WlCompositorError, ObjectError, ObjectError);
efrom!(WlCompositorError, ClientError, WlClientError);
efrom!(WlCompositorError, CreateSurfaceError, CreateSurfaceError);
efrom!(WlCompositorError, CreateRegionError, CreateRegionError);
#[derive(Debug, Error)]
pub enum CreateSurfaceError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<WlParserError>),
#[error(transparent)]
ClientError(Box<WlClientError>),
}
efrom!(CreateSurfaceError, ParseFailed, WlParserError);
efrom!(CreateSurfaceError, ClientError, WlClientError);
#[derive(Debug, Error)]
pub enum CreateRegionError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<WlParserError>),
#[error(transparent)]
ClientError(Box<WlClientError>),
}
efrom!(CreateRegionError, ParseFailed, WlParserError);
efrom!(CreateRegionError, ClientError, WlClientError);
pub(super) struct CreateSurface {
pub id: ObjectId,
}
impl RequestParser<'_> for CreateSurface {
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
Ok(Self {
id: parser.object()?,
})
}
}
impl Debug for CreateSurface {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "create_surface(id: {})", self.id)
}
}
pub(super) struct CreateRegion {
pub id: ObjectId,
}
impl RequestParser<'_> for CreateRegion {
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
Ok(Self {
id: parser.object()?,
})
}
}
impl Debug for CreateRegion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "create_region(id: {})", self.id)
}
}