1
0
Fork 0
forked from wry/wry

autocommit 2022-01-03 18:56:52 CET

This commit is contained in:
Julian Orth 2022-01-03 18:56:52 +01:00
parent fc887b339e
commit 30376c595c
39 changed files with 3157 additions and 309 deletions

View file

@ -0,0 +1,78 @@
mod types;
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
const DESTROY: u32 = 0;
const GRAB: u32 = 1;
const REPOSITION: u32 = 2;
const CONFIGURE: u32 = 0;
const POPUP_DONE: u32 = 1;
const REPOSITIONED: u32 = 2;
const INVALID_GRAB: u32 = 1;
pub struct XdgPopup {
id: ObjectId,
surface: Rc<XdgSurface>,
version: u32,
}
impl XdgPopup {
pub fn new(id: ObjectId, surface: &Rc<XdgSurface>, version: u32) -> Self {
Self {
id,
surface: surface.clone(),
version,
}
}
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
Ok(())
}
async fn grab(&self, parser: MsgParser<'_, '_>) -> Result<(), GrabError> {
let _req: Grab = self.surface.surface.client.parse(self, parser)?;
Ok(())
}
async fn reposition(&self, parser: MsgParser<'_, '_>) -> Result<(), RepositionError> {
let _req: Reposition = self.surface.surface.client.parse(self, parser)?;
Ok(())
}
async fn handle_request_(
&self,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), XdgPopupError> {
match request {
DESTROY => self.destroy(parser).await?,
GRAB => self.grab(parser).await?,
REPOSITION => self.reposition(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(XdgPopup);
impl Object for XdgPopup {
fn id(&self) -> ObjectId {
self.id
}
fn interface(&self) -> Interface {
Interface::XdgPopup
}
fn num_requests(&self) -> u32 {
REPOSITION + 1
}
}

View file

@ -0,0 +1,168 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{
XdgPopup, CONFIGURE, POPUP_DONE, REPOSITIONED,
};
use crate::object::{Object, ObjectId};
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum XdgPopupError {
#[error("Could not process `destroy` request")]
DestroyError(#[from] DestroyError),
#[error("Could not process `grab` request")]
GrabError(#[from] GrabError),
#[error("Could not process `reposition` request")]
RepositionError(#[from] RepositionError),
}
#[derive(Debug, Error)]
pub enum DestroyError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(DestroyError, ParseFailed, MsgParserError);
efrom!(DestroyError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum GrabError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(GrabError, ParseFailed, MsgParserError);
efrom!(GrabError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum RepositionError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(RepositionError, ParseFailed, MsgParserError);
efrom!(RepositionError, ClientError, ClientError);
pub(super) struct Destroy;
impl RequestParser<'_> for Destroy {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
}
}
impl Debug for Destroy {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "destroy()")
}
}
pub(super) struct Grab {
pub seat: ObjectId,
pub serial: u32,
}
impl RequestParser<'_> for Grab {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
seat: parser.object()?,
serial: parser.uint()?,
})
}
}
impl Debug for Grab {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "grab(seat: {}, serial: {})", self.seat, self.serial)
}
}
pub(super) struct Reposition {
pub positioner: ObjectId,
pub token: u32,
}
impl RequestParser<'_> for Reposition {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self {
positioner: parser.object()?,
token: parser.uint()?,
})
}
}
impl Debug for Reposition {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"reposition(positioner: {}, token: {})",
self.positioner, self.token,
)
}
}
pub(super) struct Configure {
pub obj: Rc<XdgPopup>,
pub x: i32,
pub y: i32,
pub width: i32,
pub height: i32,
}
impl EventFormatter for Configure {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, CONFIGURE)
.int(self.x)
.int(self.y)
.int(self.width)
.int(self.height);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Configure {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"configure(x: {}, y: {}, width: {}, height: {})",
self.x, self.y, self.width, self.height
)
}
}
pub(super) struct PopupDone {
pub obj: Rc<XdgPopup>,
}
impl EventFormatter for PopupDone {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, POPUP_DONE);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for PopupDone {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "popup_done()")
}
}
pub(super) struct Repositioned {
pub obj: Rc<XdgPopup>,
pub token: u32,
}
impl EventFormatter for Repositioned {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, REPOSITIONED).uint(self.token);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Repositioned {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "repositioned(token: {})", self.token)
}
}