autocommit 2022-01-03 18:56:52 CET
This commit is contained in:
parent
fc887b339e
commit
30376c595c
39 changed files with 3157 additions and 309 deletions
|
|
@ -1,12 +1,29 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::{AddObj, Client, ClientError};
|
||||
use crate::client::{AddObj, Client};
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
use crate::ifs::xdg_positioner::XdgPositioner;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::copyhashmap::CopyHashMap;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const CREATE_POSITIONER: u32 = 1;
|
||||
const GET_XDG_SURFACE: u32 = 2;
|
||||
const PONG: u32 = 3;
|
||||
|
||||
const PING: u32 = 0;
|
||||
|
||||
const ROLE: u32 = 0;
|
||||
const DEFUNCT_SURFACES: u32 = 1;
|
||||
const NOT_THE_TOPMOST_POPUP: u32 = 2;
|
||||
const INVALID_POPUP_PARENT: u32 = 3;
|
||||
const INVALID_SURFACE_STATE: u32 = 4;
|
||||
const INVALID_POSITIONER: u32 = 5;
|
||||
|
||||
pub struct XdgWmBaseGlobal {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
|
@ -14,7 +31,9 @@ pub struct XdgWmBaseGlobal {
|
|||
pub struct XdgWmBaseObj {
|
||||
global: Rc<XdgWmBaseGlobal>,
|
||||
id: ObjectId,
|
||||
client: Rc<Client>,
|
||||
version: u32,
|
||||
pub(super) surfaces: CopyHashMap<ObjectId, Rc<XdgSurface>>,
|
||||
}
|
||||
|
||||
impl XdgWmBaseGlobal {
|
||||
|
|
@ -25,13 +44,15 @@ impl XdgWmBaseGlobal {
|
|||
async fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: ObjectId,
|
||||
client: &Client,
|
||||
client: &Rc<Client>,
|
||||
version: u32,
|
||||
) -> Result<(), XdgWmBaseError> {
|
||||
let obj = Rc::new(XdgWmBaseObj {
|
||||
global: self,
|
||||
id,
|
||||
client: client.clone(),
|
||||
version,
|
||||
surfaces: Default::default(),
|
||||
});
|
||||
client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
|
|
@ -39,12 +60,65 @@ impl XdgWmBaseGlobal {
|
|||
}
|
||||
|
||||
impl XdgWmBaseObj {
|
||||
async fn handle_request_(
|
||||
pub fn break_loops(&self) {
|
||||
self.surfaces.clear();
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
if !self.surfaces.is_empty() {
|
||||
self.client.protocol_error(
|
||||
self,
|
||||
DEFUNCT_SURFACES,
|
||||
format!(
|
||||
"Cannot destroy xdg_wm_base object {} before destroying its surfaces",
|
||||
self.id
|
||||
),
|
||||
);
|
||||
return Err(DestroyError::DefunctSurfaces);
|
||||
}
|
||||
self.client.remove_obj(self).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn create_positioner(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), CreatePositionerError> {
|
||||
let req: CreatePositioner = self.client.parse(self, parser)?;
|
||||
let pos = Rc::new(XdgPositioner::new(req.id, &self.client, 3));
|
||||
self.client.add_client_obj(&pos)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_xdg_surface(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetXdgSurfaceError> {
|
||||
let req: GetXdgSurface = self.client.parse(&**self, parser)?;
|
||||
let surface = self.client.get_surface(req.surface)?;
|
||||
let xdg_surface = Rc::new(XdgSurface::new(self, req.id, &surface, 3));
|
||||
self.client.add_client_obj(&xdg_surface)?;
|
||||
xdg_surface.install()?;
|
||||
self.surfaces.set(req.id, xdg_surface);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn pong(&self, parser: MsgParser<'_, '_>) -> Result<(), PongError> {
|
||||
let _req: Pong = self.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ClientError> {
|
||||
unreachable!();
|
||||
) -> Result<(), XdgWmBaseError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
CREATE_POSITIONER => self.create_positioner(parser).await?,
|
||||
GET_XDG_SURFACE => self.get_xdg_surface(parser).await?,
|
||||
PONG => self.pong(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +154,6 @@ impl Object for XdgWmBaseObj {
|
|||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
0
|
||||
PONG + 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,149 @@
|
|||
use crate::client::ClientError;
|
||||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::ifs::xdg_wm_base::{XdgWmBaseObj, PING};
|
||||
use crate::object::{Object, ObjectId};
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XdgWmBaseError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Could not process a `destroy` request")]
|
||||
DestroyError(#[from] DestroyError),
|
||||
#[error("Could not process a `create_positioner` request")]
|
||||
CreatePositionerError(#[from] CreatePositionerError),
|
||||
#[error("Could not process a `get_xdg_surface` request")]
|
||||
GetXdgSurfaceError(#[from] GetXdgSurfaceError),
|
||||
#[error("Could not process a `pong` request")]
|
||||
PongError(#[from] PongError),
|
||||
}
|
||||
efrom!(XdgWmBaseError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error("Tried to destroy xdg_wm_base object before destroying its surfaces")]
|
||||
DefunctSurfaces,
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(DestroyError, ParseError, MsgParserError);
|
||||
efrom!(DestroyError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CreatePositionerError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(CreatePositionerError, ParseError, MsgParserError);
|
||||
efrom!(CreatePositionerError, ClientError, ClientError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetXdgSurfaceError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error(transparent)]
|
||||
XdgSurfaceError(Box<XdgSurfaceError>),
|
||||
}
|
||||
efrom!(GetXdgSurfaceError, ParseError, MsgParserError);
|
||||
efrom!(GetXdgSurfaceError, ClientError, ClientError);
|
||||
efrom!(GetXdgSurfaceError, XdgSurfaceError, XdgSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum PongError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(PongError, ParseError, MsgParserError);
|
||||
|
||||
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()",)
|
||||
}
|
||||
}
|
||||
|
||||
efrom!(XdgWmBaseError, ClientError, ClientError);
|
||||
pub(super) struct CreatePositioner {
|
||||
pub id: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for CreatePositioner {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for CreatePositioner {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "create_positioner(id: {})", self.id,)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct GetXdgSurface {
|
||||
pub id: ObjectId,
|
||||
pub surface: ObjectId,
|
||||
}
|
||||
impl RequestParser<'_> for GetXdgSurface {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
id: parser.object()?,
|
||||
surface: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for GetXdgSurface {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"get_xdg_surface(id: {}, surface: {})",
|
||||
self.id, self.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Pong {
|
||||
pub serial: u32,
|
||||
}
|
||||
impl RequestParser<'_> for Pong {
|
||||
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
|
||||
Ok(Self {
|
||||
serial: parser.uint()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Pong {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "pong(serial: {})", self.serial,)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Ping {
|
||||
pub obj: Rc<XdgWmBaseObj>,
|
||||
pub serial: u32,
|
||||
}
|
||||
impl EventFormatter for Ping {
|
||||
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
|
||||
fmt.header(self.obj.id, PING).uint(self.serial);
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for Ping {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "ping(serial: {})", self.serial)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue