autocommit 2022-01-02 15:13:33 CET
This commit is contained in:
commit
d6172b273f
50 changed files with 5807 additions and 0 deletions
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
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue