autocommit 2022-01-02 15:13:33 CET
This commit is contained in:
commit
d6172b273f
50 changed files with 5807 additions and 0 deletions
10
src/ifs/mod.rs
Normal file
10
src/ifs/mod.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
pub mod wl_callback;
|
||||
pub mod wl_compositor;
|
||||
pub mod wl_display;
|
||||
pub mod wl_region;
|
||||
pub mod wl_registry;
|
||||
pub mod wl_shm;
|
||||
pub mod wl_shm_pool;
|
||||
pub mod wl_subcompositor;
|
||||
pub mod wl_surface;
|
||||
pub mod xdg_wm_base;
|
||||
47
src/ifs/wl_callback/mod.rs
Normal file
47
src/ifs/wl_callback/mod.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
mod types;
|
||||
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::DynEventFormatter;
|
||||
use std::rc::Rc;
|
||||
use types::*;
|
||||
|
||||
const DONE: u32 = 0;
|
||||
|
||||
pub struct WlCallback {
|
||||
id: ObjectId,
|
||||
}
|
||||
|
||||
impl WlCallback {
|
||||
pub fn new(id: ObjectId) -> Self {
|
||||
Self { id }
|
||||
}
|
||||
|
||||
pub fn done(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(Done { obj: self.clone() })
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
_request: u32,
|
||||
_parser: WlParser<'_, '_>,
|
||||
) -> Result<(), ObjectError> {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlCallback);
|
||||
|
||||
impl Object for WlCallback {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlCallback
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
23
src/ifs/wl_callback/types.rs
Normal file
23
src/ifs/wl_callback/types.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use crate::ifs::wl_callback::{WlCallback, DONE};
|
||||
use crate::objects::Object;
|
||||
use crate::utils::buffd::WlFormatter;
|
||||
use crate::wl_client::EventFormatter;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub(super) struct Done {
|
||||
pub obj: Rc<WlCallback>,
|
||||
}
|
||||
impl EventFormatter for Done {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, DONE).uint(0);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for Done {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "done(callback_data: 0)")
|
||||
}
|
||||
}
|
||||
111
src/ifs/wl_compositor/mod.rs
Normal file
111
src/ifs/wl_compositor/mod.rs
Normal 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
|
||||
}
|
||||
}
|
||||
76
src/ifs/wl_compositor/types.rs
Normal file
76
src/ifs/wl_compositor/types.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
130
src/ifs/wl_display/mod.rs
Normal file
130
src/ifs/wl_display/mod.rs
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_callback::WlCallback;
|
||||
use crate::ifs::wl_registry::WlRegistry;
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId, WL_DISPLAY_ID};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::{DynEventFormatter, WlClientData};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const SYNC: u32 = 0;
|
||||
const GET_REGISTRY: u32 = 1;
|
||||
|
||||
const ERROR: u32 = 0;
|
||||
const DELETE_ID: u32 = 1;
|
||||
|
||||
const INVALID_OBJECT: u32 = 0;
|
||||
const INVALID_METHOD: u32 = 1;
|
||||
const NO_MEMORY: u32 = 2;
|
||||
const IMPLEMENTATION: u32 = 3;
|
||||
|
||||
pub struct WlDisplay {
|
||||
client: Rc<WlClientData>,
|
||||
}
|
||||
|
||||
impl WlDisplay {
|
||||
pub fn new(client: &Rc<WlClientData>) -> Self {
|
||||
Self {
|
||||
client: client.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlDisplayError> {
|
||||
match request {
|
||||
SYNC => self.sync(parser).await?,
|
||||
GET_REGISTRY => self.get_registry(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn sync(&self, parser: WlParser<'_, '_>) -> Result<(), SyncError> {
|
||||
let sync: Sync = self.client.parse(self, parser)?;
|
||||
let cb = Rc::new(WlCallback::new(sync.callback));
|
||||
self.client.attach_client_object(cb.clone())?;
|
||||
self.client.event(cb.done()).await?;
|
||||
self.client
|
||||
.objects
|
||||
.remove_obj(&self.client, cb.id())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_registry(&self, parser: WlParser<'_, '_>) -> Result<(), GetRegistryError> {
|
||||
let gr: GetRegistry = self.client.parse(self, parser)?;
|
||||
let registry = Rc::new(WlRegistry::new(gr.registry, &self.client));
|
||||
self.client.attach_client_object(registry.clone())?;
|
||||
self.client
|
||||
.state
|
||||
.globals
|
||||
.notify_all(&self.client, ®istry)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn error(
|
||||
self: &Rc<Self>,
|
||||
object_id: ObjectId,
|
||||
code: u32,
|
||||
message: String,
|
||||
) -> DynEventFormatter {
|
||||
Box::new(Error {
|
||||
obj: self.clone(),
|
||||
object_id,
|
||||
code,
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn invalid_request(self: &Rc<Self>, obj: &dyn Object, request: u32) -> DynEventFormatter {
|
||||
let id = obj.id();
|
||||
let msg = format!(
|
||||
"Object {} of type {} has no method {}",
|
||||
id,
|
||||
obj.interface().name(),
|
||||
request
|
||||
);
|
||||
self.error(id, INVALID_METHOD, msg)
|
||||
}
|
||||
|
||||
pub fn invalid_object(self: &Rc<Self>, id: ObjectId) -> DynEventFormatter {
|
||||
let msg = format!("Object {} does not exist", id,);
|
||||
self.error(id, INVALID_OBJECT, msg)
|
||||
}
|
||||
|
||||
pub fn implementation_error(self: &Rc<Self>, msg: String) -> DynEventFormatter {
|
||||
self.error(WL_DISPLAY_ID, IMPLEMENTATION, msg)
|
||||
}
|
||||
|
||||
pub fn delete_id(self: &Rc<Self>, id: ObjectId) -> DynEventFormatter {
|
||||
Box::new(DeleteId {
|
||||
obj: self.clone(),
|
||||
id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlDisplay);
|
||||
|
||||
impl Object for WlDisplay {
|
||||
fn id(&self) -> ObjectId {
|
||||
WL_DISPLAY_ID
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlDisplay
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
GET_REGISTRY + 1
|
||||
}
|
||||
|
||||
fn into_display(self: Rc<Self>) -> Result<Rc<WlDisplay>, ObjectError> {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
127
src/ifs/wl_display/types.rs
Normal file
127
src/ifs/wl_display/types.rs
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
use crate::globals::GlobalError;
|
||||
use crate::ifs::wl_display::{WlDisplay, DELETE_ID, ERROR};
|
||||
use crate::objects::{Object, ObjectError, ObjectId, WL_DISPLAY_ID};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::wl_client::{EventFormatter, RequestParser, WlClientError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlDisplayError {
|
||||
#[error("Could not process a get_registry request")]
|
||||
GetRegistry(#[source] Box<GetRegistryError>),
|
||||
#[error("A client error occurred")]
|
||||
SyncError(#[source] Box<SyncError>),
|
||||
}
|
||||
|
||||
efrom!(WlDisplayError, GetRegistry, GetRegistryError);
|
||||
efrom!(WlDisplayError, SyncError, SyncError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetRegistryError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error("An object error occurred")]
|
||||
ObjectError(#[source] Box<ObjectError>),
|
||||
#[error("An object error occurred")]
|
||||
ClientError(#[source] Box<WlClientError>),
|
||||
#[error("An error occurred while processing globals")]
|
||||
GlobalError(#[source] Box<GlobalError>),
|
||||
}
|
||||
|
||||
efrom!(GetRegistryError, ParseFailed, WlParserError);
|
||||
efrom!(GetRegistryError, ObjectError, ObjectError);
|
||||
efrom!(GetRegistryError, GlobalError, GlobalError);
|
||||
efrom!(GetRegistryError, ClientError, WlClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SyncError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error("An object error occurred")]
|
||||
ObjectError(#[source] Box<ObjectError>),
|
||||
#[error("A client error occurred")]
|
||||
ClientError(#[source] Box<WlClientError>),
|
||||
}
|
||||
|
||||
efrom!(SyncError, ParseFailed, WlParserError);
|
||||
efrom!(SyncError, ObjectError, ObjectError);
|
||||
efrom!(SyncError, ClientError, WlClientError);
|
||||
|
||||
pub(super) struct GetRegistry {
|
||||
pub registry: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for GetRegistry {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
registry: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetRegistry {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "get_registry(registry: {})", self.registry)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Sync {
|
||||
pub callback: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for Sync {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
callback: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Sync {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "sync(callback: {})", self.callback)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct DeleteId {
|
||||
pub obj: Rc<WlDisplay>,
|
||||
pub id: ObjectId,
|
||||
}
|
||||
impl EventFormatter for DeleteId {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(WL_DISPLAY_ID, DELETE_ID).object(self.id);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for DeleteId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "delete_id(id: {})", self.id)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Error {
|
||||
pub obj: Rc<WlDisplay>,
|
||||
pub object_id: ObjectId,
|
||||
pub code: u32,
|
||||
pub message: String,
|
||||
}
|
||||
impl EventFormatter for Error {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(WL_DISPLAY_ID, ERROR)
|
||||
.object(self.object_id)
|
||||
.uint(self.code)
|
||||
.string(&self.message);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for Error {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"error(object_id: {}, code: {}, message: {:?})",
|
||||
self.object_id, self.code, self.message
|
||||
)
|
||||
}
|
||||
}
|
||||
104
src/ifs/wl_region/mod.rs
Normal file
104
src/ifs/wl_region/mod.rs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
mod types;
|
||||
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId};
|
||||
use crate::pixman::Region;
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::wl_client::{RequestParser, WlClientData};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::ifs::wl_display::WlDisplay;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const ADD: u32 = 1;
|
||||
const SUBTRACT: u32 = 2;
|
||||
|
||||
pub struct WlRegion {
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
rect: RefCell<Region>,
|
||||
}
|
||||
|
||||
impl WlRegion {
|
||||
pub fn new(id: ObjectId, client: &Rc<WlClientData>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
rect: RefCell::new(Region::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn region(&self) -> Region {
|
||||
self.rect.borrow().clone()
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _destroy: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.objects.remove_obj(&self.client, self.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn add(&self, parser: WlParser<'_, '_>) -> Result<(), AddError> {
|
||||
let add: Add = self.client.parse(self, parser)?;
|
||||
if add.width < 0 || add.height < 0 {
|
||||
return Err(AddError::NegativeExtents);
|
||||
}
|
||||
let mut rect = self.rect.borrow_mut();
|
||||
*rect = rect.add(&Region::rect(add.x, add.y, add.width as _, add.height as _));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn subtract(&self, parser: WlParser<'_, '_>) -> Result<(), SubtractError> {
|
||||
let subtract: Subtract = self.client.parse(self, parser)?;
|
||||
if subtract.width < 0 || subtract.height < 0 {
|
||||
return Err(SubtractError::NegativeExtents);
|
||||
}
|
||||
let mut rect = self.rect.borrow_mut();
|
||||
*rect = rect.subtract(&Region::rect(
|
||||
subtract.x,
|
||||
subtract.y,
|
||||
subtract.width as _,
|
||||
subtract.height as _,
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlRegionError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
ADD => self.add(parser).await?,
|
||||
SUBTRACT => self.subtract(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlRegion);
|
||||
|
||||
impl Object for WlRegion {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlRegion
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
SUBTRACT + 1
|
||||
}
|
||||
|
||||
fn post_attach(self: Rc<Self>) {
|
||||
self.client.objects.regions.set(self.id, self.clone());
|
||||
}
|
||||
|
||||
fn pre_release(&self) -> Result<(), ObjectError> {
|
||||
self.client.objects.regions.remove(&self.id);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
107
src/ifs/wl_region/types.rs
Normal file
107
src/ifs/wl_region/types.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
use crate::objects::{ObjectError, ObjectId};
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::wl_client::RequestParser;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlRegionError {
|
||||
#[error("Could not process `destroy` request")]
|
||||
DestroyError(#[from] DestroyError),
|
||||
#[error("Could not process `add` request")]
|
||||
AddError(#[from] AddError),
|
||||
#[error("Could not process `subtract` request")]
|
||||
SubtractError(#[from] SubtractError),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, WlParserError);
|
||||
efrom!(DestroyError, ObjectError, ObjectError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AddError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error("width and/or height are negative")]
|
||||
NegativeExtents,
|
||||
}
|
||||
efrom!(AddError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SubtractError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error("width and/or height are negative")]
|
||||
NegativeExtents,
|
||||
}
|
||||
efrom!(SubtractError, ParseFailed, WlParserError);
|
||||
|
||||
pub(super) struct Destroy;
|
||||
impl RequestParser<'_> for Destroy {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Destroy {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Add {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Add {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
width: parser.int()?,
|
||||
height: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Add {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"add(x: {}, y: {}, width: {}, height: {})",
|
||||
self.x, self.y, self.width, self.height,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Subtract {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Subtract {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
width: parser.int()?,
|
||||
height: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Subtract {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"subtract(x: {}, y: {}, width: {}, height: {})",
|
||||
self.x, self.y, self.width, self.height,
|
||||
)
|
||||
}
|
||||
}
|
||||
91
src/ifs/wl_registry/mod.rs
Normal file
91
src/ifs/wl_registry/mod.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
mod types;
|
||||
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::{DynEventFormatter, WlClientData};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const BIND: u32 = 0;
|
||||
|
||||
const GLOBAL: u32 = 0;
|
||||
const GLOBAL_REMOVE: u32 = 1;
|
||||
|
||||
pub struct WlRegistry {
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
}
|
||||
|
||||
impl WlRegistry {
|
||||
pub fn new(id: ObjectId, client: &Rc<WlClientData>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn global(self: &Rc<Self>, global: &Rc<dyn Global>) -> DynEventFormatter {
|
||||
Box::new(GlobalE {
|
||||
obj: self.clone(),
|
||||
global: global.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn global_remove(self: &Rc<Self>, name: GlobalName) -> DynEventFormatter {
|
||||
Box::new(GlobalRemove {
|
||||
obj: self.clone(),
|
||||
name,
|
||||
})
|
||||
}
|
||||
|
||||
async fn bind(&self, parser: WlParser<'_, '_>) -> Result<(), BindError> {
|
||||
let bind: Bind = self.client.parse(self, parser)?;
|
||||
let global = self.client.state.globals.get(bind.name)?;
|
||||
if global.interface().name() != bind.interface {
|
||||
return Err(BindError::InvalidInterface(InterfaceError {
|
||||
name: global.name(),
|
||||
interface: global.interface(),
|
||||
actual: bind.interface.to_string(),
|
||||
}));
|
||||
}
|
||||
if bind.version > global.version() {
|
||||
return Err(BindError::InvalidVersion(VersionError {
|
||||
name: global.name(),
|
||||
interface: global.interface(),
|
||||
version: global.version(),
|
||||
actual: bind.version,
|
||||
}));
|
||||
}
|
||||
global.bind(&self.client, bind.id, bind.version).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlRegistryError> {
|
||||
match request {
|
||||
BIND => self.bind(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlRegistry);
|
||||
|
||||
impl Object for WlRegistry {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlRegistry
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
BIND + 1
|
||||
}
|
||||
}
|
||||
117
src/ifs/wl_registry/types.rs
Normal file
117
src/ifs/wl_registry/types.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
use crate::globals::{Global, GlobalError, GlobalName};
|
||||
use crate::ifs::wl_registry::{WlRegistry, GLOBAL, GLOBAL_REMOVE};
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::wl_client::{EventFormatter, RequestParser};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlRegistryError {
|
||||
#[error("Could not process bind request")]
|
||||
BindError(#[source] Box<BindError>),
|
||||
}
|
||||
|
||||
efrom!(WlRegistryError, BindError, BindError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BindError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
GlobalError(Box<GlobalError>),
|
||||
#[error("Tried to bind to global {} of type {} using interface {}", .0.name, .0.interface.name(), .0.actual)]
|
||||
InvalidInterface(InterfaceError),
|
||||
#[error("Tried to bind to global {} of type {} and version {} using version {}", .0.name, .0.interface.name(), .0.version, .0.actual)]
|
||||
InvalidVersion(VersionError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InterfaceError {
|
||||
pub name: GlobalName,
|
||||
pub interface: Interface,
|
||||
pub actual: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct VersionError {
|
||||
pub name: GlobalName,
|
||||
pub interface: Interface,
|
||||
pub version: u32,
|
||||
pub actual: u32,
|
||||
}
|
||||
|
||||
efrom!(BindError, ParseError, WlParserError);
|
||||
efrom!(BindError, GlobalError, GlobalError);
|
||||
|
||||
pub(super) struct GlobalE {
|
||||
pub obj: Rc<WlRegistry>,
|
||||
pub global: Rc<dyn Global>,
|
||||
}
|
||||
impl EventFormatter for GlobalE {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL)
|
||||
.uint(self.global.name().raw())
|
||||
.string(self.global.interface().name())
|
||||
.uint(self.global.version());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for GlobalE {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"global(name: {}, interface: {:?}, version: {})",
|
||||
self.global.name(),
|
||||
self.global.interface().name(),
|
||||
self.global.version()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct GlobalRemove {
|
||||
pub obj: Rc<WlRegistry>,
|
||||
pub name: GlobalName,
|
||||
}
|
||||
impl EventFormatter for GlobalRemove {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL_REMOVE).uint(self.name.raw());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for GlobalRemove {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "global_remove(name: {})", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Bind<'a> {
|
||||
pub name: GlobalName,
|
||||
pub id: ObjectId,
|
||||
pub interface: &'a str,
|
||||
pub version: u32,
|
||||
}
|
||||
impl<'a> RequestParser<'a> for Bind<'a> {
|
||||
fn parse(parser: &mut WlParser<'_, 'a>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
name: parser.global()?,
|
||||
interface: parser.string()?,
|
||||
version: parser.uint()?,
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Bind<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"bind(name: {}, interface: {:?}, version: {}, id: {})",
|
||||
self.name, self.interface, self.version, self.id
|
||||
)
|
||||
}
|
||||
}
|
||||
136
src/ifs/wl_shm/mod.rs
Normal file
136
src/ifs/wl_shm/mod.rs
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
mod types;
|
||||
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::ifs::wl_shm_pool::WlShmPool;
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::WlClientData;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const CREATE_POOL: u32 = 0;
|
||||
|
||||
const FORMAT: u32 = 0;
|
||||
|
||||
pub struct WlShmGlobal {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
pub struct WlShmObj {
|
||||
global: Rc<WlShmGlobal>,
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
}
|
||||
|
||||
impl WlShmGlobal {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
async fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ObjectId,
|
||||
client: &Rc<WlClientData>,
|
||||
_version: u32,
|
||||
) -> Result<(), WlShmError> {
|
||||
let obj = Rc::new(WlShmObj {
|
||||
global: self,
|
||||
id,
|
||||
client: client.clone(),
|
||||
});
|
||||
client.attach_client_object(obj.clone())?;
|
||||
for &format in Format::formats() {
|
||||
client
|
||||
.event(Box::new(FormatE {
|
||||
obj: obj.clone(),
|
||||
format,
|
||||
}))
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl WlShmObj {
|
||||
async fn create_pool(&self, parser: WlParser<'_, '_>) -> Result<(), CreatePoolError> {
|
||||
let create: CreatePool = self.client.parse(self, parser)?;
|
||||
if create.size < 0 {
|
||||
return Err(CreatePoolError::NegativeSize);
|
||||
}
|
||||
let pool = Rc::new(WlShmPool::new(
|
||||
create.id,
|
||||
&self.client,
|
||||
create.fd,
|
||||
create.size as usize,
|
||||
)?);
|
||||
self.client.attach_client_object(pool)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlShmError> {
|
||||
match request {
|
||||
CREATE_POOL => self.create_pool(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum Format {
|
||||
Argb8888,
|
||||
Xrgb8888,
|
||||
}
|
||||
|
||||
impl Format {
|
||||
fn uint(self) -> u32 {
|
||||
match self {
|
||||
Format::Argb8888 => 0,
|
||||
Format::Xrgb8888 => 1,
|
||||
}
|
||||
}
|
||||
|
||||
fn formats() -> &'static [Format] {
|
||||
&[Format::Argb8888, Format::Xrgb8888]
|
||||
}
|
||||
}
|
||||
|
||||
bind!(WlShmGlobal);
|
||||
|
||||
impl Global for WlShmGlobal {
|
||||
fn name(&self) -> GlobalName {
|
||||
self.name
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlShm
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn pre_remove(&self) {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlShmObj);
|
||||
|
||||
impl Object for WlShmObj {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlShm
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
CREATE_POOL + 1
|
||||
}
|
||||
}
|
||||
80
src/ifs/wl_shm/types.rs
Normal file
80
src/ifs/wl_shm/types.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
use crate::ifs::wl_shm::{Format, WlShmObj, FORMAT};
|
||||
use crate::ifs::wl_shm_pool::WlShmPoolError;
|
||||
use crate::objects::{Object, ObjectError, ObjectId};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::wl_client::{EventFormatter, RequestParser, WlClientError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::OwnedFd;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlShmError {
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
#[error("Could not process a `create_pool` request")]
|
||||
CreatePoolError(#[from] CreatePoolError),
|
||||
}
|
||||
efrom!(WlShmError, ObjectError, ObjectError);
|
||||
efrom!(WlShmError, ClientError, WlClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CreatePoolError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error("The passed size is negative")]
|
||||
NegativeSize,
|
||||
#[error(transparent)]
|
||||
WlShmPoolError(Box<WlShmPoolError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
}
|
||||
efrom!(CreatePoolError, ParseError, WlParserError);
|
||||
efrom!(CreatePoolError, WlShmPoolError, WlShmPoolError);
|
||||
efrom!(CreatePoolError, ClientError, WlClientError);
|
||||
|
||||
pub(super) struct CreatePool {
|
||||
pub id: ObjectId,
|
||||
pub fd: OwnedFd,
|
||||
pub size: i32,
|
||||
}
|
||||
impl RequestParser<'_> for CreatePool {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
fd: parser.fd()?,
|
||||
size: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for CreatePool {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"create_pool(id: {}, fd: {}, size: {})",
|
||||
self.id,
|
||||
self.fd.raw(),
|
||||
self.size
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct FormatE {
|
||||
pub obj: Rc<WlShmObj>,
|
||||
pub format: Format,
|
||||
}
|
||||
impl EventFormatter for FormatE {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, FORMAT).uint(self.format.uint());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for FormatE {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "format(format: {:?})", self.format)
|
||||
}
|
||||
}
|
||||
94
src/ifs/wl_shm_pool/mod.rs
Normal file
94
src/ifs/wl_shm_pool/mod.rs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
mod types;
|
||||
|
||||
use crate::clientmem::ClientMem;
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::WlClientData;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use uapi::OwnedFd;
|
||||
|
||||
const CREATE_BUFFER: u32 = 0;
|
||||
const DESTROY: u32 = 1;
|
||||
const RESIZE: u32 = 2;
|
||||
|
||||
pub struct WlShmPool {
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
fd: OwnedFd,
|
||||
mem: RefCell<Rc<ClientMem>>,
|
||||
}
|
||||
|
||||
impl WlShmPool {
|
||||
pub fn new(
|
||||
id: ObjectId,
|
||||
client: &Rc<WlClientData>,
|
||||
fd: OwnedFd,
|
||||
len: usize,
|
||||
) -> Result<Self, WlShmPoolError> {
|
||||
Ok(Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
mem: RefCell::new(Rc::new(ClientMem::new(fd.raw(), len)?)),
|
||||
fd,
|
||||
})
|
||||
}
|
||||
|
||||
async fn create_buffer(&self, parser: WlParser<'_, '_>) -> Result<(), CreateBufferError> {
|
||||
let create: CreateBuffer = self.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _destroy: Destroy = self.client.parse(self, parser)?;
|
||||
self.client
|
||||
.objects
|
||||
.remove_obj(&self.client, self.id)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn resize(&self, parser: WlParser<'_, '_>) -> Result<(), ResizeError> {
|
||||
let resize: Resize = self.client.parse(self, parser)?;
|
||||
let mut mem = self.mem.borrow_mut();
|
||||
if resize.size < 0 {
|
||||
return Err(ResizeError::NegativeSize);
|
||||
}
|
||||
if (resize.size as usize) < mem.len() {
|
||||
return Err(ResizeError::CannotShrink);
|
||||
}
|
||||
*mem = Rc::new(ClientMem::new(self.fd.raw(), resize.size as usize)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlShmPoolError> {
|
||||
match request {
|
||||
CREATE_BUFFER => self.create_buffer(parser).await?,
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
RESIZE => self.resize(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlShmPool);
|
||||
|
||||
impl Object for WlShmPool {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlShmPool
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
RESIZE + 1
|
||||
}
|
||||
}
|
||||
117
src/ifs/wl_shm_pool/types.rs
Normal file
117
src/ifs/wl_shm_pool/types.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
use crate::clientmem::ClientMemError;
|
||||
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 WlShmPoolError {
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
#[error("Could not process a `create_buffer` request")]
|
||||
CreateBufferError(#[from] CreateBufferError),
|
||||
#[error("Could not process a `destroy` request")]
|
||||
DestroyError(#[from] DestroyError),
|
||||
#[error("Could not process a `resize` request")]
|
||||
ResizeError(#[from] ResizeError),
|
||||
#[error(transparent)]
|
||||
ClientMemError(Box<ClientMemError>),
|
||||
}
|
||||
efrom!(WlShmPoolError, ObjectError, ObjectError);
|
||||
efrom!(WlShmPoolError, ClientError, WlClientError);
|
||||
efrom!(WlShmPoolError, ClientMemError, ClientMemError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CreateBufferError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
}
|
||||
efrom!(CreateBufferError, ParseError, WlParserError);
|
||||
efrom!(CreateBufferError, ObjectError, ObjectError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseError, WlParserError);
|
||||
efrom!(DestroyError, ObjectError, ObjectError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResizeError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error("Tried to shrink the pool")]
|
||||
CannotShrink,
|
||||
#[error("Requested size is negative")]
|
||||
NegativeSize,
|
||||
#[error(transparent)]
|
||||
ClientMemError(Box<ClientMemError>),
|
||||
}
|
||||
efrom!(ResizeError, ParseError, WlParserError);
|
||||
efrom!(ResizeError, ClientMemError, ClientMemError);
|
||||
|
||||
pub(super) struct CreateBuffer {
|
||||
pub id: ObjectId,
|
||||
pub offset: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub stride: i32,
|
||||
pub format: u32,
|
||||
}
|
||||
impl RequestParser<'_> for CreateBuffer {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
offset: parser.int()?,
|
||||
width: parser.int()?,
|
||||
height: parser.int()?,
|
||||
stride: parser.int()?,
|
||||
format: parser.uint()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for CreateBuffer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"create_buffer(id: {}, offset: {}, width: {}, height: {}, stride: {}, format: {})",
|
||||
self.id, self.offset, self.width, self.height, self.stride, self.format,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Destroy;
|
||||
impl RequestParser<'_> for Destroy {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Destroy {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()",)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Resize {
|
||||
pub size: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Resize {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
size: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Resize {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "resize(size: {})", self.size,)
|
||||
}
|
||||
}
|
||||
80
src/ifs/wl_subcompositor/mod.rs
Normal file
80
src/ifs/wl_subcompositor/mod.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
mod types;
|
||||
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::WlClientData;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
pub struct WlSubcompositorGlobal {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
pub struct WlSubcompositorObj {
|
||||
global: Rc<WlSubcompositorGlobal>,
|
||||
id: ObjectId,
|
||||
}
|
||||
|
||||
impl WlSubcompositorGlobal {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
async fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ObjectId,
|
||||
client: &WlClientData,
|
||||
_version: u32,
|
||||
) -> Result<(), WlSubcompositorError> {
|
||||
let obj = Rc::new(WlSubcompositorObj { global: self, id });
|
||||
client.attach_client_object(obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl WlSubcompositorObj {
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), ObjectError> {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
bind!(WlSubcompositorGlobal);
|
||||
|
||||
impl Global for WlSubcompositorGlobal {
|
||||
fn name(&self) -> GlobalName {
|
||||
self.name
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlSubcompositor
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn pre_remove(&self) {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlSubcompositorObj);
|
||||
|
||||
impl Object for WlSubcompositorObj {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlSubcompositor
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
14
src/ifs/wl_subcompositor/types.rs
Normal file
14
src/ifs/wl_subcompositor/types.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use crate::objects::ObjectError;
|
||||
use crate::wl_client::WlClientError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSubcompositorError {
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
}
|
||||
|
||||
efrom!(WlSubcompositorError, ObjectError, ObjectError);
|
||||
efrom!(WlSubcompositorError, ClientError, WlClientError);
|
||||
162
src/ifs/wl_surface/mod.rs
Normal file
162
src/ifs/wl_surface/mod.rs
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
mod types;
|
||||
|
||||
use std::cell::Cell;
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId};
|
||||
use crate::utils::buffd::{WlParser, WlParserError};
|
||||
use crate::wl_client::{RequestParser, WlClientData};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::pixman::Region;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const ATTACH: u32 = 1;
|
||||
const DAMAGE: u32 = 2;
|
||||
const FRAME: u32 = 3;
|
||||
const SET_OPAQUE_REGION: u32 = 4;
|
||||
const SET_INPUT_REGION: u32 = 5;
|
||||
const COMMIT: u32 = 6;
|
||||
const SET_BUFFER_TRANSFORM: u32 = 7;
|
||||
const SET_BUFFER_SCALE: u32 = 8;
|
||||
const DAMAGE_BUFFER: u32 = 9;
|
||||
|
||||
const ENTER: u32 = 0;
|
||||
const LEAVE: u32 = 1;
|
||||
|
||||
const INVALID_SCALE: u32 = 0;
|
||||
const INVALID_TRANSFORM: u32 = 1;
|
||||
const INVALID_SIZE: u32 = 2;
|
||||
|
||||
pub struct WlSurface {
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
pending: PendingState,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct PendingState {
|
||||
opaque_region: Cell<Option<Region>>,
|
||||
input_region: Cell<Option<Region>>,
|
||||
}
|
||||
|
||||
impl WlSurface {
|
||||
pub fn new(id: ObjectId, client: &Rc<WlClientData>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
pending: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse<'a, T: RequestParser<'a>>(
|
||||
&self,
|
||||
parser: WlParser<'_, 'a>,
|
||||
) -> Result<T, WlParserError> {
|
||||
self.client.parse(self, parser)
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: WlParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let destroy: Destroy = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn attach(&self, parser: WlParser<'_, '_>) -> Result<(), AttachError> {
|
||||
let attach: Attach = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn damage(&self, parser: WlParser<'_, '_>) -> Result<(), DamageError> {
|
||||
let damage: Damage = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn frame(&self, parser: WlParser<'_, '_>) -> Result<(), FrameError> {
|
||||
let frame: Frame = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_opaque_region(
|
||||
&self,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), SetOpaqueRegionError> {
|
||||
let region: SetOpaqueRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(region.region)?;
|
||||
self.pending.opaque_region.set(Some(region.region()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_input_region(&self, parser: WlParser<'_, '_>) -> Result<(), SetInputRegionError> {
|
||||
let region: SetInputRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(region.region)?;
|
||||
self.pending.input_region.set(Some(region.region()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn commit(&self, parser: WlParser<'_, '_>) -> Result<(), CommitError> {
|
||||
let commit: Commit = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_buffer_transform(
|
||||
&self,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), SetBufferTransformError> {
|
||||
let transform: SetBufferTransform = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_buffer_scale(&self, parser: WlParser<'_, '_>) -> Result<(), SetBufferScaleError> {
|
||||
let scale: SetBufferScale = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn damage_buffer(&self, parser: WlParser<'_, '_>) -> Result<(), DamageBufferError> {
|
||||
let damage: DamageBuffer = self.parse(parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlSurfaceError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
ATTACH => self.attach(parser).await?,
|
||||
DAMAGE => self.damage(parser).await?,
|
||||
FRAME => self.frame(parser).await?,
|
||||
SET_OPAQUE_REGION => self.set_opaque_region(parser).await?,
|
||||
SET_INPUT_REGION => self.set_input_region(parser).await?,
|
||||
COMMIT => self.commit(parser).await?,
|
||||
SET_BUFFER_TRANSFORM => self.set_buffer_transform(parser).await?,
|
||||
SET_BUFFER_SCALE => self.set_buffer_scale(parser).await?,
|
||||
DAMAGE_BUFFER => self.damage_buffer(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlSurface);
|
||||
|
||||
impl Object for WlSurface {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlSurface
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
DAMAGE_BUFFER + 1
|
||||
}
|
||||
|
||||
fn pre_release(&self) -> Result<(), ObjectError> {
|
||||
self.client.objects.surfaces.remove(&self.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_attach(self: Rc<Self>) {
|
||||
self.client.objects.surfaces.set(self.id, self.clone());
|
||||
}
|
||||
}
|
||||
299
src/ifs/wl_surface/types.rs
Normal file
299
src/ifs/wl_surface/types.rs
Normal file
|
|
@ -0,0 +1,299 @@
|
|||
use crate::objects::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 WlSurfaceError {
|
||||
#[error("Could not process `destroy` request")]
|
||||
DestroyError(#[source] Box<DestroyError>),
|
||||
#[error("Could not process `attach` request")]
|
||||
AttachError(#[source] Box<AttachError>),
|
||||
#[error("Could not process `damage` request")]
|
||||
DamageError(#[source] Box<DamageError>),
|
||||
#[error("Could not process `frame` request")]
|
||||
FrameError(#[source] Box<FrameError>),
|
||||
#[error("Could not process `set_opaque_region` request")]
|
||||
SetOpaqueRegionError(#[source] Box<SetOpaqueRegionError>),
|
||||
#[error("Could not process `set_input_region` request")]
|
||||
SetInputRegionError(#[source] Box<SetInputRegionError>),
|
||||
#[error("Could not process `commit` request")]
|
||||
CommitError(#[source] Box<CommitError>),
|
||||
#[error("Could not process `set_buffer_transform` request")]
|
||||
SetBufferTransformError(#[source] Box<SetBufferTransformError>),
|
||||
#[error("Could not process `set_buffer_scale_error` request")]
|
||||
SetBufferScaleError(#[source] Box<SetBufferScaleError>),
|
||||
#[error("Could not process `damage_buffer` request")]
|
||||
DamageBufferError(#[source] Box<DamageBufferError>),
|
||||
}
|
||||
efrom!(WlSurfaceError, DestroyError, DestroyError);
|
||||
efrom!(WlSurfaceError, AttachError, AttachError);
|
||||
efrom!(WlSurfaceError, DamageError, DamageError);
|
||||
efrom!(WlSurfaceError, FrameError, FrameError);
|
||||
efrom!(WlSurfaceError, SetOpaqueRegionError, SetOpaqueRegionError);
|
||||
efrom!(WlSurfaceError, SetInputRegionError, SetInputRegionError);
|
||||
efrom!(WlSurfaceError, CommitError, CommitError);
|
||||
efrom!(
|
||||
WlSurfaceError,
|
||||
SetBufferTransformError,
|
||||
SetBufferTransformError
|
||||
);
|
||||
efrom!(WlSurfaceError, SetBufferScaleError, SetBufferScaleError);
|
||||
efrom!(WlSurfaceError, DamageBufferError, DamageBufferError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AttachError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(AttachError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DamageError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(DamageError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FrameError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(FrameError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetOpaqueRegionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
}
|
||||
efrom!(SetOpaqueRegionError, ParseFailed, WlParserError);
|
||||
efrom!(SetOpaqueRegionError, ClientError, WlClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetInputRegionError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
}
|
||||
efrom!(SetInputRegionError, ParseFailed, WlParserError);
|
||||
efrom!(SetInputRegionError, ClientError, WlClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CommitError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(CommitError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetBufferTransformError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(SetBufferTransformError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetBufferScaleError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(SetBufferScaleError, ParseFailed, WlParserError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DamageBufferError {
|
||||
#[error("Parsing failed")]
|
||||
ParseFailed(#[source] Box<WlParserError>),
|
||||
}
|
||||
efrom!(DamageBufferError, ParseFailed, WlParserError);
|
||||
|
||||
pub(super) struct Destroy;
|
||||
impl RequestParser<'_> for Destroy {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Destroy {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "destroy()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Attach {
|
||||
pub buffer: ObjectId,
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Attach {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
buffer: parser.object()?,
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Attach {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"attach(buffer: {}, x: {}, y: {})",
|
||||
self.buffer, self.x, self.y
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Damage {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for Damage {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
width: parser.int()?,
|
||||
height: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Damage {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"damage(x: {}, y: {}, width: {}, height: {})",
|
||||
self.x, self.y, self.width, self.height
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Frame {
|
||||
pub callback: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for Frame {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
callback: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Frame {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "frame(callback: {})", self.callback)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct SetOpaqueRegion {
|
||||
pub region: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for SetOpaqueRegion {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
region: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetOpaqueRegion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_opaque_region(region: {})", self.region)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct SetInputRegion {
|
||||
pub region: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for SetInputRegion {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
region: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetInputRegion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_input_region(region: {})", self.region)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Commit;
|
||||
impl RequestParser<'_> for Commit {
|
||||
fn parse(_parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self)
|
||||
}
|
||||
}
|
||||
impl Debug for Commit {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "commit()")
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct SetBufferTransform {
|
||||
pub transform: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetBufferTransform {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
transform: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetBufferTransform {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_buffer_transform(transform: {})", self.transform)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct SetBufferScale {
|
||||
pub scale: i32,
|
||||
}
|
||||
impl RequestParser<'_> for SetBufferScale {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
scale: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for SetBufferScale {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "set_buffer_scale(scale: {})", self.scale)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct DamageBuffer {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
impl RequestParser<'_> for DamageBuffer {
|
||||
fn parse(parser: &mut WlParser<'_, '_>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
x: parser.int()?,
|
||||
y: parser.int()?,
|
||||
width: parser.int()?,
|
||||
height: parser.int()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for DamageBuffer {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"damage_buffer(x: {}, y: {}, width: {}, height: {})",
|
||||
self.x, self.y, self.width, self.height
|
||||
)
|
||||
}
|
||||
}
|
||||
85
src/ifs/xdg_wm_base/mod.rs
Normal file
85
src/ifs/xdg_wm_base/mod.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
mod types;
|
||||
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::objects::{Interface, Object, ObjectError, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::WlClientData;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
pub struct XdgWmBaseGlobal {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
pub struct XdgWmBaseObj {
|
||||
global: Rc<XdgWmBaseGlobal>,
|
||||
id: ObjectId,
|
||||
version: u32,
|
||||
}
|
||||
|
||||
impl XdgWmBaseGlobal {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
async fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ObjectId,
|
||||
client: &WlClientData,
|
||||
version: u32,
|
||||
) -> Result<(), XdgWmBaseError> {
|
||||
let obj = Rc::new(XdgWmBaseObj {
|
||||
global: self,
|
||||
id,
|
||||
version,
|
||||
});
|
||||
client.attach_client_object(obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgWmBaseObj {
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), ObjectError> {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
bind!(XdgWmBaseGlobal);
|
||||
|
||||
impl Global for XdgWmBaseGlobal {
|
||||
fn name(&self) -> GlobalName {
|
||||
self.name
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::XdgWmBase
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
3
|
||||
}
|
||||
|
||||
fn pre_remove(&self) {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgWmBaseObj);
|
||||
|
||||
impl Object for XdgWmBaseObj {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::XdgWmBase
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
}
|
||||
14
src/ifs/xdg_wm_base/types.rs
Normal file
14
src/ifs/xdg_wm_base/types.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use crate::objects::ObjectError;
|
||||
use crate::wl_client::WlClientError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XdgWmBaseError {
|
||||
#[error(transparent)]
|
||||
ObjectError(Box<ObjectError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<WlClientError>),
|
||||
}
|
||||
|
||||
efrom!(XdgWmBaseError, ObjectError, ObjectError);
|
||||
efrom!(XdgWmBaseError, ClientError, WlClientError);
|
||||
Loading…
Add table
Add a link
Reference in a new issue